[R-sig-eco] prediction of fitted gam for newdata does not work

Aitor Gastón aitor.gaston at upm.es
Thu Jan 12 00:09:47 CET 2012


As you use "data=Hyla_Model" in the gam function, variable names should not 
include the data.frame or matrix name, try:

 model8<- gam(AES_Peak_modified ~ s(var1) +s(var2)+ var3 + var4, 
data=Hyla_Model, family = poisson)

Hope it helps,

Aitor


--------------------------------------------------
From: "Felisa Henrikus" <felisa.henrikus at googlemail.com>
Sent: Wednesday, January 11, 2012 6:05 PM
To: <r-sig-ecology at r-project.org>
Subject: [R-sig-eco] prediction of fitted gam for newdata does not work

> Hello,
>
> I calculated a GAM with Poisson distribution for tree frogs (mgcv and
> MASS).The original matrix on which the GAM is based contains 13 predictor
> variables (rows) and 49 sampling units (lines) and is called 'Hyla_Model'.
> Four of these predictor variables were significant and  two out of these 4
> entered the model as smoothed terms s(x) .The original matrix on which the
> GAM is based contains 13 predictor variables (rows) and 49 sampling units
> (lines) and is called 'Hyla_Model'. Four of these predictor variables were
> significant and  two out of these 4 entered the model as smoothed terms
> s(x):
>
> model8<- gam(Hyla_Model$AES_Peak_modified ~ s(Hyla_Model$var1 +
> s(Hyla_Model$var2)+ Hyla_Model$var3 + Hyla_Model$var4,  data=Hyla_Model,
> family = poisson)
>
>
> Now I want to make a prediction for unsettled habitats. Therefore I got a
> second matrix (looks exactly the same as said above with all 13 predictor
> variables, BUT only containing 19 sampling units(lines)).
>
>
> Unfortunatly I keep getting errors.....
>
> here my commands:
>
> east_Wittenberge<-read.table("C:\\Dokumente und
> Einstellungen\\Oestlich_Wittenberge_Matrix_komplett.txt",sep="",header=
> TRUE)
>
> predict.gam(model8, newdata=east_Wittenberge,type="link",se=T)
>
>
> here the error message:
>
> Error in model.frame.default(ff, data = newdata, na.action = na.act) :
>  invalid type (list) for variable 'Hyla_Model'
> In addition: Warning message:
> In predict.gam(model8, newdata = east_Wittenberge, type = "link",  :
>  not all required variables have been supplied in  newdata!
>
>
> It seems like R uses the original martix 'Hyla_Model´ somehow....???
>
> The GAM contains 4 significant predictor variables, two are smoothed 
> terms.
> In the new matrix east_Wittenberge none of these 4 predictors is 
> "smoothed"
> --> could this be a problem?
>
> Can anybody help me?
>
> Best wishes,
> Felisa
>
> [[alternative HTML version deleted]]
>
>



> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



More information about the R-sig-ecology mailing list