Tor A Strand
2003-Jul-12 16:50 UTC
[R] question regarding GAM from a novice (in GAM as well as in R)
Need to use generalized additive models and have therefore obtained R I am able to do the analysis but I have problems understanding the syntax and the options Can someone explain what some of the terms do in this model do:? c<-gam(depvar~var1+var2+s(var3)+s(var4, by=var5)+s(var6, var7)+s(var8,3), data=xdataset ) I do not use the terms including var4- var8 in my model, just want to know what they do. +s(var4, by=var5) +s(var6, var7) +s(var8,3) Furthermore, the results become rather different when I change the model to: c<-gam(depvar~var1+var2-1+s(var3)+s(var4, by=var5)+s(var6, var7)+s(var8,3), data=xdataset ) # note just adding a -1 Why. Please forgive my ignorance. Dr. Tor A Strand Centre for International Health Haukeland Hospital University of Bergen 5021 Bergen Norway Phone: (country prefix 47) Residence:56 51 10 88, office: 55 97 49 80, fax: 55 97 49 79, cellular: 90 97 10 86
kjetil brinchmann halvorsen
2003-Jul-12 22:22 UTC
[R] question regarding GAM from a novice (in GAM as well as in R)
On 12 Jul 2003 at 18:50, Tor A Strand wrote: Hei!> Need to use generalized additive models and have therefore obtained R > > I am able to do the analysis but I have problems understanding the syntax > and the options > > Can someone explain what some of the terms do in this model do:? > > c<-gam(depvar~var1+var2+s(var3)+s(var4, by=var5)+s(var6, var7)+s(var8,3), > data=xdataset ) > > I do not use the terms including var4- var8 in my model, just want to know > what they do. > > +s(var4, by=var5)Presumably var5 is a factor, separate smooths are calculated for each level of the factor. This is a kind of interaction.> +s(var6, var7)This looks like a bivariate smooth, that is , a surface. Never tried that.> +s(var8,3)second argument is the number of degrees of freedom.> > Furthermore, the results become rather different when I change the model to: > > c<-gam(depvar~var1+var2-1+s(var3)+s(var4, by=var5)+s(var6, var7)+s(var8,3), > data=xdataset ) > # note just adding a -1 > > Why.This is removing the intercept from the model, and as all smooths are centered at zero in some way, that should have more or less the same effect as removing the intercept from a linear model. That can make a HUGE difference.> > Please forgive my ignorance.You probably have a local expert at Haukeland: Try to call Tore Wenzel-Larsen if you need more help. Kjetil Halvorsen> > > Dr. Tor A Strand > Centre for International Health > Haukeland Hospital > University of Bergen > 5021 Bergen > Norway > Phone: (country prefix 47) > Residence:56 51 10 88, office: 55 97 49 80, > fax: 55 97 49 79, cellular: 90 97 10 86 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Tor A Strand
2003-Jul-13 22:45 UTC
[R] question regarding GAM from a novice (in GAM as well as in R)
On 7/13/03 12:22 AM, "kjetil brinchmann halvorsen" <kjetil at entelnet.bo> wrote:> On 12 Jul 2003 at 18:50, Tor A Strand wrote: > > Hei! > >> Need to use generalized additive models and have therefore obtained R >> >> I am able to do the analysis but I have problems understanding the syntax >> and the options >> >> Can someone explain what some of the terms do in this model do:? >> >> c<-gam(depvar~var1+var2+s(var3)+s(var4, by=var5)+s(var6, var7)+s(var8,3), >> data=xdataset ) >> >> I do not use the terms including var4- var8 in my model, just want to know >> what they do. >> >> +s(var4, by=var5) > > Presumably var5 is a factor, separate smooths are calculated for each > level of the factor. This is a kind of interaction. > >> +s(var6, var7) > > This looks like a bivariate smooth, that is , a surface. Never tried > that. > >> +s(var8,3) > > second argument is the number of degrees of freedom. > >> >> Furthermore, the results become rather different when I change the model to: >> >> c<-gam(depvar~var1+var2-1+s(var3)+s(var4, by=var5)+s(var6, var7)+s(var8,3), >> data=xdataset ) >> # note just adding a -1 >> >> Why. > > This is removing the intercept from the model, and as all smooths are > centered at zero in some way, that should have more or less the same > effect as removing the intercept from a linear model. That can make a > HUGE difference. > >> >> Please forgive my ignorance. > > You probably have a local expert at Haukeland: Try to call > Tore Wenzel-Larsen if you need more help. > > Kjetil Halvorsen >All of the above were extremely useful. I will also ask Tore. Thanks
Simon Wood
2003-Jul-14 10:14 UTC
[R] question regarding GAM from a novice (in GAM as well as in R)
> > Can someone explain what some of the terms do in this model do:? > > c<-gam(depvar~var1+var2+s(var3)+s(var4, by=var5)+s(var6, var7)+s(var8,3), > data=xdataset ) > > I do not use the terms including var4- var8 in my model, just want to know > what they do. > > +s(var4, by=var5)- var5 is a variable multiplying this smooth of var4. i.e. the model is something like: E(depvar_i) = .... f(var4_i)var5_i + ... e_i where f is a smooth function. Models like this are sometimes called variable coefficient models (see Hastie and Tibhirani JRSSB 1993?)> +s(var6, var7)- A smooth function of two variables: var6 and var7 (you can, in principle have smooths of any number of variables.)> +s(var8,3)old form of s(var8,k=3,bs="cr") uses a cubic regression spline basis with 3 knots to represent the smooth function of var8. Note that default k for a 1-d smooth is 10, and default basis is "tp" - a thin plate regression spline. The default basis is usually slightly better, and admits smooths of several variables, but the "cr" basis is much quicker computatioanlly.> Furthermore, the results become rather different when I change the model to: > > c<-gam(depvar~var1+var2-1+s(var3)+s(var4, by=var5)+s(var6, var7)+s(var8,3), > data=xdataset )- *iff* var1 and var2 are not factors, then this is a model with no intercept term, and the mean of the fitted values will be zero. Hence the big change! Simon _____________________________________________________________________> Simon Wood simon at stats.gla.ac.uk www.stats.gla.ac.uk/~simon/ >> Department of Statistics, University of Glasgow, Glasgow, G12 8QQ >>> Direct telephone: (0)141 330 4530 Fax: (0)141 330 4814