# Species Distribution Modeling with GAM: s() function giving weird summary results

I'm using a GAM for a presence/absence species distribution model (SDM) from the mgcv package, where my n total = 125. At the moment, I'm getting some weird results, and I'm hoping to get some advice from someone who is more familiar with GAM than a neophyte like myself. My GAM equation is the following:

GAM1<-gam(final, data=sdmdata_final, family="binomial")


with final being the equation:

final<-pb~elev+p_jul+ndvi_1+ndvi_2+ndvi_3+t_sep+t_apr+t_feb+t_may+t_jun+t_total


The variables above are the environmental variables for the SDM, and pb is binomial data. Now, I understand that with a GAM, a smoothing function is typically used. In my case, I was initially using s() around each of my environmental variables, so the equation looked something like:

final.s<-pb~s(elev)+s(p_jul)+...+s(t_total)


However, when I entered final.s into the above GAM equation and performed a summary(GAM1), I got an adjusted R-sq. = 1, with 100% of my deviance explained. This, of course, makes no sense. If I remove the s(), I get more realistic results, but is removing the smoothing function from a GAM appropriate for proper analyses? Is there something I need to change in either my final.s or GAM1 code that helps the smoothing function, s(), work? Thanks in advance.

## migrated from stackoverflow.comFeb 28 '17 at 21:00

This question came from our site for professional and enthusiast programmers.

• 1) If you remove smooths from a GAM, you essentially get a GLM. So doing that won't really solve your problem, as your result is indeed strange. 2) What kind of variables are those? Are any of them factors (categorical), or are they all continuous? – Tilen Feb 28 '17 at 23:38
• First of all, I think 11 splines is quite a lot! That way you are over specifying your model, as a result you would have a perfect fit. Second, I think you should specify how many points you want to use for each spline, for example: final.s <- pb~s(elev, 10)+s(p_jul,10) – Robbie Mar 1 '17 at 6:58
• @Robbie If you don't set fx = TRUE, the second parameter (k) of s indicates the starting value of the basis dimension. mgcv shrinks this dimension through penalized regression. Your value of 10 is probably larger than what is automatically chosen. – Roland Mar 1 '17 at 7:19
• @OP Have you tried setting select = TRUE in gam? That way some smoothers could be shrunk to zero. Anyway, 11 smoothers is too many if you can support them only with 125 data points. I'd want at least a few thousand data points for such a complex model. – Roland Mar 1 '17 at 7:23
• Sorry for the belated reply. @Tilen those variables are all continuous – Tula Mar 1 '17 at 15:33