View source: R/model-comparison.R
| compare_models | R Documentation |
Compare multiple demand models using information criteria and likelihood ratio tests (when applicable). Works with all beezdemand model classes.
compare_models(..., test = c("auto", "lrt", "none"))
... |
Two or more model objects of class |
test |
Character; type of statistical test. One of:
|
Models are compared using AIC and BIC. For models from the same statistical backend (e.g., two hurdle models or two NLME models), likelihood ratio tests can be performed if the models are nested.
When comparing models from different backends (e.g., hurdle vs NLME), only information criteria comparisons are possible since the likelihoods are not directly comparable for LRT purposes.
| Backend 1 | Backend 2 | LRT Possible? |
| hurdle | hurdle | Yes (if nested) |
| nlme | nlme | Yes (if nested) |
| fixed | fixed | No (no likelihood) |
| hurdle | nlme | No |
| hurdle | fixed | No |
| nlme | fixed | No |
An object of class beezdemand_model_comparison containing:
Data frame with model fit statistics
Type of test performed
LRT results if performed (NULL otherwise)
Index of best model by BIC
Character vector of notes/warnings
Logical; always FALSE since nesting is not automatically verified. Users must ensure models are properly nested for valid LRT interpretation.
The likelihood ratio test (LRT) assumes that:
The models are nested (the reduced model is a special case of the full model obtained by constraining parameters).
Both models are fit to identical data.
Under the null hypothesis, the LR statistic follows a chi-square distribution with degrees of freedom equal to the difference in the number of parameters.
Important caveat for mixed-effects models: When variance components are tested at the boundary (e.g., testing whether a random effect variance is zero), the standard chi-square distribution is not appropriate. The correct null distribution is a mixture of chi-squares (Stram & Lee, 1994). The p-values reported here use the standard chi-square approximation, which is conservative (p-values are too large) for boundary tests.
This function does not automatically verify that models are nested. Users should ensure models are properly nested before interpreting LRT p-values.
Stram, D. O., & Lee, J. W. (1994). Variance components testing in the longitudinal mixed effects model. Biometrics, 50(4), 1171-1177.
compare_hurdle_models() for the legacy hurdle-specific comparison
data(apt)
fit2 <- fit_demand_hurdle(apt, y_var = "y", x_var = "x", id_var = "id",
random_effects = c("zeros", "q0"))
fit3 <- fit_demand_hurdle(apt, y_var = "y", x_var = "x", id_var = "id",
random_effects = c("zeros", "q0", "alpha"))
compare_models(fit2, fit3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.