getSimulations {DHARMa}R Documentation

Get model simulations

Description

Wrapper to simulate from a fitted model

Usage

getSimulations(object, nsim = 1, type = c("normal", "refit"), ...)

## Default S3 method:
getSimulations(object, nsim = 1, type = c("normal", "refit"), ...)

## S3 method for class 'negbin'
getSimulations(object, nsim = 1, type = c("normal", "refit"), ...)

## S3 method for class 'lmerMod'
getSimulations(object, nsim = 1, type = c("normal", "refit"), ...)

## S3 method for class 'glmmTMB'
getSimulations(object, nsim = 1, type = c("normal", "refit"), ...)

## S3 method for class 'HLfit'
getSimulations(object, nsim = 1, type = c("normal", "refit"), ...)

## S3 method for class 'MixMod'
getSimulations(object, nsim = 1, type = c("normal", "refit"), ...)

Arguments

object

a fitted model

nsim

number of simulations

type

if simulations should be prepared for getQuantile or for refit

...

additional parameters to be passed on, usually to the simulate function of the respective model class

Details

The purpose of this wrapper for for the simulate function is to return the simulations from a model in a standardized way

The function is a wrapper for for the simulate function is to return the simulations from a model in a standardized way.

Note: if the model was fit with weights, the function will throw a warning if used with a model class whose simulate function does not include the weightsi in the simulations. Note that the results may or may not be appropriate in this case, depending on how you use the weights.

Value

a matrix with simulations

Author(s)

Florian Hartig

See Also

getObservedResponse, getRefit, getFixedEffects, getFitted

Examples

testData = createData(sampleSize = 400, family = gaussian())

fittedModel <- lm(observedResponse ~ Environment1 , data = testData)

# response that was used to fit the model
getObservedResponse(fittedModel)

# predictions of the model for these points
getFitted(fittedModel)

# extract simulations from the model as matrix
getSimulations(fittedModel, nsim = 2)

# extract simulations from the model for refit (often requires different structure)
x = getSimulations(fittedModel, nsim = 2, type = "refit")

getRefit(fittedModel, x[[1]])

getRefit(fittedModel, getObservedResponse(fittedModel))

[Package DHARMa version 0.4.3 Index]