Search code examples
rr-caretgammgcv

validating poisson GAM models with caret


I'm trying to run a cross-validation for a generalized additive model (GAM) using the 'caret' package in R. I can get this to work for a GLM, and think it should be simple to run the same thing for a GAM, but cannot get it to work, see below:

dat <- data.frame(label=round(rpois(100,20)),v1=rnorm(100),v2=rnorm(100))
tc <- trainControl("cv",10,savePred=T)
(fit <- train(label~.,data=dat,method="glm",trControl=tc,family=poisson(link = "log")))

(fit1 <- train(label~.,data=dat,method="gam",trControl=tc,family=poisson(link = "log")))

The crucial warning that is thrown when running the last line is this:

20: In eval(expr, envir, enclos) :
  model fit failed for Fold10: select=FALSE, method=GCV.Cp Error in mgcv:::gam(modForm, data = dat, family = dist, select = param$select,  : 
  formal argument "family" matched by multiple actual arguments

It appears that somehow the family argument is not being passed to gam() in the same way that it is in glm(). I haven't found any working examples of this after searching the web exhaustively. Any help would be appreciated!

Nick


Solution

  • Upon further review, it appears that Poisson outcomes are explicitly not supported using any of the GAM-based model types in caret. I flagged this as an issue (in documentation at least, if not in explicit support of these types of models) in the caret codebase on Github.