This
x <- rnorm(100)
y <- rnorm(100)
gam(y ~ s(x))
## Family: gaussian
## Link function: identity
## Formula:
## y ~ s(x)
## Estimated degrees of freedom:
## 1 total = 2
## GCV score: 0.8116283
breaks down, when VGAM package is loaded:
library(VGAM)
gam(y ~ s(x))
##Error: $ operator is invalid for atomic vectors
Both implement s() function, but this shouldn't happen right? Is this an error in mgcv or VGAM package?
mgcv:gamcallsmgcv:interpret.gamwhich is where the fail is.interpret.gamseems to parse the formula for special functions, including 's', and then evaluatess(x)in the environment of the formula. Which means it will find whatever the current 's' is from the caller. Which could be something that returns something thatgamdoesn't like.You can't fix it like this:
But you can like this:
So its not an error in either package. You asked for a gam with
s(x), and happened to have currently defineds(x)to be incompatible with thatgamneeds. You can't just plug any old function in there.