[R-sig-ME] nlme model.matrix problem for prediction intervals

Ben Bolker bbolker at gmail.com
Wed Sep 12 18:58:16 CEST 2012


Andrew Close <andrew.close at ...> writes:


> I am trying to generate prediction intervals for an nlme model by
>  following the example provided in http://glmm.wikidot.com/faq

> I have encountered a problem when  calculating "predvar" and 
> an error message is produced.
> 
> The problem, as far as I can tell, 
> is actually in creating the model matrix: "Error in Designmat %*%
> fm1$varFix : non-conformable arguments"

  The basic problem is that the code on that page is intended for
*linear* models.  In order to do the equivalent construction for
a nonlinear model, I believe you'd have to compute the linearization
(i.e. the gradient of the response variable with respect to each of 
the parameters) at each specified prediction point.  This is certainly
do-able, but doing it automatically by extracting information from
the model could be a little tricky.

  Perhaps someone will step forward with a solution ...


  Ben Bolker

> Here is the code I have used
> 
> library(nlme)
> 
> ##
> fm1 <- nlme(height ~ SSasymp(age, Asym, R0, lrc),
> data = Loblolly,
> fixed = Asym + R0 + lrc ~ 1,
> random = Asym ~ 1,
> start = c(Asym = 103, R0 = -8.5, lrc = -3.3))
> 
> newLoblolly$pred<-predict(fm1, newLoblolly)
> newLoblolly <- expand.grid(age = c(5,10,15,20,25,30), Seed = c(301,327))
> newLoblolly$pred<-predict(fm1, newLoblolly, level=0)
> 
> Designmat <- model.matrix(eval(eval(fm1$call$model)[-2]), newLoblolly[-3])
> Designmat



More information about the R-sig-mixed-models mailing list