Learn R Programming

greta (version 0.1.5)

greta-inference: Statistical Inference on Greta Models

Description

Define a greta_model object and carry out statistical inference on parameters of interest by MCMC

Usage

define_model(...)

mcmc(model, method = c("hmc"), n_samples = 1000, thin = 1, warmup = 100, verbose = TRUE, control = list(), initial_values = NULL)

Arguments

greta_array objects to be tracked by the model (i.e. those for which samples will be retained during mcmc). If not provided, all of the non-data greta_array objects defined in the calling environment will be tracked.
model
greta_model object
method
the method used to sample values. Currently only hmc is implemented
n_samples
the number of samples to draw (after any warm-up, but before thinning)
thin
the thinning rate; every thin samples is retained, the rest are discarded
warmup
the number of samples to spend warming up the sampler. During this phase the sampler moves toward the highest density area and may tune sampler hyperparameters.
verbose
whether to print progress information to the console
control
an optional named list of hyperparameters and options to control behaviour of the sampler
initial_values
an optional named vector of initial values for the free parameters in the model

Value

define_model - a greta_model object. See greta-model for details.

mcmc - an mcmc.list object that can be analysed using functions from the coda package. This will on contain mcmc samples of the parameters of interest, as defined in model.

Examples

Run this code

## Not run: ------------------------------------
# 
# # define a simple model
# mu = free()
# sigma = lognormal(1, 0.1)
# x = rnorm(10)
# likelihood(x) = normal(mu, sigma)
# 
# m <- define_model(mu, sigma)
# 
## ---------------------------------------------
## Not run: ------------------------------------
# # carry out mcmc on the model
# draws <- mcmc(m,
#               n_samples = 100,
#               warmup = 10)
## ---------------------------------------------

Run the code above in your browser using DataLab