[R] GLM model vs. GAM model

Thomas Lumley tlumley at u.washington.edu
Tue Oct 26 16:40:32 CEST 2004


On Tue, 26 Oct 2004, SUBIRANA CACHINERO, ISAAC wrote:

> I have a question about how to compare a GLM with a GAM model using anova
> function.

You don't say what gam() function you are using. There are at least two 
out there and they work in quite different ways.

> A GLM is performed for example:
>
> model1 <-glm(formula = exitus ~ age+gender+diabetes, family = "binomial",
> na.action = na.exclude)
>
> A second nested model could be:
>
> model2 <-glm(formula = exitus ~ age+gender, family = "binomial", na.action =
> na.exclude)
<snip>
>
> Similarly for GAM models
>
> model3 <-gam(formula = exitus ~ s(age)+gender, family = "binomial",
> na.action = na.exclude)
>
> "R" allows to compare these two models (GLM vs. GAM)
>
> anova(model2,model3, test="F")
>
> This instruction returns a p-value with no error or warning, but this test
> is based on maximum likelihood, and GAM models are not fitted with maximum
> likelihood criteria, thus I think this p-value is not correct.

Probably not.  If the number of degrees of freedom for age is small it may 
be quite a good approximation. If you are using mgcv::gam you will have 
seen a warning to this effect on the help page for anova.gam.

If you need a more accurate test you could simulate from model2 and 
compare the simulated distribution of the p-value to the value in the 
observed data.

 	-thomas




More information about the R-help mailing list