Description Usage Arguments Value Examples

Prepare user-defined variables to be passed to one of Stan's program blocks. This is primarily useful for defining more complex priors, for refitting models without recompilation despite changing priors, or for defining custom Stan functions.

1 2 3 4 5 6 7 8 |

`x` |
An |

`name` |
Optional character string providing the desired variable
name of the object in |

`scode` |
Line of Stan code to define the variable
in Stan language. If |

`block` |
Name of one of Stan's program blocks in
which the variable should be defined. Can be |

`position` |
Name of the position within the block where the
Stan code should be placed. Currently allowed are |

`pll_args` |
Optional Stan code to be put into the header
of |

An object of class `stanvars`

.

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 | ```
bprior <- prior(normal(mean_intercept, 10), class = "Intercept")
stanvars <- stanvar(5, name = "mean_intercept")
make_stancode(count ~ Trt, epilepsy, prior = bprior,
stanvars = stanvars)
# define a multi-normal prior with known covariance matrix
bprior <- prior(multi_normal(M, V), class = "b")
stanvars <- stanvar(rep(0, 2), "M", scode = " vector[K] M;") +
stanvar(diag(2), "V", scode = " matrix[K, K] V;")
make_stancode(count ~ Trt + zBase, epilepsy,
prior = bprior, stanvars = stanvars)
# define a hierachical prior on the regression coefficients
bprior <- set_prior("normal(0, tau)", class = "b") +
set_prior("target += normal_lpdf(tau | 0, 10)", check = FALSE)
stanvars <- stanvar(scode = "real<lower=0> tau;",
block = "parameters")
make_stancode(count ~ Trt + zBase, epilepsy,
prior = bprior, stanvars = stanvars)
# ensure that 'tau' is passed to the likelihood of a threaded model
# not necessary for this example but may be necessary in other cases
stanvars <- stanvar(scode = "real<lower=0> tau;",
block = "parameters", pll_args = "real tau")
make_stancode(count ~ Trt + zBase, epilepsy,
stanvars = stanvars, threads = threading(2))
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.