Description Usage Arguments Value References Examples
View source: R/sampling_parallel.R
Sample from a Stan model in parallel (on Unix-like machines). This is simply a wrapper for the code on the rstan wiki to make it simple to sample from Stan models without writing lots of code each time.
1 2 | sampling_parallel(object, data, chains = 4L, cores = 2L, rng_seed = NULL,
...)
|
object |
An object of class |
data |
An object of class |
chains |
Positive integer giving the number of chains to pass to
|
cores |
Positive integer giving the number of cores to use. Passed
to the |
rng_seed |
An optional value to pass to |
... |
Anything else to pass to |
An S4 object of class stanfit
as returned from
stan
. The multiple chains have been joined into a
single model object.
https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ## Not run:
schools_code <- "data {
int<lower=0> J; // number of schools
real y[J]; // estimated treatment effects
real<lower=0> sigma[J]; // s.e. of effect estimates
}
parameters {
real mu;
real<lower=0> tau;
real eta[J];
}
transformed parameters {
real theta[J];
for (j in 1:J)
theta[j] <- mu + tau * eta[j];
}
model {
eta ~ normal(0, 1);
y ~ normal(theta, sigma);
}"
schools_dat <- list(
J = 8,
y = c(28, 8, -3, 7, -1, 1, 18, 12),
sigma = c(15, 10, 16, 11, 9, 11, 10, 18))
sm <- rstan::stan_model(model_code = schools_code)
fit <- sampling_parallel(sm, schools_dat, cores = 4L)
fit
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.