bprior <- prior(normal(mean_intercept, 10), class = "Intercept")
stanvars <- stanvar(5, name = "mean_intercept")
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;")
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 tau;",
block = "parameters")
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 tau;",
block = "parameters", pll_args = "real tau")
stancode(count ~ Trt + zBase, epilepsy,
stanvars = stanvars, threads = threading(2))
Run the code above in your browser using DataLab