Hi,

I have used the mgcv library to generate a simple additive model. I want to 
know how to plot the function on the raw data with confidence intervals whan 
I have TWO variables in the model. I get it to work with one variable but 
not with two. I am on the limit for what I understand in R, so be gentle. I 
have read the help file on predict.gam, but did not get any help out of it.

#My model:
Model <- gam(var ~ s(var1, k=4) + s(var2, k=4), data = mydata)

# Plotting the model:
par(mfrow=c(1,1))
plot(Model ) #get a plot of the smoother
plot(var ~ var1, data = mydata) #plotting the raw data

##predictions from M1
pred.gam <- predict.gam(M1, se.fit=TRUE, type="response")

#Plotting the function and confidence intervals.
I <- order(mydata$Ncell)
lines(mydata$Ncell[I], pred.gam$fit[I], lwd = 2) 
lines(mydata$Ncell[I], pred.gam$fit[I] + 2 * pred.gam$se.fit[I], lty = 2, 
lwd = 2) 
lines(mydata$Ncell[I], pred.gam$fit[I] - 2 * pred.gam$se.fit[I], lty = 2, 
lwd = 2)

It all works fine if the model instead is:
ModelSimple <- gam(var ~ s(var1, k=4), data = mydata)

However, I get different results (for obvious reasons) if I predict from 
Model or ModelSimple.
Please, help me!!!! 
Anna

Anna Zakrisson Braeunlich
PhD Student

Department of Systems Ecology
Stockholm University
Svante Arrheniusv. 21A
SE-106 91 Stockholm

E-mail: a...@ecology.su.se
Tel work: +46 (0)8 161103
Mobile: +46-(0)700-525015
Web site: http://www.ecology.su.se/staff/personal.asp?id=163

><((((º>`•. . • `•. .• `•. . ><((((º>`•. . • `•. .• 
`•. .><((((º>


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to