Function for comparing two GAMM models.

1 2 |

`model1` |
First model. |

`model2` |
Second model. |

`signif.stars` |
Logical (default = TRUE). Whether or not to display stars indicating the level of significance on 95% confidence level. |

`print.output` |
Logical: whether or not to print the output.
By default controlled globally in the package options:
If the function |

As an Chi-Square test is performed on two times the difference in minimized smoothing parameter selection score (GCV, fREML, REML, ML), and the difference in degrees of freedom specified in the model. The degrees of freedom of the model terms are the sum of 1) the number of estimated smoothing parameters for the model, 2) number of parametric (non-smooth) model terms including the intercept, and 3) the sum of the penalty null space dimensions of each smooth object.

This method is preferred over other functions such as `AIC`

for
models that include an AR1 model or random effects (especially nonlinear
random smooths using `bs="fs"`

). CompareML also reports the AIC
difference, but that value should be treated with care.

Note that the Chi-Square test will result in a very low p-value when the difference in degrees of freedom approaches zero. Use common sense to determine if the difference between the two models is meaningful. A warning is presented when the difference in score is smaller than 5.

The order of the two models is not important. Model comparison is only implemented for the methods GCV, fREML, REML, and ML.

Optionally returns the Chi-Square test table.

If no output is provided in the command window, set info messages to TRUE:
`infoMessages("on")`

and try again.
For suppressing the output and all warnings, set infoMessages to FALSE
(`infoMessages("on")`

) and use the function
`suppressWarnings`

to suppress warning messages.

Jacolien van Rij. With many thanks to Simon N. Wood for his feedback.

For models without AR1 model or random effects `AIC`

can be used.

Other Testing for significance: `plot_diff2`

,
`plot_diff`

, `report_stats`

,
`wald_gam`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ```
data(simdat)
## Not run:
infoMessages("on")
# some arbitrary models:
m1 <- bam(Y~Group + s(Time, by=Group), method="fREML", data=simdat)
m2 <- bam(Y~Group + s(Time), method="fREML", data=simdat)
compareML(m1, m2)
# exclude significance stars:
compareML(m1, m2, signif.stars=FALSE)
m3 <- bam(Y~Group + s(Time, by=Group, k=25), method="fREML",
data=simdat)
compareML(m1, m3)
# do not print output, but save table for later use:
cml <- compareML(m1, m2, print.output=FALSE)$table
cml
# alternative way:
infoMessages('off')
cml <- compareML(m1, m2, print.output=FALSE)$table
infoMessages('on')
# Use suppressWarnings to also suppress warnings:
suppressWarnings(cml <- compareML(m1, m2, print.output=FALSE)$table)
## End(Not run)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.