Hi, I am comparing the observed and fitted values of my GAM model, which includes the explanatory variables: longitude, depth, ssh, year and month. When I compare observed and fitted values for longitude, depth and ssh it works. But when I try to do it for month and year (which are as factors in the GAM model) it doesn't work. My observed and fitted values are exactly the same.. How is that possible? Thanks> Obs_factor1<-aggregate(x=albdata$turtles,by=list(albdata$Year),FUN=mean) > names(Obs_factor1)=c("Bin","Observed") > Obs_factor1Bin Observed 1 1997 0.017094017 2 1998 0.010652463 3 1999 0.023000000 4 2000 0.017167382 5 2001 0.030465950 6 2002 0.007446809 7 2003 0.010568032 8 2004 0.011450382 9 2005 0.016270338 10 2006 0.017006803 11 2007 0.030969031 12 2008 0.066455696> Fit_factor1<-aggregate(x=predict(gam.def.lon,type="response"),by=list(albdata$Year),FUN=mean) > names(Fit_factor1)=c("Bin","Fitted") > Fit_factor1Bin Fitted 1 1997 0.017094017 2 1998 0.010652463 3 1999 0.023000000 4 2000 0.017167382 5 2001 0.030465950 6 2002 0.007446809 7 2003 0.010568032 8 2004 0.011450382 9 2005 0.016270338 10 2006 0.017006803 11 2007 0.030969031 12 2008 0.066455696 [[alternative HTML version deleted]]
On Aug 21, 2009, at 5:03 PM, Luc?a Rueda wrote:> Hi, > > I am comparing the observed and fitted values of my GAM model, which > includes the explanatory variables: longitude, depth, ssh, year and > month. When I compare observed and fitted values for longitude, > depth and ssh it works. But when I try to do it for month and year > (which are as factors in the GAM model) it doesn't work. My observed > and fitted values are exactly the same..So then, you are complaining because it "works" but _unexpectedly_ well.> How is that possible? ThanksIf you have a balanced design in Year and it is the only covariate, then that is precisely what should happen with any regression method: > newdat <- data.frame(val=rnorm(40), cat=factor(1:4)) > aggregate(newdat$val, list(newdat$cat), mean) Group.1 x 1 1 0.4972092 2 2 -0.1042936 3 3 0.1549305 4 4 -0.1500513 > lm(val~cat, newdat) Call: lm(formula = val ~ cat, data = newdat) Coefficients: (Intercept) cat2 cat3 cat4 0.4972 -0.6015 -0.3423 -0.6473 > 0.4972092 + coef(lm(val~cat, newdat))[2:4] cat2 cat3 cat4 -0.1042937 0.1549304 -0.1500514> snipped output from OP-- David Winsemius, MD Heritage Laboratories West Hartford, CT
You haven't given quite enough information to be sure, but I would guess that this is not really a problem, but rather the interesting proporty of GLMs fitted with a canonical link described in e.g. section 2.1.8 of Wood (2006) Generalized additive models: and introduction with R, or at the beginning of the GLM chapter in Venables and Ripley MASS. On Friday 21 August 2009 22:03, Luc??a Rueda wrote:> Hi, > > I am comparing the observed and fitted values of my GAM model, which > includes the explanatory variables: longitude, depth, ssh, year and month. > When I compare observed and fitted values for longitude, depth and ssh it > works. But when I try to do it for month and year (which are as factors in > the GAM model) it doesn't work. My observed and fitted values are exactly > the same.. How is that possible?? Thanks > > > Obs_factor1<-aggregate(x=albdata$turtles,by=list(albdata$Year),FUN=mean) > > names(Obs_factor1)=c("Bin","Observed") > > Obs_factor1 > > ??? Bin??? Observed > 1? 1997 0.017094017 > 2? 1998 0.010652463 > 3? 1999 0.023000000 > 4? 2000 0.017167382 > 5? 2001 0.030465950 > 6? 2002 0.007446809 > 7? 2003 0.010568032 > 8? 2004 0.011450382 > 9? 2005 0.016270338 > 10 2006 0.017006803 > 11 2007 0.030969031 > 12 2008 0.066455696 > > > Fit_factor1<-aggregate(x=predict(gam.def.lon,type="response"),by=list(alb > >data$Year),FUN=mean) names(Fit_factor1)=c("Bin","Fitted") > > Fit_factor1 > > ??? Bin????? Fitted > 1? 1997 0.017094017 > 2? 1998 0.010652463 > 3? 1999 0.023000000 > 4? 2000 0.017167382 > 5? 2001 0.030465950 > 6? 2002 0.007446809 > 7? 2003 0.010568032 > 8? 2004 0.011450382 > 9? 2005 0.016270338 > 10 2006 0.017006803 > 11 2007 0.030969031 > 12 2008 0.066455696 > > > > > > > [[alternative HTML version deleted]]--> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK > +44 1225 386603 www.maths.bath.ac.uk/~sw283