Learn R Programming

greta (version 0.1.7)

greta-distribution: Define a Distribution Over a greta Array

Description

distribution is used to link observed data, free parameters and other greta arrays with probability distributions. For example, distribution can be used to define the likelhood term for a model by using distribution on some observed data. likelihood is an alias for distribution. It is deprecated and will be removed in version 0.2.

Usage

distribution(greta_array) <- value

distribution(greta_array)

likelihood(greta_array) <- value

Arguments

greta_array
a greta array. For the assignment method it must be a greta array that doesn't already have a probability distribution.
value
a greta array with a distribution (see greta-distributions)

Details

The extract method returns the greta array if it has a distribution, or NULL if it doesn't. It has now real function, but is included for completeness

distribution can also be used to create truncated distributions, by first defining a greta array with constraints (the truncation) and then defining the distribution on that greta array. See below for an example.

Examples

Run this code

# define a model likelihood

# observed data and mean parameter to be estimated
# (explicitly coerce data to a greta array so we can refer to it later)
y = as_data(rnorm(5, 0, 3))
mu = free()
# define the distribution over y (the model likelihood)
distribution(y) = normal(mu, 1)

# get the distribution over y
distribution(y)

# define a truncated-positive standard normal random variable
tn = free(lower = 0)
distribution(tn) = normal(0, 1)

Run the code above in your browser using DataLab