Create a greta_model
object representing a statistical model (using model
), and plot a graphical representation of the model. Statistical inference can be performed on greta_model
objects with mcmc
model(..., precision = c("single", "double"), n_cores = NULL, compile = TRUE) # S3 method for greta_model print(x, ...) # S3 method for greta_model plot(x, y, ...)
...
for model
: 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. For print
and plot
:further arguments passed to or from other methods (currently ignored).
precision
the floating point precision to use when evaluating this model. Switching from ‘single’
(the default) to ‘double’
should reduce the risk of numerical instability during sampling, but will also increase the computation time, particularly for large models.
n_cores
the number of cpu cores to use when evaluating this model. Defaults to and cannot exceed the number detected by parallel::detectCores
.
compile
whether to apply XLA JIT compilation to the tensorflow graph representing the model. This may slow down model definition, and speed up model evaluation.
x
a greta_model
object
y
unused default argument
model
- a greta_model
object.
plot
- a DiagrammeR::gdr_graph
object (invisibly).
model()
takes greta arrays as arguments, and defines a statistical model by finding all of the other greta arrays on which they depend, or which depend on them. Further arguments to model
can be used to configure the tensorflow graph representing the model, to tweak performance.
The plot method produces a visual representation of the defined model. It uses the DiagrammeR
package, which must be installed first. Here’s a key to the plots:
# define a simple model mu <- variable() sigma <- lognormal(1, 0.1) x <- rnorm(10) distribution(x) <- normal(mu, sigma) m <- model(mu, sigma) plot(m)