simulate_residual: Convert a 'greta_mcmc_list' to a 'DHARMa' object

View source: R/simulate_residual.r

simulate_residualR Documentation

Convert a greta_mcmc_list to a DHARMa object

Description

Create a DHARMa object from a fitted greta model.

Usage

simulate_residual(object, y, linpred, nsim = 10, integerResponse = FALSE)

Arguments

object

A greta_mcmc_list object obtained from the greta::mcmc function

y

A greta array of the response variable, see example

linpred

A greta array of the expected value of y (typically the linear predictor in GLMM)

nsim

A numeric, the number of posterior simulation to draw, default is 10

integerResponse

A logical, whether the response variable is of integer type (binomial or poisson distribution). If TRUE, noise will be added to the residuals to maintain uniform expectations. Default is FALSE.

Details

For hierarchical models the linear predictor can be set conditional to the random terms, or unconditional to them. Best practice seems to be to define the linear predictor (the predictions) unconditional from the random effects (see DHARMa issues 43). DHARMa objects come with many methods to check (among other): model miss-fit, overdispersion, spatial or temporal autocorrelation ... Check the DHARMa manual for examples and options.

Value

A DHARMa object that allows plenty of model checks methods from the DHARMa package.

Examples

## Not run: 

x <- runif(100, -2, 2)
y <- rnorm(100, 1 + 2 * x, 1)
y <- as_data(y)

intercept <- normal(0, 1)
slope <- normal(0, 1)
linpred <- intercept + slope * x
sd_res <- cauchy(0, 1, truncation = c(0, 50))

distribution(y) <- normal(linpred, sd_res)
m <- model(intercept, slope, sd_res)
d <- mcmc(m)

sims <- simulate_residual(d, y, linpred)
plot(sims)

## End(Not run)


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