6

I'm trying to use the gamsel R package to fit a sparse generalized additive model, and I can't seem to get it to work on real data. When I run on synthetic data as described in the package documentation, everything works well:

library(gamsel)
data=gendata(n=500,p=12,k.lin=3,k.nonlin=3,deg=8,sigma=0.5)
attach(data)
bases=pseudo.bases(X,degree=10,df=6)
gamsel.out=gamsel(X,y,bases=bases)

But when I run on real data, I get the following error:

library(gamsel)
X = as.matrix(read.csv("X.csv"),header=FALSE)
y = as.matrix(read.csv("y.csv"),header=FALSE)
gam_fit = gamsel(X,y)

Error in if (abs((df - current.df)/df) < 1e-04 | iterations == 1) return(list(lambda = lambda, : missing value where TRUE/FALSE needed

You can access sample data files that will reproduce this result here. Any thoughts about how to fix this error?

Olivier De Meulder
  • 2,493
  • 3
  • 25
  • 30
FChopin
  • 61
  • 3
  • I get the same problem with my real data too. It seems to be part of `df.inv` which is called by `pseudo.bases`. https://github.com/cran/gamsel/blob/master/R/df.inv.R. If I work it out I'll post an answer, even though this is a little elderly as a question. – Peter Ellis Sep 10 '16 at 03:57
  • Could it be a division by zero? I notice some zeros in your `X`, and the error occurs in a line that divides by `df`. An `NA` in an `if` statement could cause this error message: https://stackoverflow.com/questions/7355187/error-in-if-while-condition-missing-value-where-true-false-needed – Charlie Brummitt Jul 12 '17 at 14:54
  • Anybody knows how the lambda is used inside the `gam` function of the `mgcv` library? – igorkf Apr 12 '20 at 19:46

0 Answers0