cp_LRT | R Documentation |
Computes the likelihood ratio expressed as a difference between the log-likelihoods of observed data under two nested competing models.
cp_LRT(ll_restricted, ll_full)
ll_restricted |
numeric vector of length 1 (or an object of class 'logLik') storing the log-likelihood of the observed data under the restricted model |
ll_full |
numeric vector of length 1 (or an object of class 'logLik') storing the log-likelihood of the observed data under the full model |
Note that:
The full model is always the model with more estimated parameters, the model with more predictor variables.
The restricted model is the model with fewer estimated parameters.
The restricted model must be nested within the full model.
numeric vector of length 1 storing the likelihood ratio test statistic
Edoardo Costantini, 2023
# Fit a nested model
nested <- glm(mpg ~ cyl + disp, data = mtcars)
# Fit a complex model
complex <- glm(mpg ~ cyl + disp + hp + am, data = mtcars)
# Compute log-likelihood statistic with your function
LRT_M <- cp_LRT(
ll_restricted = logLik(nested),
ll_full = logLik(complex)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.