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).
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)
print(pm) (or pm at the prompt) shows the
tables, autoplot(pm) (or plot(pm)) draws. predictmeans() has no plot or plot_args: the 1.x plots are
autoplot(pm) (means with one LSD bar), type = "bar", type = "ci" (the back-transformed plot, with
data = TRUE the observations) and type = "pvalue"; x, group, panel replace plotord, lines = FALSE
lineplot = FALSE, and + labs() / + theme_bw(14) the titles and basesz.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.permmodels() uses Freedman–Lane permutations, so its p-values are not those of permanova.lmer()'s refits
(Results that change).
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; letter_ci = 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, 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.
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.
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:
| 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() | 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 |
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)
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.
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) pm$`Predicted Means` pm$means
df_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 letter_ci.
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.Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.