This function performs chi-squared test for nested models.
lrtest_msel(model1, model2)
Arguments
model1: the first model.
model2: the second model.
Returns
The function returns an object of class 'lrtest_msel' that is a list with the following elements:
n1 - the number of observations in the first model.
n2 - the number of observations in the second model.
ll1 - log-likelihood value of the first model.
ll2 - log-likelihood value of the second model.
df1 - the number of parameters in the first model.
df2 - the number of parameters in the second model.
restrictions - the number of restrictions in the nested model.
value - chi-squared (likelihood ratio) test statistic value.
p_value - p-value of the chi-squared (likelihood ratio) test.
Details
Arguments model1 and model2 should be objects of class that has implementations of logLik and nobs methods. It is assumed that either model1
is nested into model2 or vice versa. More precisely it is assumed that the model with smaller log-likelihood value is nested into the model with greater log-likelihood value.
Arguments model1 and model2 may be the lists of models. If model1 is a list of models then it is assumed that the number of degrees of freedom and log-likelihood of the first model are just a sum of degrees of freedom and log-likelihoods of the models in this list. Similarly for model2.
If model1 or model2 is a list then the number of observations of the associated models are calculated as the sum of the numbers of observations of the models in corresponding lists. However sometimes it may be misleading. For example, when bivariate probit model (full) is tested against two independent probit models (restricted). Then it will be assumed that the number of observations in the restricted model is twice the number of observations in the full model that is not the case. Fortunately it will not affect the results of the likelihood ratio test.
Examples
set.seed(123)# Generate data according to linear regressionn <-100eps <- rnorm(n)x1 <- runif(n)x2 <- runif(n)y <- x1 +0.2* x2 + eps
# Estimate full modelmodel1 <- lm(y ~ x1 + x2)# Estimate restricted (nested) modelmodel2 <- lm(y ~ x1) results
lrtest_msel(model1, model2)