These methods generate simulated response vectors from the multivariate normal distribution implied by a fitted gls or lme model. The simulation accounts for the fitted mean and covariance structure of the model.

# S3 method for class 'gls'
simulate(object, nsim = 1, seed = NULL, ...)

# S3 method for class 'lme'
simulate(object, nsim = 1, seed = NULL, ...)

Arguments

object

A fitted gls or lme object (from the nlme package).

nsim

Number of simulated datasets to generate (default is 1).

seed

Optional random seed for reproducibility.

...

Additional arguments (currently ignored).

Value

A data frame with nsim simulated response vectors as columns. Each column represents one simulated replicate of the response under the model's implied distribution.

Details

For gls objects, the mean vector is the fitted values and the covariance matrix is obtained via cov_matrix(). For lme objects, the mean vector is the level-0 (population) predicted values and the covariance matrix is also obtained via cov_matrix().

Examples

if (require(nlme)) {
  NSIM <- 10
  ## Example for gls
  fit_gls <- gls(distance ~ age, data = Orthodont)
  sims_gls <- simulate(fit_gls, nsim = NSIM, seed = 123)
  head(sims_gls)

  ## Example for lme
  fit_lme <- lme(distance ~ age, random = ~ 1 | Subject, data = Orthodont)
  sims_lme <- simulate(fit_lme, nsim = NSIM, seed = 123)
  head(sims_lme)
}
#> Error in UseMethod("simulate"): no applicable method for 'simulate' applied to an object of class "gls"