Migrating from predictmeans 1.x

knitr::opts_chunk$set(collapse = TRUE, comment = "#>", message = FALSE, warning = FALSE)

predictmeans 2.0 removes options that did the same thing under two names, the printing and plot settings in the calls of the analysis functions, five functions, and the 1.x smooth interface (smZ(), smoothZ). The means functions share one vocabulary: conf_level, df_method, at, weights, vcov, plot.

To update a 1.1.1 script, run it. A removed argument or function stops with its 2.0 spelling, the value you gave filled in:

library(predictmeans)
Oats <- as.data.frame(nlme::Oats)
Oats$nitro <- factor(Oats$nitro)
fm <- lmer(yield ~ nitro * Variety + (1 | Block/Variety), data = Oats)
try(predictmeans(fm, "nitro", level = 0.1, Df = 30))

Nothing is silently ignored. A rewritten call gives the same numbers as 1.1.1, apart from the changes listed under Defaults that change and Results that change. The package sources check this for every rewrite (dev/snapshot-*.R, dev/check-smz-migration.R).

Code side by side

The models: fm above; fm0, the same model without the interaction; fmc, with nitro as a covariate; fs, a smooth model; fit stands for any model. Every 2.0 line below is run by dev/check-migrating.R in the package sources, and every 1.1.1 line checked to stop with the 2.0 spelling.

fm0 <- lmer(yield ~ nitro + Variety + (1 | Block/Variety), data = Oats)
fmc <- lmer(yield ~ nitro * Variety + (1 | Block/Variety), data = nlme::Oats)
fs <- semireg(rate ~ s(pressure, by = QB, bs = "os", k = 4) + (pressure | Subject),
              data = nlme::Dialyzer)

Means and comparisons

1.1.1 wzxhzdk:3
2.0 wzxhzdk:4

Covariates and curves

1.1.1 wzxhzdk:5
2.0 wzxhzdk:6

Permutation tests

1.1.1 wzxhzdk:7
2.0 wzxhzdk:8

permmodels() uses Freedman–Lane permutations, so its p-values are not those of permanova.lmer()'s refits (Results that change).

Diagnostics, R² and letters

1.1.1 wzxhzdk:9
2.0 wzxhzdk:10

Every argument and function

| Function | 1.1.1 | 2.0 | |---|---|---| | predictmeans(), contrastmeans(), covariatemeans(), pm_slopes(), semipred(), permstats(), PMplot() | level = 0.05 (a significance level) | conf_level = 0.95 | | varcomp() | level = 0.9 (a confidence level) | conf_level = 0.9 | | predictmeans(), contrastmeans(), covariatemeans() | Df = 10 | df_method = 10 | | df_term() | type = | df_method = | | covariatemeans(), semipred(), Kmatrix() | covariateV = | at = | | predictmeans(), covariatemeans() | trans = exp, transOff = 1 | trans = function(x) exp(x) - 1 | | predictmeans(), covariatemeans() | responsen = | removed: the response is read from the model | | predictmeans() | count = TRUE | removed: Poisson and negative binomial means are detected | | predictmeans() | mplot, barplot, pplot, bkplot, and plot of earlier 2.0 versions | autoplot(pm, type = "means"), "bar", "pvalue", "ci"; plot = FALSE is still accepted | | predictmeans() | lsd_bar, plotord, lineplot, plottitle, plotxlab, plotylab, jitterv, basesz, and plot_args | autoplot(pm, interval = , x = , group = , panel = , lines = , data = TRUE, jitter = ) + labs(title, x, y) + theme_bw(size) | | predictmeans(), Kmatrix() | prtnum, ndecimal, prtplt | removed: print(pm, digits = ); autoplot(pm) | | covariatemeans() | trellis, plotord, mtitle, ci, point, jitterv | autoplot(cm, panel = , group = , title = , interval = , data = , jitter = ); plot_args = list(...) still works (superseded) | | covariatemeans() | cm$pltdf | cm$pred_df (as semipred()); cm$pltdf still gives it, with a message once per session | | semipred() | semipred(semireg = fit) | semipred(fit) (model =, as in every function) | | semipred() | trellis, scales, plotord, ci, point, jitterv, threeD | autoplot(sp, panel = , scales = , group = , interval = , data = , jitter = , type = "3d"); plot_args = list(...) still works (superseded); threeD gives one plotly widget, not a list | | semipred(), semireg(), semireg_tmb(), permmodels(), bootmodels() | prt | removed: print(x) | | predictmeans(), covariatemeans(), residplot(), CookD(), PMplot() | newwd | removed: ggplot2 draws in the current device | | semireg(), semireg_tmb() | smoothZ = list(sm = smZ(x)) | smooths in the formula: s(x, bs = "os") (below) | | semireg() | ncenter, nscale, resp_scale | removed: variables are used as they are | | semireg() | ngbinomial = TRUE | semireg_tmb(family = glmmTMB::nbinom2) | | semireg(), semireg_tmb() | predict_info | removed: always kept | | permlmer() | lmer0 =, lmer1 = | model0 =, model1 = (any class: lmer, glmer, glmmTMB) | | permmodels() | fo = f (the formula in a variable) | removed: read from the model | | residplot() | level = 2 (the random-effect term); newwd, ask | re_level = 2; removed | | CookD() | idn = 5 | id = 5, as residplot() | | PMplot() | margin, legendx | removed: ggplot2 sizes the margins and the legend | | every function | dotted argument names: conf.level, letterCI, as.is, test.statistic, max.degree, drop.unused.levels | conf_level, letter_ci, as_is, test_statistic, max_degree, drop_unused_levels (one style: snake_case) | | smZ() | | removed: smooths in the formula | | permglmer(), permglmmTMB() | | removed: permlmer() (they were the same function) | | permanova.lmer() | | removed: permmodels(model, type = ) | | R2_glmm() | | removed: R2_model(model) | | ci_mcp() | | removed: predictmeans(..., letter_ci = TRUE) |

Every other argument of 1.1.1 is kept, with its meaning.

Smooth models: smZ() and smoothZ

Smooths are written in the formula. Their fixed terms (the covariate, and with by = f the factor and its slopes) are added automatically, so they need not be written, and cannot be forgotten. Each form below was fitted both ways on the last build that had smZ() (dev/check-smz-migration.R in the package sources): the REML log-likelihoods are equal and the fitted values and curves agree to 1e-5 or better, unless a note says otherwise.

1.1.1 wzxhzdk:11
2.0 wzxhzdk:12
1.1.1 wzxhzdk:13
2.0 wzxhzdk:14
1.1.1 wzxhzdk:15
2.0 wzxhzdk:16
1.1.1 wzxhzdk:17
2.0 wzxhzdk:18
1.1.1 wzxhzdk:19
2.0 wzxhzdk:20
1.1.1 wzxhzdk:21
2.0 wzxhzdk:22
1.1.1 wzxhzdk:23
2.0 wzxhzdk:24
1.1.1 wzxhzdk:25
2.0 wzxhzdk:26
1.1.1 wzxhzdk:27
2.0 wzxhzdk:28
1.1.1 wzxhzdk:29
2.0 wzxhzdk:30

Notes:

The models of the overview article

The smooth models of the overview article (vignettes/articles/overview.Rmd), in its 1.1.1 version and in 2.0:

1.1.1 wzxhzdk:31
2.0 wzxhzdk:32
1.1.1 wzxhzdk:33
2.0 wzxhzdk:34
1.1.1 wzxhzdk:35
2.0 wzxhzdk:36
1.1.1 wzxhzdk:37
2.0 wzxhzdk:38
1.1.1 wzxhzdk:39
2.0 wzxhzdk:40
1.1.1 wzxhzdk:41
2.0 wzxhzdk:42
1.1.1 wzxhzdk:43
2.0 wzxhzdk:44
1.1.1 wzxhzdk:45
2.0 wzxhzdk:46

| Model | REML / ML log-likelihood, 1.1.1 code | 2.0 code | | |---|---|---|---| | Warsaw, one curve | -1772.452 | -1772.452 | the same fit | | Warsaw, a curve per district | -1751.525 | -1751.525 | the same fit | | California schools | -1601.803 | -1601.803 | the same fit | | Respiratory infection, one curve | -323.509 | -323.509 | the same fit | | Respiratory infection, a curve per sex | -322.806 | -322.788 | 2.0 adds sex:age, the slope of each sex, which the 1.1.1 formula left out | | Pollen, a curve per year | -1168.703 | -1164.093 | 2.0 adds year:dayInSeason, the slope of each year, which the 1.1.1 formula left out | | Copper | -159.428 | -159.203 | 1.1.1 depended on the centring of the coordinates (-163.948 with ncenter = FALSE) |

In the two models with a curve per group, the 1.1.1 formulas had the factor but not its interaction with the covariate. A smooth by a factor then has no unpenalised slope per group, so the groups' straight-line trends are shrunk towards each other. The formula form adds the slopes itself, which is why the 2.0 fits are better.

Defaults that change

| Function | Setting | 1.1.1 | 2.0 | |---|---|---|---| | library(predictmeans) | packages attached | glmmTMB, lme4, nlme, lmerTest | lme4, nlme: add library(glmmTMB) to call glmmTMB() or nbinom1, and library(lmerTest) for its summary() p-values and ranova() | | predictmeans() | plots | drawn | none: autoplot(pm) or plot(pm) | | covariatemeans(), semipred() | plots | drawn | plot = FALSE: autoplot(x), plot = TRUE, or options(predictmeans.plot = TRUE) for a session | | every function | printing | tables printed during the call | nothing printed: print(x) | | predictmeans(), contrastmeans() | standard errors of REML lmer fits | unadjusted, with Kenward–Roger df | Kenward–Roger adjusted (below); vcov_adjust = FALSE for 1.x | | predictmeans(), contrastmeans(), covariatemeans() | df | per model class | df_method = "auto" (table in vignette("predictmeans")) | | predictmeans() | pairwise | FALSE: no comparisons unless TRUE | NULL: comparisons are made when adj, atvar, permlist, letter_ci or pairwise = TRUE asks for them; pairwise only sets what is printed | | predictmeans(), permlmer(), permmodels() | ncore | 3 | 1 | | semireg() | control | lmerControl(optimizer = "bobyqa") | lmerControl(optimizer = "nloptwrap"): the same fit to the optimizer's tolerance | | semireg() | centring | ncenter = TRUE centred every covariate | variables used as they are | | residplot() | id | FALSE | 3: the three largest residuals are labelled |

Results that change

Kenward–Roger adjusted standard errors

For lmer models fitted by REML, standard errors, confidence limits, LSDs and p-values use the Kenward–Roger adjusted covariance, as SAS DDFM=KR and emmeans do; 1.x used the unadjusted covariance with Kenward–Roger df. For balanced designs the two agree; for unbalanced ones the adjusted SEs are slightly larger. vcov_adjust = FALSE gives the 1.x numbers:

Om <- Oats[-c(1, 2, 30), ]   # unbalanced
fm_u <- lmer(yield ~ nitro * Variety + (1 | Block/Variety), data = Om)
new <- predictmeans(fm_u, "Variety")
old <- predictmeans(fm_u, "Variety", vcov_adjust = FALSE)
cbind(SE_2.0 = new$means$std.error, SE_1.x = old$means$std.error)

Means that cannot be estimated are NA

A mean that depends on aliased coefficients used to be a number that depended on which coefficient R dropped. It is now NA, with a message; estimable pairwise differences are still shown. Means over empty cells keep the 1.x rule: the average of the observed cells, with a warning.

Permutation tests

Other changes in numbers

Bugs fixed

Some 1.x results were wrong and are now right: permlist with atvar, a user-supplied Df for lmer models, factor levels containing ":", several Kmatrix() cases with transformed covariates, and others listed in NEWS.md.

The result of predictmeans()

The 1.x list elements are still there, so code that reads pm$"Predicted Means" or pm$"Pairwise p-value" keeps working. The tables means, pairs and settings hold the same numbers in one layout for every function (as.data.frame(), tidy(), summary(), autoplot()):

pm <- predictmeans(fm, "nitro", adj = "BH")
names(pm)
pm$`Predicted Means`
pm$means

New in 2.0



Try the predictmeans package in your browser

Any scripts or data that you put into this service are public.

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