simulate_lme: Simulate values from an object of class 'lme'

View source: R/simulate_lme.R

simulate_lmeR Documentation

Simulate values from an object of class lme

Description

Simulate values from an object of class lme. Unequal variances, as modeled using the ‘weights’ option are supported, and there is experimental code for considering the ‘correlation’ structure.

Usage

simulate_lme(
  object,
  nsim = 1,
  psim = 1,
  value = c("matrix", "data.frame"),
  data = NULL,
  ...
)

Arguments

object

object of class lme or gls

nsim

number of samples, default 1

psim

parameter simulation level, 0: for fitted values, 1: for simulation from fixed parameters (assuming a fixed vcov matrix), 2: for simulation considering the uncertainty in the residual standard error (sigma), this returns data which will appear similar to the observed values. 3: in addition samples a new set of random effects.

value

whether to return a matrix (default) or an augmented data frame

data

the data argument is needed when using this function inside user defined functions.

...

additional arguments (it is possible to supply a newdata this way)

Details

This function is based on predict.lme function

It uses function mvrnorm to generate new values for the coefficients of the model using the Variance-Covariance matrix vcov. This variance-covariance matrix refers to the one for the parameters 'beta', not the one for the residuals.

Value

It returns a vector with simulated values with length equal to the number of rows in the original data

Note

I find the simulate.merMod in the lme4 pacakge confusing. There is use.u and several versions of re.form. From the documentation it seems that if use.u = TRUE, then the current values of the random effects are used. This would mean that it is equivalent to psim = 2 in this function. Then use.u = FALSE, would be equivalent to psim = 3. re.form allows for specifying the formula of the random effects.

See Also

predict.lme and ‘simulate.merMod’ in the ‘lme4’ package.

Examples


require(nlme)
data(Orange)

fm1 <- lme(circumference ~ age, random = ~ 1 | Tree, data = Orange)

sims <- simulate_lme(fm1, nsim = 10)



nlraa documentation built on May 29, 2024, 2:01 a.m.