{"id":15800909,"url":"https://github.com/seananderson/stanhelpers","last_synced_at":"2025-03-31T21:28:15.659Z","repository":{"id":22423141,"uuid":"25760898","full_name":"seananderson/stanhelpers","owner":"seananderson","description":"Helper functions for Stan/rstan","archived":false,"fork":false,"pushed_at":"2017-03-17T17:49:37.000Z","size":10,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-12T01:18:55.691Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seananderson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-26T06:49:22.000Z","updated_at":"2017-03-17T12:35:53.000Z","dependencies_parsed_at":"2022-08-20T17:00:49.834Z","dependency_job_id":null,"html_url":"https://github.com/seananderson/stanhelpers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seananderson%2Fstanhelpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seananderson%2Fstanhelpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seananderson%2Fstanhelpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seananderson%2Fstanhelpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seananderson","download_url":"https://codeload.github.com/seananderson/stanhelpers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246543509,"owners_count":20794364,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-05T01:08:44.721Z","updated_at":"2025-03-31T21:28:15.633Z","avatar_url":"https://github.com/seananderson.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"## stanhelpers\n\nstanhelpers is a small collection of functions to make things that I do with\n[Stan](http:://mc-stan.org/) and [rstan](http:://mc-stan.org/rstan.html) easier. The package is a work in progress as I discover and solve bottlenecks.\n\nInstall the package with:\n\n```R\n# install.packages(\"devtools\")\ndevtools::install_github(\"seananderson/stanhelpers\")\n```\n\nRight now there are only two functions: `sampling_parallel()` and `extract_df()`. \n\n### `extract_df()`\n\nThe default function `rstan::extract()` extracts posterior samples from a Stan model. The output is a list containing matrices of samples (where parameters are vectors). `extract_df()` instead extracts the samples and returns them in one of three \"tidy data\" formats:\n\n1. A list of data frames\n2. A single wide data frame\n3. A single long-format data frame\n\nThese formats should be easier to use with packages such as dplyr, tidyr, or ggplot2. Internally, the data frame columns are renamed with index numbers for each element of a parameter. For example, an underscore would result in column names of `b0_1` and `b0_2` for a variable named `b0` with 2 columns.\n\n### `sampling_parallel()`\n\n**This is now built into rstan. You should use `options(mc.cores = parallel::detectCores())` or, e.g., `stan(..., cores = 4)` instead.**\n\nThis function makes it easy to sample from Stan models in parallel (on OS X or Linux). The [rstan wiki](https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started#sample-multiple-chains-in-parallel) explains how to sample in parallel, but this takes a lot of extra code. I want it to be as easy to sample in parallel as it is to call the default functions. So, instead of writing the following for every model:\n\n```R\nlibrary(\"parallel\")\nsflist \u003c- \nmclapply(1:4, mc.cores = 2, \n  function(i) sampling(object = foo, data = foo_data, seed = rng_seed, \n  chains = 1, chain_id = i, refresh = -1))\nfit \u003c- sflist2stanfit(sflist)\n```\n\nI can just write:\n\n```R\nfit \u003c- sampling_parallel(foo, foo_data, chains = 4L)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseananderson%2Fstanhelpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseananderson%2Fstanhelpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseananderson%2Fstanhelpers/lists"}