Skip to content

GAMs under R?

3 messages · Brian Ripley, E. S. Venkatraman, Simon Wood

#
On Sun, 30 Apr 2000, Stephen R. Laniel wrote:

            
loess: yes, and it's not really hidden. It is in standard package modreg.
It does not do `generalized additive models' though, even under S.
(The R implementation is a little less general than that in S.)

gam(): no, it is not there.  Look at the original code to see one reason
why: it is highly convoluted and not at all well documented.  I think
additive models have been greatly over-sold in certain statistical circles,
but if you want to use them for least-squares fitting, try bruto (in
package mda on CRAN) instead as at least that makes a sensible attempt to
choose the smoothness of the variable transformations.

I wonder why you were surprised?  See section 5.6 of the FAQ:

  5.6 How can I contribute to R?
  ==============================

[...]

     One place where functionality is still missing is the modeling
  software as described in "Statistical Models in S" (see *Note What is
  S?::); Generalized Additive Models (*gam*) and some of the nonlinear
  modeling code are not there yet.

which shows we are still waiting for a volunteer (hint, hint).
#
I have the following problem.  I have survival data (time, status) along
with several covariates (X1, X2,..., Xn).  I want to fit a Cox model for
each of the covariate (univariately) and obtain the fitted probability of
survival at a fixed time point t0 and covariate value Xi0.  I tried to do
this in a for loop where the index is the variable name as follows

covnames <- names(...)
for (covi in covnames) {
  survout <- coxph(Surv(time,status) ~ covi, data = dataname)
  print(summary(survfit(survout,newdata),t0))
}

Unfortunately "covi" is being treated as the variable name instead of 
being evaluated and the coxph call gives an error.  None of as.character,
eval, substitute (at least the way I called them) worked.  How does one
pass on variable names to model formula?

Thanks,
Venkat
-----------------------------------------------------------------------
E. S. Venkatraman, Ph.D.     Phone: (212) 639-8520  Fax: (212) 717-3137
Assistant Attending Member     Memorial Sloan-Kettering Cancer Center
-----------------------------------------------------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
1 day later
#
Linked from my web page (and on the RSS site) there's an R package
(mgcv) for fitting and smoothing parameter estimation (by GCV) for models
with multiple penalties. I wrote it to deal with various non-linear
problems, but it lets you set up GAMs using penalized regression splines -
and the package includes code for doing this. If this is any use to you,
you'd need to add in the `generalized' bit of GAMs yourself, but that's
pretty trivial, given the code that's there (it's on my `to do' list). 
The smoothing parameter selection method is a generalization of Gu and
Wahba's multiple gcv method for spline models to problems with less
structure. 

Simon
  ______________________________________________________________________
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._