getSimulations | R Documentation |

Wrapper to simulate from a fitted model

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 'gam' getSimulations(object, nsim = 1, type = c("normal", "refit"), mgcViz = TRUE, ...) ## 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"), ...)

`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 |

`mgcViz` |
whether simulations should be created with mgcViz (if mgcViz is available) |

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

The purpose of this function is to wrap or implement the simulate function of different model classes and thus return simulations from fitted models in a standardized way.

Note: GLMM and other regression packages often differ in how simulations are produced, and which parameters can be used to modify this behavior.

One important difference is how to modifiy which hierarchical levels are held constant, and which are re-simulated. In lme4, this is controlled by the re.form argument (see lme4::simulate.merMod). For other packages, please consort the help.

If the model was fit with weights and the respective model class does not include the weights in the simulations, getSimulations will throw a warning. The background is if weights are used on the likelihood directly, then what is fitted is effectively a pseudo likelihood, and there is no way to directly simulate from the specified likelihood. Whether or not residuals can be used in this case depends very much on what is tested and how weights are used. I'm sorry to say that it is hard to give a general recommendation, you have to consult someone that understands how weights are processed in the respective model class.

a matrix with simulations

Florian Hartig

`getObservedResponse`

, `getRefit`

, `getFixedEffects`

, `getFitted`

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))

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.