| plot_means | R Documentation |
Plots means, with confidence intervals, and (optionally) p-values for differences of means and interactions
plot_means(
formula,
data = NULL,
cluster = NULL,
tests = "auto",
quiet = FALSE,
order = NULL,
legend.title = NULL,
col = NULL,
col.text = NULL,
values.cex = 1,
values.align = "top",
values.round = 1,
pvalue.cex = 0.9,
pvalue.col = "gray50",
ci.level = 95,
buffer.top = "auto",
...
)
formula |
A formula, e.g., |
data |
Optional data frame containing variables in the formula. |
cluster |
Optional clustering variable when there are repeated
observations per cluster
e.g., |
tests |
specifies which comparisons of means to report. Syntax involves
putting column numbers in a character string, with a - to symbolize a
comparison and a + symbolizing combination. For example tests="1-2" reports
t-test comparing columns 1 and 2. tests="1-2,3-4" t-tests comparing columns
1 & 2 and another 3 & 4. To run an interaction use parentheses:
tests= |
quiet |
Logical. When |
order |
Controls the order of |
legend.title |
Character string. Title for the legend. If |
col |
Color(s) for |
col.text |
Color for confidence intervals and other non-bar annotations.
If |
values.cex |
Numeric scalar controlling text size for mean value labels (and related annotations). |
values.align |
Where within the bars to put the mean value labels: |
values.round |
Non-negative integer. Number of decimal places for mean value labels. |
pvalue.cex |
Numeric scalar controlling p-value label size. |
pvalue.col |
Color for p-value brackets/labels. |
ci.level |
Confidence interval level for |
buffer.top |
Either |
... |
Additional arguments passed to |
When tests="auto", the function reports a small default set of
differences-of-means tests (when applicable) and, in 2x2 designs, an
interaction test:
If cluster is NULL, these are Welch
two-sample t-tests computed with t.test(..., var.equal=FALSE). If
cluster is provided, these comparisons are computed from a
regression using lm2() with clustered standard errors.
The interaction is tested using a linear regression fit
with lm2(), even when cluster is NULL; when
cluster is provided, the interaction test uses clustered standard
errors.
The regression-based tests use heteroskedasticity-robust inference (HC3) when
cluster is NULL. HC3 is a common small-sample adjustment to
White-type robust standard errors and is used to reduce sensitivity to
heteroskedasticity. When cluster is provided, plot_means()
instead uses clustered standard errors (robust to within-cluster correlation).
In the returned $means table, ciL and ciH are the lower and
upper bounds of a ci.level% confidence interval for the mean (when
available). The same confidence level is used for the confidence-interval
whiskers drawn in the figure.
A minimal list returned invisibly with two elements:
meansA data frame of means (and, when available, confidence intervals) aligned to the plotting grid.
testsA data frame of comparisons used for p-value
annotation (or NULL if not applicable).
df <- data.frame(y = rnorm(100), group = rep(c("A", "B"), 50))
plot_means(y ~ group, data = df)
df2 <- data.frame(
y = rnorm(200),
x1 = rep(c("A", "B"), 100),
x2 = rep(c("X", "Y"), each = 100)
)
plot_means(y ~ x1 + x2, data = df2)
df3 <- data.frame(
y = rnorm(600),
x1 = rep(c("control", "treatment"), times = 300),
x2 = rep(rep(c("low", "high"), each = 150), times = 2),
x3 = rep(c("online", "lab"), each = 300)
)
plot_means(y ~ x1 + x2 + x3, data = df3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.