model_contrast_table: Summarize Model Variables, Families, and Contrast Matrices

View source: R/model_contrast_table.R

model_contrast_tableR Documentation

Summarize Model Variables, Families, and Contrast Matrices

Description

model_contrast_table() extracts model-level and variable-level information from a fitted model object.

It reports the model class, family and link function when available, number of variables, dependent variable, predictors, interactions, random-effect grouping variables, variable types, number of factor levels, and contrast matrix types for categorical variables.

The function is designed to work with fitted models supported by the package's internal model-extraction infrastructure, including models fitted with stats::lm(), stats::glm(), lme4::lmer(), lme4::glmer(), nlme::lme(), and glmmTMB::glmmTMB().

Usage

model_contrast_table(model, type = c("all", "summary", "x&y", "x", "y"))

Arguments

model

A fitted model object.

type

Character string indicating which output should be returned. Available options are "all", "summary", "x&y", "x", and "y".

Details

Variables found in the model frame are reported in the variable-level summary. In mixed-effects models, grouping variables used in the random structure may therefore also appear among the predictors.

To avoid interpreting these variables as fixed effects only, the model-level summary includes a separate "Random Effects" row listing the grouping variables used in the random-effects structure.

The variable-level summary also contains a Random_Effect column that indicates whether each variable is used as a random-effect grouping variable.

The function identifies the following contrast matrix types:

  • "Sum": sum-to-zero contrasts generated by stats::contr.sum().

  • "Treatment": treatment contrasts generated by stats::contr.treatment().

  • "Polynomial": polynomial contrasts generated by stats::contr.poly(), with equally spaced or user-supplied scores.

  • "Helmert": Helmert contrasts generated by stats::contr.helmert().

  • "Sliding Differences": sliding-difference contrasts generated by MASS::contr.sdif().

  • "Reverse Helmert": reverse Helmert contrasts generated by reverse_helmert().

  • "Custom": any other user-defined contrast matrix.

Matrices that do not coincide with one of these generators are classified from the structure of their hypothesis matrix, the inverse of the coding matrix with an intercept column. Treatment contrasts are therefore recognized with any reference level, sum contrasts with any omitted level, and all types after rescaling of their columns. The same classification is used by contrasts_onepred() and moplot_onepred().

Value

Depending on type, either a list of two data frames or a single data frame.

Examples

set.seed(1234)
dat <- data.frame(
  group = factor(rep(c("A", "B", "C"), each = 20)),
  y = rnorm(60)
)
contrasts(dat$group) <- stats::contr.helmert(3)
mod <- stats::lm(y ~ group, data = dat)
model_contrast_table(mod)


MoPlot documentation built on Nov. 25, 2026, 5:10 p.m.