Computes the likelihood ratio test (LRT) statistic and p-value for comparing nested models.
lrt(null_loglik, alt_loglik, dof)A hypothesis_test object of subclass likelihood_ratio_test
containing:
The LRT statistic \(\Lambda = -2(\ell_0 - \ell_1)\)
P-value from chi-squared distribution with dof degrees
of freedom
The degrees of freedom
The input null model log-likelihood
The input alternative model log-likelihood
The likelihood ratio test is a fundamental method for comparing nested statistical models. Given a null model \(M_0\) (simpler, fewer parameters) nested within an alternative model \(M_1\) (more complex), the LRT tests whether the additional complexity of \(M_1\) is justified by the data.
The test statistic is:
$$\Lambda = -2 \left( \ell_0 - \ell_1 \right) = -2 \log \frac{L_0}{L_1}$$
where \(\ell_0\) and \(\ell_1\) are the maximized log-likelihoods under the null and alternative models, respectively.
Under \(H_0\) and regularity conditions, \(\Lambda\) is asymptotically chi-squared distributed with degrees of freedom equal to the difference in the number of free parameters between models.
The null model must be nested within the alternative model (i.e., obtainable by constraining parameters of the alternative).
Both likelihoods must be computed from the same dataset.
Standard regularity conditions for asymptotic chi-squared distribution must hold (true parameter not on boundary, etc.).
The LRT is one of the "holy trinity" of likelihood-based tests, alongside
the Wald test (wald_test()) and the score (Lagrange multiplier) test.
All three are asymptotically equivalent under \(H_0\), but the LRT is
often preferred because it is invariant to reparameterization.
wald_test() for testing individual parameters
# Comparing nested regression models
# Null model: y ~ x1 (log-likelihood = -150)
# Alt model: y ~ x1 + x2 + x3 (log-likelihood = -140)
# Difference: 3 additional parameters
test <- lrt(null_loglik = -150, alt_loglik = -140, dof = 3)
test
#> Hypothesis test ( likelihood_ratio_test )
#> -----------------------------
#> Test statistic: 20
#> P-value: 0.0001697424
#> Degrees of freedom: 3
#> Significant at 5% level: TRUE
# Is the more complex model significantly better?
is_significant_at(test, 0.05)
#> [1] TRUE
# Extract the test statistic (should be 20)
test_stat(test)
#> [1] 20
# Access stored inputs for inspection
test$null_loglik
#> [1] -150
test$alt_loglik
#> [1] -140