Search code examples
rgammgcv

invalid model formula in ExtractVars with gam s() wrapper


What I am trying to do is simple. I am trying to fit a gam model where I can decide the df of the smoothing spline (the s function in the formula part). Calling the gam model should return the fit, but yet it gives an error. What am I doing wrong here?

    library(mgcv)
    library(gam)
    set.seed(2) ## simulate some data... 
    dat <- gamSim(1,n=400,dist="normal",scale=2)
    b <- gam(y~s(x0,df = 5)+s(x1)+s(x2)+s(x3),data=dat)

Solution

  • Apparently was related to the mcgv package and to the version of 'gam'. Using gam '1.14' and not using mcgv worked. Example:

        library(ISLR)
        attach(Wage)
        library(gam)
        fit = gam(wage ~ s(year, 4) + s(age, 5) +   education, data = Wage)
        plot(fit)
        summary(fit)