
Unless I am misunderstanding what you're after, one thing you can do is just append the fitted values to the data frame (you will want to use math.lme3@frame in case of dropped observations) and from there pick out the predicted value for each student at age 15. All of the appropriate other effects should be factored in.

Jake

> Subject: RE: [R-sig-ME] How to calculate predictions
> From: slu@ccsr.uchicago.edu
> To: jake987722@hotmail.com
> CC: r-sig-mixed-models@r-project.org
> Date: Mon, 27 Feb 2012 16:42:48 -0600
> 
> On Mon, 2012-02-27 at 14:20 -0700, Jake Westfall wrote:
> > 1) Yes2) ?fitted
> 
> I don't think fitted is what I want. According to the docs, fitted
> returns the fitted conditional means of the responses. I want the
> predicted value when age-11 is 4, (age-11)^2 is 16, old4gr has the
> appropriate value, and all the individual random effects are included.
> 
> > > From: slu@ccsr.uchicago.edu
> > > To: r-sig-mixed-models@r-project.org
> > > Date: Mon, 27 Feb 2012 15:02:31 -0600
> > > Subject: [R-sig-ME] How to calculate predictions
> > > 
> > > Hello, I have modeled student math growth curves with lmer with a model
> > > like this. It predicts math achievement by age (centered at age 11) with
> > > a linear and quadratic term, with both these and the intercept varying
> > > randomly across students:
> > > 
> > > math.lme3 <- lmer(data=allmathgains, math ~ I(age-11) + I((age-11)^2) +
> > > old4gr + (I(age-11) + I((age-11)^2) | sid))
> > > 
> > > where sid is the student ID and old4gr take a value of 1 if the student
> > > is old for grade, 0 otherwise. I want to get a prediction of each
> > > student's achievement at age 15. I have done this kind of thing:
> > > 
> > > random.effects3 <- ranef(math.lme3)
> > > fixed.effects3 <- fixef(math.lme3)
> > > 
> > > ## Just try it for the first 100 students for now
> > > test <- random.effects3$sid[1:100,]
> > > test2 <- cbind(as.numeric(rownames(test)),
> > >                test[,1]+fixed.effects3[1],
> > >                test[,2]+fixed.effects3[2],
> > >                test[,3]+fixed.effects3[3])
> > >  
> > > test3 <- cbind(test2, allmathgains[1:100, "old4gr"])
> > >  
> > > to.predict <- as.data.frame(cbind(rep(1, 100), rep(4, 100), rep(16,
> > > 100)))
> > > to.predict2 <- cbind(to.predict, allmathgains[1:100, "old4gr"])
> > > 
> > > my.predictions <- numeric(100)
> > > for (i in 1:100) {
> > >   my.predictions[i] <- test3[i, 2:5] %*% t(as.matrix(to.predict2[i,]))
> > > }
> > > 
> > > My questions: 
> > > 1) Is my idea to add each random effect to the fixed effects (to make
> > > data.frame test2) correct? 
> > > 2) Is there a more efficient way of doing this? This is a big issue
> > > because I am working with a data set of about 240,000 students. 
> > > 
> > > Thanks in advance.
> > > -- 
> > > Stuart Luppescu -=- slu .at. ccsr.uchicago.edu        
> > > University of Chicago -=- CCSR 
> > > $B:MJ8$HCRF`H~$NIc(B -=-    Kernel 3.2.1-gentoo-r2                
> > > For the S system, which has forever altered the way
> > >  people analyze, visualize, and manipulate data
> > >  .... S is an elegant, widely accepted, and
> > >  enduring software system, with conceptual
> > >  integrity, thanks to the insight, taste, and
> > >  effort of John Chambers.    -- Association for
> > >  Computing Machinery       ACM/Software System
> > >  Award citation (1998)
> > > 
> > > _______________________________________________
> > > R-sig-mixed-models@r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >  		 	   		  
> 
> 
> -- 
> Stuart Luppescu -=- slu .at. ccsr.uchicago.edu        
> University of Chicago -=- CCSR 
> $B:MJ8$HCRF`H~$NIc(B -=-    Kernel 3.2.1-gentoo-r2                
> My institution has a particularly diabolical policy
>  on intellectual property, especially on software. 
>  -- Ross Ihaka       R-help (August 2003)   
>  
> 
> 
> 
> 
> 
> 
 		 	   		  
	[[alternative HTML version deleted]]


