# anova.gam, significant test and 0 deviance

I have fitted a series of GAMs of increasing complexity, and compared with anova.gam. I get a significant p value (based on Chisq test) for a pair of models, even though the difference in deviance between the two models is 0.

The models are specified using default settings for gam, in mgcv (i.e. select = FALSE).

The smooth term in model 2 is non-significant and has edf = approx. 0, p = 1. Therefore I am not surprised the deviance does not change with its inclusion. However, I would expect the p value for the Chisq test to be ~1.

Am I misinterpreting this test?

Output below. Note the p-value for contrast between models 1 and 2 is very small even though deviance is 0.

anova.gam(model1, model2, models3, test="Chisq")

Analysis of Deviance Table

Model 1: outcome ~ s(sujetno, bs = "re")
Model 2: outcome ~ s(z.Cluster_1_PC1) + s(sujetno, bs = "re")
Model 3: outcome ~ s(z.Cluster_1_PC1) + s(sujetno, bs = "re") + z.age

Resid. Df Resid. Dev          Df Deviance  Pr(>Chi)
1      1890     1889.0
2      1890     1889.0 -4.8263e-08    0.000 4.707e-07 ***
3      1886     1878.2  4.0115e+00   10.765   0.02899 *


Thanks,

Al

In the wikipedia-definition of the $$\chi^2$$-distribution (https://en.wikipedia.org/wiki/Chi-squared_distribution), $$k$$ (the "degrees of freedom") is an integer. However, the distribution itself can be evaluated for non-integer values, too.
In your case, your change in deviance is tiny (the value is not actually shown, except that it is less than 0.001), but the difference in degrees of freedom is even tinier. Hence, when computing the resulting $$\chi^2$$-value, it becomes highly significant. To illustrate:
dchisq(0.001, df=1E-8)