
Predicted (least-squares) means, standard errors, LSDs, pairwise
comparisons and contrasts for linear, generalized linear and mixed
models — aov, lm, glm,
gls, lme, lmer,
glmer, glmmTMB, gam and
semiparametric semireg models — with Kenward–Roger,
Satterthwaite or containment degrees of freedom, permutation and
bootstrap tests, R² for mixed models and diagnostics.
lmer; permutation p-values (b + 1)/(B
+ 1); aov with Error() analysed by strata (SEs
from stratum mean squares, as Genstat); means over empty cells average
the observed cells with equal weight, with a warning.nlme::lme
and emmeans.advice(x) reads it,
options(predictmeans.advice = FALSE) turns it off.ncore.
install.packages("predictmeans") # CRAN
# remotes::install_github("dongwenluo/predictmeans") # development versionlibrary(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")
pm$means # one row per mean: estimate, std.error, df, conf.low, conf.high, group, n, ...
pm$pairs # one row per comparison: estimate, std.error, df, statistic, p.value, p.adj, ...
ggplot2::autoplot(pm)Every predictmeans() result has three stable data
frames, means, pairs and
settings, with fixed column names;
as.data.frame(), tidy(), coef()
and vcov() work on it.
| Task | Function |
|---|---|
| Means and pairwise comparisons | predictmeans(), covariatemeans() |
| Contrasts | specify_contrast(), contrast_family(),
contrastmeans() |
| Joint tests (slices) and slopes | pm_joint(), pm_slopes() |
| Resampling tests | permmodels(), permlmer(),
bootmodels() |
| Semiparametric models | semireg(), semireg_tmb(),
semipred() |
| R², variance components, diagnostics | R2_model(), varcomp(),
pm_check(), residplot(),
CookD() |
| Reference grid / K matrix | Kmatrix() |
The package website has the help pages and vignettes: getting started; contrasts, joint tests and slopes; link and response scale; permutation and bootstrap tests; smooth curves in mixed models; missing cells and non-estimable means; R² for mixed models; and migrating from version 1.x.
For AI assistants and scripted use, a compact description of the
result tables, the defaults and common recipes is installed with the
package:
system.file("llms-context.md", package = "predictmeans")
(on
GitHub).