Search code examples
rr-caretgamparallel-foreach

R Crashes when training using caret and method = gamLoess


When I run the code below, R crashes. If I comment out the tuneGrid line in the call to train, there is no crash. I've tried this with another dataset, and still crash R. Crash message is R Session Aborted R encountered a fatal error The session was terminated Start new session.

The code is:

library(splines)
library(foreach)
library(gam)
library(lattice)
library(ggplot2)
library(caret)

# crashes when I uncomment the tuneGrid = tuneGrid line

Set_seed_seed <- 100
data_set <- diamonds[, c(1, 5, 6, 7, 8, 9, 10)]
data_set <- data_set[1:1000,]
formula <- price ~ carat + depth + table + x + y + z
training_control <- trainControl(method = "cv", allowParallel = FALSE)
tune_grid <- expand.grid(span = seq(0.1, 0.9, length = 9), degree = seq(1, 2, length = 2))
set.seed(Set_seed_seed)
GAM_model <- train(formula,
                  data = data_set,
                  method = "gamLoess", 
                  tuneGrid = tune_grid,
                  trControl = training_control
               )

This occurred in R3.2.1 and 3.2.2 using R Studio.

In R gui, also get crashes.


Solution

  • It is a bug in the gam package. I alerted Trevor Hastie on March 3, 2014 about it:

     library(gam)
     set.seed(1)
     x <- rnorm(1000)
     y <- x^2+0.1*rnorm(1000)
     tdat <- data.frame(y = y, x = x)
    
     m1 <- gam(y ~ lo(x, span = .5, degree = 2), data = tdat)
    

    That works fine but as I fit multiple models a seg fault occurs (but only with loess and degree = 2).

    This will produce it for me:

     for(i in 1:10) m1 <- gam(y ~ lo(x, span = .5, degree = 2), data = tdat)