Hi Steve,

Thanks for your comment. Unfortunately the predict function does not work with lme4, and therefore nor with gamm4.

The issue is what to do with random effects - and the fact that some random effects are to be incorporated (s-terms for additive model) but some are not (i-terms, or random effects at the individual level).

Justin
________________________________
From: Steve Candy [Steve.Candy@aad.gov.au]
Sent: 30 July 2013 08:03
To: Grace, Justin
Subject: [R-sig-ME] Using a gamm4 model to predict estimates in new [SEC=UNCLASSIFIED]


Hi Justin



I use Simon Wood’s {mgcv} gamm.



I haven’t used gamm4 but using gamm I get (marginal) predictions successfully using either the fitting dataset or new data using e.g.



For fitting dataset



gamm.pred <- predict(object=gamm.01$gam,type="link",se.fit=TRUE)





cheers



Steve







From: "Grace, Justin" <justin.grace@kcl.ac.uk<mailto:justin.grace@kcl.ac.uk>>

To: "r-sig-mixed-models@r-project.org<mailto:r-sig-mixed-models@r-project.org>"

      <r-sig-mixed-models@r-project.org<mailto:r-sig-mixed-models@r-project.org>>

Subject: [R-sig-ME] Using a gamm4 model to predict estimates in new

      data

Message-ID:

      <A042DBD144258E4E99FFFB9970610C991A6E10AC@AMSPRD0310MB349.eurprd03.prod.outlook.com<mailto:A042DBD144258E4E99FFFB9970610C991A6E10AC@AMSPRD0310MB349.eurprd03.prod.outlook.com>>



Content-Type: text/plain



Dear group,



I have been experimenting with gamm4 to derive GAMMs of some repeated measures data.



The models looks very nice and seem to give more flexibility than my LMMs.



Ultimately I want to compare models not by the quality of their fit (also the reality of comparing LMM and GAMM fits seems complex?), but in the quality of their predictions in new data sets, and in simulated new data by MCMC.



With LMMs I predict using the fixed effects only using:

mm <- model.matrix(terms(lmer),newdata)

newdata$predicted <- mm %*% fixef(lmer)



This is fine since we are predicting in new individuals, with new independent random effects.



I cannot get this predict method to work with gamm4.



> mm <- model.matrix(terms(gamm4$mer), newdata)

Error in model.frame.default(object, data, xlev = xlev) :

  variable lengths differ (found for 'X')



I think this is because the GAM process creates new variables in order to transform predictor variables.

It is also complex, because I believe the transforms are stored as random effects, so I would need to extract these random effects, but not the "individual level" random effects.



Does anyone now how I can



a)      Extract just the tranform effect terms from the gamm4 model?



b)      make predictions into new data using gamm4?



c)       Extract the model specification of the GAMM so I could impliment it as a standalone algorithm?



d)      General advice?



Thanks,



Justin

-------------------------------------------------------------------

King's College London

Department of Primary Care and Public Health Sciences Division of Health and Social Care Research 7th Floor Capital House

42 Weston Street

London SE1 3QD



Tel: 020 7848 6638

Fax: 020 7848 6620




Dr Steven G. Candy
Senior Applied Statistician
Wildlife Conservation and Fisheries
Australian Antarctic Division
203 Channel Hwy, Kingston, Tasmania, 7050, Australia
ph: (+61) 3 62 323135


___________________________________________________________________________

    Australian Antarctic Division - Commonwealth of Australia
IMPORTANT: This transmission is intended for the addressee only. If you are not the
intended recipient, you are notified that use or dissemination of this communication is
strictly prohibited by Commonwealth law. If you have received this transmission in error,
please notify the sender immediately by e-mail or by telephoning +61 3 6232 3209 and
DELETE the message.
        Visit our web site at http://www.antarctica.gov.au/
___________________________________________________________________________

	[[alternative HTML version deleted]]

