简体   繁体   中英

Error in mgcv R package, depending of the R version

The following program works perfectly with R\\2.15.3 with the mgcv packages:

foo<-c(0.08901294, 0.04221170, 0.01608613, 0.04389676, 0.04102295, 0.03552413, 0.06571099, 0.11004966, 0.08380553, 0.09181121, 0.07422538,
        0.11494897, 0.18523257, 0.13809043, 0.13569868, 0.13433534, 0.16056145, 0.15559133, 0.22381149, 0.13998797, 0.02831030)
infant.gamfit<-gam(foo~s(c(1:21)), family=gaussian(link = "logit"))

But with R\\3.1.1 and 3.1.2, it produces the following error:

Error in reformulate(pav) : 'termlabels' must be a character vector of length at least one

Which is an error I don't understand. Of course the values in foo is an example among others, but I have the same problem with other values. Fixing k in the spline doesn't change anything.

That wouldn't be a problem if I wouldn't need to use it on a large scale with a supercomputer where all the versions of R create the same error... (for the sake of the discussion, the R versions I tested on the supercomputer were:

  • R/2.15.3-foss-2014a-default;
  • R/2.15.3-foss-2014a-st;
  • R/2.15.3-intel-2014a-default;
  • R/3.0.2-foss-2014a-default)

So that's not a supercomputer problem, but more a problem related to the use of mgcv in different version of R.

I didn't find any answer on the internet.
Thank you in advance for your help.
Guillaume

It looks like recent versions of mgcv::gam can be a bit fragile when your predictor is an expression, as opposed to a named variable. This works:

x <- 1:21
gam(foo~s(x), family=gaussian(link = "logit"))

As does this:

x <- 1:21
gam(foo~s(x + 0), ...)

But this doesn't:

x <- rep(0, 21)
gam(foo~s(x + 1:21), ...)

In general, I'd suggest you should precompute your predictors when using gam .

PS. Gaussian family with logit link isn't very sensible, but that's another issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM