Learn R Programming

pbkrtest (version 0.5.5)

getLRT: Likelihood Ratio Test Between Nested Models

Description

Performs a likelihood ratio test (LRT) between two nested models. Supports models of class lm, lmerMod, glmerMod, lme, and gls.

Usage

getLRT(fit1, fit0)

Value

A named numeric vector with:

tobs

Test statistic (twice the difference in log-likelihoods).

df

Degrees of freedom (difference in number of parameters).

p.value

P-value from the chi-squared distribution.

Arguments

fit1

A model object representing the more complex (full) model.

fit0

A model object representing the simpler (nested) model.

Examples

Run this code
## lm
fit1 <- lm(mpg ~ wt + hp, data = mtcars)
fit0 <- lm(mpg ~ wt, data = mtcars)
getLRT(fit1, fit0)

## lmerMod
if (requireNamespace("lme4", quietly = TRUE)) {
  library(lme4)
  fit1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy, REML = FALSE)
  fit0 <- lmer(Reaction ~ 1 + (Days | Subject), sleepstudy, REML = FALSE)
  getLRT(fit1, fit0)
}

## glmerMod
if (requireNamespace("lme4", quietly = TRUE)) {
  library(lme4)
  data(cbpp)
  fit1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
                data = cbpp, family = binomial)
  fit0 <- glmer(cbind(incidence, size - incidence) ~ 1 + (1 | herd),
                data = cbpp, family = binomial)
  getLRT(fit1, fit0)
}

## lme
if (requireNamespace("nlme", quietly = TRUE)) {
  library(nlme)
  fit1 <- lme(distance ~ age + Sex, random = ~1 | Subject,
              data = Orthodont, method = "ML")
  fit0 <- lme(distance ~ age, random = ~1 | Subject,
              data = Orthodont, method = "ML")
  getLRT(fit1, fit0)
}

## gls
if (requireNamespace("nlme", quietly = TRUE)) {
  library(nlme)
  fit1 <- gls(mpg ~ wt + hp, data = mtcars, method = "ML")
  fit0 <- gls(mpg ~ wt, data = mtcars, method = "ML")
  getLRT(fit1, fit0)
}

Run the code above in your browser using DataLab