inference_stan {makemyprior} | R Documentation |
Run inference
Description
This function helps you run inference with rstan using a prior object from make_prior.
Note that you must install Stan: install.packages("rstan")
, see mc-stan.org.
Usage
inference_stan(
prior_obj,
use_likelihood = TRUE,
print_prior = TRUE,
path = NULL,
...
)
Arguments
prior_obj |
An object from make_prior, from makemyprior_gui, from inference_stan, or from inference_inla (for refitting model) |
use_likelihood |
Whether to sample from the prior only ( |
print_prior |
Whether to print a text with the chosen prior or not (default |
path |
Path to folder. See compile_stan. Only necessary if compiled code is
stored somewhere else than in |
... |
Other arguments to be sent to sampling. Useful arguments include:
See sampling for more details. Note that for inference with |
Details
We cannot sample from a Jeffreys' prior since it is improper.
If use_likelihood = FALSE
and Jeffreys' prior is used for the total variance, the prior will be changed to a Gaussian(0,1) prior on
the log total variance. This means that it does not make sense to look at the variances/standard deviations/precisions,
but the variance proportions will be correct. Note that this is only an issue when sampling from the prior
(i.e., not using the likelihood).
Value
A named list with a prior object (prior
), a stan-object (stan
) and some data stan requires (stan_data
).
Examples
## Not run:
vignette("make_prior", package = "makemyprior")
## End(Not run)
ex_prior <- makemyprior_example_model()
if (interactive() && requireNamespace("rstan")){
posterior <- inference_stan(ex_prior, iter = 100)
# Note: For reliable results, increase the number of iterations (e.g., 'iter = 2000')
plot(posterior)
}
## Not run:
posterior <- inference_stan(ex_prior, use_likelihood = TRUE, iter = 1e4, chains = 1, seed = 1)
plot(posterior)
## End(Not run)