tidy.predictmeans: Predicted Means and Pairwise Comparisons as Data Frames

View source: R/tidy.R

tidy.predictmeansR Documentation

Predicted Means and Pairwise Comparisons as Data Frames

Description

Return the means or pairs table of a predictmeans result (glance(): one row describing it). The tables have fixed column names (see the Value section of predictmeans) and unrounded values, which makes them easy to use in further analysis, reports, Shiny apps or AI tools. tidy() is the generic from package generics (also used by broom); as.data.frame() needs no other package. coef() and vcov() return the means (on the model scale, as in the estimate column) and their covariance matrix (Kenward-Roger adjusted when the means are), named by the mean labels. With them, multcomp::glht() or marginaleffects::hypotheses() can test any contrast of the means, e.g. hypotheses(pm, hypothesis = "n2 - n0 = 0") (normal-based). Recent versions of marginaleffects need the class listed first: options(marginaleffects_model_classes = "predictmeans").

Usage

## S3 method for class 'predictmeans'
tidy(x, what = c("means", "pairs"), ...)

## S3 method for class 'predictmeans'
glance(x, ...)

## S3 method for class 'predictmeans'
as.data.frame(x, row.names = NULL, optional = FALSE,
              what = c("means", "pairs"), ...)

## S3 method for class 'predictmeans'
coef(object, ...)

## S3 method for class 'predictmeans'
vcov(object, ...)

Arguments

x

A result of predictmeans.

object

A result of predictmeans.

what

Which table: "means" (the default) or "pairs".

row.names

Optional row names for the result.

optional

Not used.

...

Not used.

Value

A data frame; for coef() a named vector and for vcov() a matrix. glance() gives one row: modelterm, n.means, n.pairs, nobs (observations in the cells), df.method, adjust, level, vcov, vcov.adjust, sed.min, sed.mean, sed.max (standard errors of the differences), lsd.mean, nperm and model.class.

Author(s)

Dongwen Luo, Siva Ganesh and John Koolaard

See Also

predictmeans, autoplot.predictmeans, advice

Examples

  library(predictmeans)
  Oats <- as.data.frame(nlme::Oats)
  Oats$nitro <- factor(Oats$nitro)
  fm <- lmer(yield ~ nitro*Variety + (1|Block/Variety), data = Oats)
  pm <- predictmeans(fm, "nitro:Variety", atvar = "Variety", adj = "tukey")
  as.data.frame(pm)
  head(as.data.frame(pm, what = "pairs"))
  if (requireNamespace("generics", quietly = TRUE)) generics::glance(pm)

  # Any contrast of the means from coef() and vcov(): Victory - Golden Rain at nitro 0.6
  b <- coef(pm)
  L <- (names(b) == "0.6:Victory") - (names(b) == "0.6:Golden Rain")
  c(estimate = sum(L*b), SE = sqrt(drop(L %*% vcov(pm) %*% L)))

predictmeans documentation built on Nov. 24, 2026, 5:10 p.m.