Thanks. I wonder if there is a general way of extracting var(u) and var(e), which would be needed to simulate u and e. Clearly, one can get the estimated parameters, but is there a clever way of 'setting up' the matrices?? Best S??ren On 6/19/05, S??ren H??jsgaard <Soren.Hojsgaard at agrsci.dk> wrote:> I would like to draw a sample from a linear mixed model y=Xb+Zu+e which has been fitted with lme(), i.e. a model y ~ N(Xb, C), where C=Z cov(u) Z' + cov(e). > I've tried to figure out how to extract C from an lme object, because that would solve my problem when also using the predict() function, but without any luck. > Can anyone help on that?C is not stored in an lme object. In fact it is never created. (Consider the dimensions of this matrix. It could be huge.) The easiest way to simulate data from a linear mixed model is to simulate u and e then form Xb+Zu+e ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Have you considered "simulate.lme"? Also, have you read Pinheiro and Bates (2000) Mixed-Effects Models in S and S-Plus (Springer). It is excellent. spencer graves S??ren H??jsgaard wrote:> Thanks. I wonder if there is a general way of extracting var(u) and var(e), which would be needed to simulate u and e. Clearly, one can get the estimated parameters, but is there a clever way of 'setting up' the matrices?? > Best > S??ren > > On 6/19/05, S??ren H??jsgaard <Soren.Hojsgaard at agrsci.dk> wrote: > >>I would like to draw a sample from a linear mixed model y=Xb+Zu+e which has been fitted with lme(), i.e. a model y ~ N(Xb, C), where C=Z cov(u) Z' + cov(e). >>I've tried to figure out how to extract C from an lme object, because that would solve my problem when also using the predict() function, but without any luck. >>Can anyone help on that? > > > C is not stored in an lme object. In fact it is never created. > (Consider the dimensions of this matrix. It could be huge.) > > The easiest way to simulate data from a linear mixed model is to > simulate u and e then form Xb+Zu+e > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
On 6/20/05, S?ren H?jsgaard <Soren.Hojsgaard at agrsci.dk> wrote:> Thanks. I wonder if there is a general way of extracting var(u) and var(e), which would be needed to simulate u and e. Clearly, one can get the estimated parameters, but is there a clever way of 'setting up' the matrices?? > Best > S??renThe short answer is that the result of VarCorr applied to a fitted lmer model gives the variance-covariance matrix of the random effects and the variance of the noise term. I enclose a function that can be used to simulate data somewhat more efficiently from a fitted lmer model. It uses some of the intermediate values that have been stored in the object. At least I think this lmerSim function works. It takes two arguments, the first is the fitted model and the second is the number of data sets to simulate. It uses the estimated fixed effects from the model. An enhancement would be to allow the fixed effects to be given as a third argument.> On 6/19/05, S??ren H??jsgaard <Soren.Hojsgaard at agrsci.dk> wrote: > > I would like to draw a sample from a linear mixed model y=Xb+Zu+e which has been fitted with lme(), i.e. a model y ~ N(Xb, C), where C=Z cov(u) Z' + cov(e). > > I've tried to figure out how to extract C from an lme object, because that would solve my problem when also using the predict() function, but without any luck. > > Can anyone help on that? > > C is not stored in an lme object. In fact it is never created. > (Consider the dimensions of this matrix. It could be huge.) > > The easiest way to simulate data from a linear mixed model is to > simulate u and e then form Xb+Zu+e > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > > >
Reasonably Related Threads
- How to sample from a linear mixed model
- Calling substitute(expr, list(a=1)) when expr <- expression(a+b+c)
- Drawing a graph with vertices and edges using tcl/tk
- Computer algebra in R - would that be an idea??
- lattice/xyplot: plotting 4 variables in two panels - can this be done?