s-news
[Top] [All Lists]

[S] Cross-validation of GAM-models with smoothed responses

To: s-news@wubios.wustl.edu
Subject: [S] Cross-validation of GAM-models with smoothed responses
From: rej@DMU.dk
Date: Sat, 18 Dec 1999 17:19:57 +0100
Sender: owner-s-news@wubios.wustl.edu
Dear S-plussers

I am currently investigating response curves of plants, and need to approach a
cross-validated smoothing optimum for a large number of cases, avoiding
overfitting and unrealistic response shapes.

I am trying to get Ripley and Venables CV-functions (Venables & Ripley 1997 pp.
493-496) to work for a GAM-model with smoothed responses (Actually modelling the
response of a plant species along one or two environmental gradients). My idea
was to compare the predicted abundance with the observed abundance (is there a
sound way of doing that?).

I ran into problems however, trying to make the functions work on my pc with
S-Plus 4.5:

 set.seed(123); rand <- sample (5, 573, replace=T)
> 
> CVprobs <- function(fitfn, predfn, ...)
+ {
+       res <- fullph$succ.pra
+       for (i in sort(unique(rand))) {
+               cat("fold",i,"\n",sep="")
+               learn <- fitfn(rand != i, ...)
+               res[rand==i] <- predfn(learn, rand== i)
+       }
+       res
+ }
> 
> probs.gam1 <- CVprobs(
+       function(x, ...) {
+       assign("x", x, f=1)
+       gam(succ.pra ~ s(ph), data=fullph, subset=x, ...)
+       },
+       function(obj, x) predict(obj, fullph[x,],type="response"))
fold1
Error in safe.predict.gam: No data to interpret as a character string: # NULL
Dumped

I'd appreciate any comments, on the general problem as well as the specific
function.

Regards

Rasmus
Rasmus Ejrnæs
Ph.D. in Plant Ecology
Department of Landscape Ecology
National Environmental Research Institute
> Grenaavej 12, Dk-8410 Ronde, Denmark
tel: +45 8920 1705
fax: +45 8920 1515
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>
  • [S] Cross-validation of GAM-models with smoothed responses, rej <=