Note: the simulated data using simulate.lme does not match elements of the original data structure or model fit (eg. variance, effect size...) nor does it creation of data de novo for experimental design testing.
require(nlme)
?nlme::simulate.lme
fit <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1)
orthSim <- simulate.lme(fit, nsim = 1)
This produces a simulated fitting (with a possible alternative model).
This is thanks to an answer by @Momo on one of my questions:
Is there a general method for simulating data from a formula or analysis available?
If you require the simulated data, you will need to create a new function from the simulate.lme function.
simulate.lme.data<-edit(simulate.lme)
add the following line right before the last bracket
return(base2)
You can then create as much data as you want:
orthSimdata <- simulate.lme.data(fit, nsim = 1)
Note this is from my (possibly mis-)interpretation of the un-commented code in simulate.lme.
Though this is useful, this seems to do little less than add gaussian noise to your existing data.
This can not be used to directly simulate data de novo. I currently create the start data by adding the numeric value of the factors levels of my experimental design data frame (eg. response=as.numeric(factor1)+as.numeric(factor2)+as.numeric(factor1)*as.numeric(factor1)+rnorm(sd=2)...).