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))
#> Error : predictmeans(): 'level' was removed in predictmeans 2.0: use conf.level = 0.9.
#> 'Df' was removed in predictmeans 2.0: use df_method = 30.
#> See vignette("migrating") for every change from 1.1.1.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).
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)1.1.1
predictmeans(fm, "nitro:Variety",
pairwise = TRUE, level = 0.1,
plotord = c(2, 1), plottitle = "Yield",
prtnum = FALSE)
predictmeans(fm, "nitro", Df = 30,
mplot = FALSE, barplot = TRUE,
pplot = FALSE, bkplot = FALSE)
predictmeans(fit, "A", trans = exp,
transOff = 1)
predictmeans(fit_pois, "A", count = TRUE)
contrastmeans(fm, "nitro", ctrmatrix = K,
Df = 30)
df_term(fm, "nitro",
type = "Satterthwaite")2.0
pm <- predictmeans(fm, "nitro:Variety",
pairwise = TRUE, conf.level = 0.9)
autoplot(pm, plotord = c(2, 1),
plottitle = "Yield")
# or plot = TRUE, plot_args = list(...)
predictmeans(fm, "nitro", df_method = 30,
plot = "bar")
predictmeans(fit, "A",
trans = function(x) exp(x) - 1)
predictmeans(fit_pois, "A")
contrastmeans(fm, "nitro", ctrmatrix = K,
df_method = 30)
df_term(fm, "nitro",
df_method = "Satterthwaite")print(pm) (or pm at the prompt) shows the
tables, autoplot(pm) draws, and plot = TRUE
draws the 1.x default plots in the call.trans is needed only for a transformation outside the
formula: log(y + 1) in the formula is detected and
back-transformed, constant included. Poisson and negative binomial means
need no count = TRUE.1.1.1
covariatemeans(fmc, "Variety",
covariate = "nitro",
covariateV = seq(0, 0.6, 0.1),
level = 0.1, trellis = FALSE,
mtitle = "Yield by nitrogen")
semipred(semireg = fs, modelterm = "QB",
covariate = "pressure",
covariateV = c(0.5, 1, 1.5),
trellis = FALSE, prt = FALSE)
Kmatrix(fmc, "Variety", covariate = "nitro",
covariateV = 0.3, prtnum = TRUE)2.0
cm <- covariatemeans(fmc, "Variety",
covariate = "nitro",
at = seq(0, 0.6, 0.1),
conf.level = 0.9)
autoplot(cm, trellis = FALSE,
mtitle = "Yield by nitrogen")
sp <- semipred(fs, "QB", "pressure",
at = c(0.5, 1, 1.5))
autoplot(sp, trellis = FALSE)
Kmatrix(fmc, "Variety", covariate = "nitro",
at = 0.3)1.1.1
permmodels() uses Freedman–Lane permutations, so its
p-values are not those of permanova.lmer()’s refits (Results that change).
1.1.1
varcomp(level = 0.9) was a confidence level already:
the value stays.R2_model() gives the values of R2_glmm()
as numbers, not as text with a % sign.ci_mcp() gave letters from the overlap of the intervals
it was given. Overlap of 95% (or 83.4%) confidence intervals does not
answer the pairwise tests; letterCI = TRUE gives letters
from comparison intervals, which overlap exactly when a pair is not
significant (vignette("predictmeans")).| 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 |
plot = c("mean", "bar", "pval", "back"), the plots
wanted |
predictmeans() |
lsd_bar, plotord, lineplot,
plottitle, plotxlab, plotylab,
jitterv, basesz |
autoplot(pm, ...) or
plot_args = list(...) |
predictmeans(), Kmatrix() |
prtnum, ndecimal, prtplt |
removed: print(pm, digits = );
autoplot(pm) |
covariatemeans() |
trellis, plotord, mtitle,
ci, point, jitterv |
autoplot(cm, ...) or
plot_args = list(...) |
semipred() |
semipred(semireg = fit) |
semipred(fit) (model =, as in every
function) |
semipred() |
trellis, scales, plotord,
ci, point, jitterv,
threeD |
autoplot(sp, ...) or
plot_args = 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 |
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(..., letterCI = TRUE) |
Every other argument of 1.1.1 is kept, with its meaning.
smZ() and smoothZSmooths 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
1.1.1
Notes:
bs = "os" is the O’Sullivan spline of
smZ() (k interior knots, 6 by default as
smZ()); bs = "ztps" is its thin-plate basis
(k = 6 knots per axis as smZ(); the default of
bs = "ztps" is 10).x before smZ() saw
it (ncenter = TRUE, the default), so knots given in the
units of the data were in the wrong place (in the check: REML
log-likelihood -398.53 against -389.12; 1.x with
ncenter = FALSE gives -389.12).smZ(x, drv = 1) (the derivative of the basis) is
semipred(fit, ..., deriv = 1).s(x, bs = "user", xt = list(basis = f)), with
f(x) returning the basis matrix; its columns must not be in
the span of the constant and x (the fixed part). The other
smZ() types ("bs", "ns", the
splines2 types, "smspline") gave their B-spline or
natural-spline columns iid random coefficients, which shrinks the curve
towards zero rather than towards a straight line; they have no formula
form that gives the same fit. bs = "os" is the penalised
B-spline that does the same job properly.fit$knots_lst, fit$range_lst,
fit$type_lst and fit$smoothZ_call are no
longer in the result; a fit made with smZ() and saved
before 2.0 cannot be used by semipred() (it says so): refit
it.The smooth models of the overview article
(vignettes/articles/overview.Rmd), in its 1.1.1 version and
in 2.0:
1.1.1
1.1.1
1.1.1
1.1.1
1.1.1
1.1.1
1.1.1
1.1.1
| 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.
| 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(), 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(), 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 |
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)
#> SE_2.0 SE_1.x
#> [1,] 8.086340 8.085432
#> [2,] 8.057580 8.057580
#> [3,] 8.138192 8.132226A 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.
permmodels() uses Freedman–Lane permutations
(method = "auto"): each term, coefficient or pair is tested
against the model without it, so the other terms keep their effects. It
works for glm, glmer and glmmTMB
too, without refits. method = "raw" is the 1.x scheme.method = "raw"
p-values for mixed models also differ slightly from 1.x.permanova.lmer() refitted each model with and without
the term through permlmer(); permmodels()
tests the same hypotheses, with other permutation p-values.trans = function(x) exp(x) - 1: the pairs have no
ratio columns. With an offset, 1.x gave ratios of
y + 1 labelled as ratios of y.semireg(ngbinomial = TRUE) took theta from a Poisson
fit, which is not the maximum-likelihood fit (on a test data set
log-likelihood -1133.60 against -1132.98 for
semireg_tmb(family = glmmTMB::nbinom2); theta 3.31 against
2.80, true value 3).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.
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)
#> [1] "Predicted Means" "Standard Error of Means"
#> [3] "Standard Error of Differences" "LSD"
#> [5] "Pairwise p-value" "predictmeansPlot"
#> [7] "predictmeansBarPlot" "mean_table"
#> [9] "p_valueMatrix" "means"
#> [11] "pairs" "settings"
pm$`Predicted Means`
#> nitro
#> 0 0.2 0.4 0.6
#> 79.3889 98.8889 114.2222 123.3889
pm$means
#> nitro estimate std.error df conf.low conf.high comparison.low
#> 1 0 79.38889 7.174754 6.791824 62.31730 96.46047 74.92186
#> 2 0.2 98.88889 7.174754 6.791824 81.81730 115.96047 94.42186
#> 3 0.4 114.22222 7.174754 6.791824 97.15064 131.29381 109.75519
#> 4 0.6 123.38889 7.174754 6.791824 106.31730 140.46047 118.92186
#> comparison.high group n estimable
#> 1 83.85592 A 18 TRUE
#> 2 103.35592 B 18 TRUE
#> 3 118.68925 C 18 TRUE
#> 4 127.85592 D 18 TRUEdf_method = "Kenward-Roger", "Satterthwaite",
"containment", "between-within",
"inner-outer", or a number.weights = "proportional" (SAS OM),
"outer", "cells", "flat".adj = "sidak",
"scheffe", "mvt" (exact single-step);
contrast_family(), specify_contrast(),
pm_joint(), pm_slopes(); comparison intervals
and letterCI. See vignette("contrasts").s(), t2(), by =),
semipred() with simultaneous bands, derivatives and curve
differences, anova() of smooth terms.permindex()),
bootmodels(). See vignette("resampling").pm_check(),
residplot() and CookD() for every model class,
varcomp() with intervals and tests,
R2_model().?pm_coef); fewer dependencies; faster Kenward–Roger and
Satterthwaite.