prior_check: Prior predictive checks for greta models

View source: R/prior_check.r

prior_checkR Documentation

Prior predictive checks for greta models

Description

Perform prior predictive checks on a greta model object

Usage

prior_check(y, fun = "mean", probs = c(0.1, 0.9), nsim = 100)

Arguments

y

A greta array of the response variable

fun

A character, the name of the function to apply to the simulated response values, default is "mean". Custom functions can also be passed, see examples.

probs

A vector of two numeric, the lower and upper bound of the predictive interval

nsim

A numeric, the number of simulation draws, default is 100

Details

Prior predictive checks allow a better tuning of the prior distribution of the model parameters by checking simulated new draws of the response. For instance, if we want to model the speed of migratory birds, we do not expect the maximum value of simulated draws from the priors to be beyond 100 of km/h.

Value

A character string of the form: XX of the nsim simulated response from the prior distributions had a fun value between XX and XX.

Examples

## Not run: 

# a simple lm example
intercept <- normal(0, 1)
slope <- normal(0, 1)
sd_resid <- cauchy(0, 1, truncation = c(0, 100))
x <- runif(100)
y <- as_data(rnorm(100, 1 + 2 * x, 1))
linpred <- intercept + slope * x
distribution(y) <- normal(linpred, sd_resid)
prior_check(y)

# can also use custom function, like counting number 
# of zero observations to check for zero-inflation
count0 <- function(x){
sum(x==0)
}

# a poisson regression
intercept <- normal(0, 1)
slope <- normal(0, 1)
x <- runif(100)
y <- as_data(rpois(100, exp(0.001 + 1 * x, 1))
linpred <- intercept + slope * x
distribution(y) <- poisson(linpred)
prior_check(y, fun = "count0")


## End(Not run)


lionel68/greta.checks documentation built on July 30, 2022, 11:39 a.m.