Regarding the 'gam' package, though the example in help("step.gam")
, shown below, works just fine, removing the smoother term 's(x,12)' from consideration in the model yields NULL. Why?
The s(x,12) term does not end up being included in model step.object
... so why would removing it from consideration be a problem?
Works fine:
data(gam.data)
gam.object <- gam(y~x+z, data=gam.data)
step.object <-step.gam(gam.object, scope=list("x"=~1+x+s(x,4)+s(x,6)+s(x,12),"z"=~1+z+s(z,4)))
Not fine:
step.object <-step.gam(gam.object, scope=list("x"=~1+x+s(x,4)+s(x,6),"z"=~1+z+s(z,4)))
If you run the code with trace=2
,
data(gam.data)
gam.object <- gam(y~x + z, data=gam.data)
step.object <- step.Gam(gam.object, scope=list("x"=~1+x+s(x,4)+s(x,6),"z"=~1+z+s(z,4)),
trace = 2)
It will print more information about the algorithm results:
Start: y ~ x + z; AIC= 127.7316
Trial: y ~ 1 + z ; AIC= 234.8821
Trial: y ~ s(x, 4) + z ; AIC= 44.0543
Trial: y ~ x + 1 ; AIC= 126.5148
Trial: y ~ x + s(z, 4) ; AIC= 131.028
Step:1 y ~ s(x, 4) + z ; AIC= 44.0543
Trial: y ~ s(x, 6) + z ; AIC= 43.7495
Trial: y ~ s(x, 4) + 1 ; AIC= 43.1799
Trial: y ~ s(x, 4) + s(z, 4) ; AIC= 47.1024
Step:2 y ~ s(x, 4) ; AIC= 43.1799
Trial: y ~ s(x, 6) + 1 ; AIC= 42.6681
Step:3 y ~ s(x, 6) ; AIC= 42.6681
The problem is at the last step, i.e. Step 3. Since by default the search direction is both backward and forward, it will search for all the possibilities with one order difference in terms of complexity. There are two trials that could be done, namely s(x,4) + 1
and s(x,6) + z
. However, both of those were already computed in Step 1, hence no trials are further computed.
Normally, the search algorithm should terminate when AIC in all of the trials during a step increase. In this case, there is a decrease in AIC during step 2, which leads to step 3, yet no trial was done in step 3. Hence the algorithm does not terminate AND there is no further computation, leads to the result of NULL
.