Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

simulate_nlme

Simulate samples from a nonlinear mixed model from fixed effects


Description

Simulate multiple samples from a nonlinear model

Usage

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

Arguments

object

object of class gnls or nlme

nsim

number of samples, default 1

psim

simulation level for vector of fixed parameters for simulate_nlme_one

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 to be passed to either simulate_gnls or simulate_nlme_one

Details

The details can be found in either simulate_gnls or simulate_nlme_one. This function is very simple and it only sets up a matrix and a loop in order to simulate several instances of model outputs.

Value

It returns a matrix with simulated values from the original object with number of rows equal to the number of rows of fitted and number of columns equal to the number of simulated samples (‘nsim’). In the case of ‘data.frame’ it returns an augmented data.frame, which can potentially be a very large object, but which makes furhter plotting more convenient.

Examples

require(nlme)
data(barley, package = "nlraa")
barley2 <- subset(barley, year < 1974)
fit.lp.gnls2 <- gnls(yield ~ SSlinp(NF, a, b, xs), data = barley2)
barley2$year.f <- as.factor(barley2$year)
cfs <- coef(fit.lp.gnls2)
fit.lp.gnls3 <- update(fit.lp.gnls2, 
                      params = list(a + b + xs ~ year.f),
                      start = c(cfs[1], 0, 0, 0, 
                                cfs[2], 0, 0, 0,
                                cfs[3], 0, 0, 0))
                                
sims <- simulate_nlme(fit.lp.gnls3, nsim = 3)

nlraa

Nonlinear Regression for Agricultural Applications

v0.89
GPL-3
Authors
Fernando Miguez [aut, cre] (<https://orcid.org/0000-0002-4627-8329>), José Pinheiro [ctb, cph] (author of nlme::nlsList, nlme::predict.gnls, nlme::predict.nlme), Douglas Bates [ctb, cph] (author of nlme::nlsList, nlme::predict.gnls, nlme::predict.nlme), R-core [ctb, cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.