Learn R Programming

pbkrtest (version 0.5.5)

get_nested_model_info: Resolve Nested Model Representation

Description

Constructs or extracts a nested model (fit0) from a full model (fit1) using flexible input: a model object, formula, character string, or matrix.

This function is useful for preparing models for comparison, e.g., via likelihood ratio test.

Usage

get_nested_model_info(fit1, fit0)

Value

A list with:

formula_large

Formula for fit1.

formula_small

Formula for resolved fit0.

large_model

The full model fit1.

small_model

The nested model fit0.

L

Restriction matrix defining the nested model.

Arguments

fit1

A fitted model object (e.g., from lm, lmer, etc.).

fit0

A nested model specification: a model object, a formula (e.g., ~ . - x), a character vector of term names to remove, or a restriction matrix.

Examples

Run this code
if (requireNamespace("lme4", quietly = TRUE)) {
  library(lme4)
  data(sleepstudy)
  fit1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
  fit0 <- lmer(Reaction ~ (Days | Subject), sleepstudy)

  get_nested_model_info(fit1, fit0)               # as model object
  get_nested_model_info(fit1, ~ . - Days)         # as formula
  get_nested_model_info(fit1, "Days")             # as string
  ## get_nested_model_info(fit1, c(0, 1))         # numeric (converted to matrix)
}

Run the code above in your browser using DataLab