| lrtest | R Documentation |
Compares two or more nested likelihood-based regression models. Objects
returned by R4VN logistic() and poisson() can be supplied directly.
lrtest(..., digits = 3, p_digits = 3, show = TRUE, console = FALSE)
... |
Two or more nested fitted models, ordered from the smaller model
to progressively larger models. R4VN statistical results containing a
fitted model in |
digits |
Number of decimal places for likelihood and LR statistics. |
p_digits |
Number of decimal places for p-values. |
show |
Logical; open the formatted result in the Viewer. Default |
console |
Logical; also print the result in the Console. Default |
When more than two models are supplied, comparisons are sequential:
M1 versus M2, then M2 versus M3, and so on.
The models must use the same outcome, analytic observations, weights, offsets/exposure definition, and likelihood family/link, and each larger model must contain the smaller model.
Supported fits include ordinary likelihood-based glm models such as
logistic and Poisson regression, MASS::glm.nb() negative-binomial models,
survival::coxph() Cox models, and survival::survreg() parametric survival
models.
Quasi-likelihood models are not supported. R4VN models fitted with
vce = "robust" or vce = "cluster" are also rejected because the
classical likelihood-ratio chi-square test is model-likelihood inference,
not robust covariance inference.
For ordinary linear regression use the nested-model F test rather than
lrtest().
An object of class r4vn_stat. The unformatted comparison table is
stored in result$raw$table; the backward-compatible result$raw$comparison table is also retained.
logistic(), poisson()
set.seed(2026)
d <- data.frame(
y = factor(rbinom(250, 1, .35), levels = 0:1,
labels = c("No", "Yes")),
age = rnorm(250, 45, 12),
sex = factor(sample(c("Female", "Male"), 250, TRUE)),
treatment = factor(sample(c("No", "Yes"), 250, TRUE))
)
m1 <- logistic(y, c.age, i.sex, i.treatment,
data = d, event = "Yes", show = FALSE)
m2 <- logistic(y, c.age, i.sex*i.treatment,
data = d, event = "Yes", show = FALSE)
lrtest(m1, m2, show = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.