Hi everybody, I am trying to fit a GAM model without intercept using library mgcv. However, the result has nothing to do with the observed data. In fact the predicted points are far from the predicted points obtained from the model with intercept. For example: #First I generate some simulated data: library(mgcv) x<-seq(0,10,length=100) y<-x^2+rnorm(100) #then I fit a gam model with and without intercept m1<-gam(y~s(x,k=10,bs='cs')) m2<-gam(y~s(x,k=10,bs='cs')-1) #and now I obtain predicted values for the interval 0-1 x1<-seq(0,10,0.1) y1<-predict(m1,newdata=list(x=x1)) y2<-predict(m2,newdata=list(x=x1)) #plotting predicted values plot(x,y,ylim=c(0,100)) lines(x1,y1,lwd=4,col='red') lines(x1,y2,lwd=4,col='blue') In this example you can see that the red line are the predicted points from the model with intercept which fit pretty good to the data, but the blue line (without intercept) is far from the observed points. Probably I missunderstanding some key elements in gam modelling or using incorrect syntaxis. I don't know what the problem is. Any ideas will be helpful. Sergio -- Sergio A. Estay Inst. Ciencias Ambientales y Evolutivas Universidad Austral de Chile Casilla 567, Valdivia, Chile Phone: 5663-293913 http://www.ciencias.uach.cl/instituto/ciencias_ambientales_evolutivas/academicos/sergio-estay.php -- View this message in context: http://r.789695.n4.nabble.com/GAM-without-intercept-tp4645786.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
Hi Sergio, based on my understanding ( see Wood Generalized Additive Model) smoothing basis incorporates the intercept already, due to identifiable issues. Therefore the intercept is always specified and you don't need to specify. I guess that your m2 to model is simply not correct. Hope it helps Anna Anna Freni Sterrantino Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. ________________________________ Da: SAEC <sergio.estay@uach.cl> A: r-help@r-project.org Inviato: Giovedì 11 Ottobre 2012 0:22 Oggetto: [R] GAM without intercept Hi everybody, I am trying to fit a GAM model without intercept using library mgcv. However, the result has nothing to do with the observed data. In fact the predicted points are far from the predicted points obtained from the model with intercept. For example: #First I generate some simulated data: library(mgcv) x<-seq(0,10,length=100) y<-x^2+rnorm(100) #then I fit a gam model with and without intercept m1<-gam(y~s(x,k=10,bs='cs')) m2<-gam(y~s(x,k=10,bs='cs')-1) #and now I obtain predicted values for the interval 0-1 x1<-seq(0,10,0.1) y1<-predict(m1,newdata=list(x=x1)) y2<-predict(m2,newdata=list(x=x1)) #plotting predicted values plot(x,y,ylim=c(0,100)) lines(x1,y1,lwd=4,col='red') lines(x1,y2,lwd=4,col='blue') In this example you can see that the red line are the predicted points from the model with intercept which fit pretty good to the data, but the blue line (without intercept) is far from the observed points. Probably I missunderstanding some key elements in gam modelling or using incorrect syntaxis. I don't know what the problem is. Any ideas will be helpful. Sergio -- Sergio A. Estay Inst. Ciencias Ambientales y Evolutivas Universidad Austral de Chile Casilla 567, Valdivia, Chile Phone: 5663-293913 http://www.ciencias.uach.cl/instituto/ciencias_ambientales_evolutivas/academicos/sergio-estay.php -- View this message in context: http://r.789695.n4.nabble.com/GAM-without-intercept-tp4645786.html Sent from the R help mailing list archive at Nabble.com. [[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. [[alternative HTML version deleted]]
Smooth terms are constrained to sum to zero over the covariate values. This is an identifiability constraint designed to avoid confounding with the intercept (particularly important if you have more than one smooth). If you remove the intercept from you model altogether (m2) then the smooth will still sum to zero over the covariate values, which in your case will mean that the smooth is quite a long way from the data. When you include the intercept (m1) then the intercept is effectively shifting the constrained curve up towards the data, and you get a nice fit. So it's not quite true that m2 has nothing to do with the data. The curve you get is as close to the data as a curve constrained to average to zero can get. best, Simon On 10/10/12 23:22, SAEC wrote:> Hi everybody, > > I am trying to fit a GAM model without intercept using library mgcv. > However, the result has nothing to do with the observed data. In fact > the predicted points are far from the predicted points obtained from the > model with intercept. For example: > > #First I generate some simulated data: > > library(mgcv) > x<-seq(0,10,length=100) > y<-x^2+rnorm(100) > > #then I fit a gam model with and without intercept > > m1<-gam(y~s(x,k=10,bs='cs')) > m2<-gam(y~s(x,k=10,bs='cs')-1) > > #and now I obtain predicted values for the interval 0-1 > > x1<-seq(0,10,0.1) > y1<-predict(m1,newdata=list(x=x1)) > y2<-predict(m2,newdata=list(x=x1)) > > #plotting predicted values > > plot(x,y,ylim=c(0,100)) > lines(x1,y1,lwd=4,col='red') > lines(x1,y2,lwd=4,col='blue') > > In this example you can see that the red line are the predicted points > from the model with intercept which fit pretty good to the data, but the > blue line (without intercept) is far from the observed points. > > Probably I missunderstanding some key elements in gam modelling or using > incorrect syntaxis. I don't know what the problem is. Any ideas will be > helpful. > > Sergio > > > > > > >-- Simon Wood, Mathematical Science, University of Bath BA2 7AY UK +44 (0)1225 386603 http://people.bath.ac.uk/sw283