Learn R Programming

DHARMa (version 0.4.1)

getFitted: Get fitted / predicted values

Description

Wrapper to get the fitted / predicted response of model at the response scale

Usage

getFitted(object, ...)

# S3 method for default getFitted(object, ...)

# S3 method for default getResiduals(object, ...)

# S3 method for gam getFitted(object, ...)

# S3 method for HLfit getFitted(object, ...)

# S3 method for MixMod getFitted(object, ...)

Arguments

object

a fitted model

...

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

Details

The purpose of this wrapper is to standardize extract the fitted values, which is implemented via predict(model, type = "response") for most model classes.

If you implement this function for a new model class, you should include an option to modifying which REs are included in the predictions. If this option is not available, it is essential that predictions are provided marginally / unconditionally, i.e. without the random effect estimates (because of https://github.com/florianhartig/DHARMa/issues/43), which corresponds to re-form = ~0 in lme4

See Also

getObservedResponse, getSimulations, getRefit, getFixedEffects

Examples

Run this code
# NOT RUN {
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))
# }

Run the code above in your browser using DataLab