[R] gam

Henric Nilsson henric.nilsson at statisticon.se
Fri Jan 20 12:06:07 CET 2006


I.Szentirmai said the following on 2006-01-19 19:43:

 > Dear R users,
 >
 > I'm new to both R and to this list and would like to get
 > advice on how to build generalized additive models in R.
 > Based on the description of gam, which I found on the R

Which `gam'? Note that R ships with package `mgcv' which has a `gam' 
function, but also package `gam' on CRAN has a `gam' function. 
(Furthermore, several other packages exists with functions that I'd 
categorize as GAM-fitters, e.g. SemiPar, assist, gss, gamlss, ...)

 > website, I specified the following model:
 > model1<-gam(ST~s(MOWST1),family=binomial,data=strikes.S),
 > in which ST is my binary response variable and MOWST1 is a
 > categorical independent variable.
 >
 > I get the following error message:
 > Error in smooth.construct.tp.smooth.spec(object, data,

 From this error message, I can however deduce that we're talking about 
the `mgcv::gam' function.

 > knots) :
 >          NA/NaN/Inf in foreign function call (arg 1)
 > In addition: Warning messages:
 > 1: argument is not numeric or logical: returning NA in:
 > mean.default(xx)
 > 2: - not meaningful for factors in: Ops.factor(xx,
 > shift[i])
 >
 > I would greatly appreciate if someone could tell me what I
 > did wrong. Can I use categorical independents in gam at
 > all?

It's not clear to me what you mean by this. Yes, you can use factors in gam:

gam(ST ~ MOWST1, family = binomial, data = strikes.S)

would work. But you tried smoothing a factor, which isn't supported (and 
to me it doesn't make any sense doing so).

Smoothing an ordered factor may make sense, but this is not supported 
(and you didn't try it, according to the error message above) by `mgcv'. 
  I was under the impression that the `gam' function in package `gam' 
should be able to do this, but I just tried it and was rewarded by the 
error message

"Error: 'codes' is defunct."

relating to the internals of `gam' using a defunct R function -- I've 
e-mailed Prof Hastie, maintainer of package `gam', about this.

Even if it worked, the `gam' package won't allow estimation of the 
degree of smoothness of the model terms as part of the fitting process. 
So if this is what you want in combination with ordered factors, you're 
probably out of luck. (You can always send Prof Wood, `mgcv' maintainer, 
a feature request.)


HTH,
Henric




More information about the R-help mailing list