| apa_cor | R Documentation |
APA-formatted correlation table
apa_cor(
data,
alpha = c(0.05, 0.01, 0.001),
digits = 2,
bold_significant = FALSE,
star_significant = TRUE,
significance_note = TRUE,
keep_empty_star_columns = TRUE,
summary_functions = list(M = mean, SD = stats::sd),
column_formats = NULL,
method = "pearson",
p_adjust = "none",
partial = FALSE,
...,
output,
note,
font_family,
font_size,
text_color,
border_color,
border_width,
line_spacing,
table_width,
p_value
)
data |
data.frame or tibble with variables to be correlated, or the
output of |
alpha |
p-value thresholds for significance stars, from largest to
smallest (default: |
digits |
number of decimal places of the correlations (unaffected by
|
bold_significant |
if |
star_significant |
if |
significance_note |
if |
keep_empty_star_columns |
if |
summary_functions |
Any named list of functions that summarize data columns (e.g., |
column_formats |
|
method |
kind of correlation (e.g., |
p_adjust |
method of adjusting the p-values (and so the stars) for
multiple comparisons (e.g., |
partial |
if |
... |
other arguments passed to |
output, note, font_family, font_size, text_color, border_color, border_width, line_spacing, table_width |
deprecated. If any is given, a flextable is returned as in apa7 0.2.0,
with a warning (except |
p_value |
deprecated; use |
apa_cor() computes the correlations with correlation::correlation().
By default, they are Pearson correlations of all pairwise complete
observations, and the stars are for unadjusted p-values. Use method,
p_adjust, partial, and the other arguments of
correlation::correlation() for other kinds of correlations. The column
names of data are the variable names in the table, and they can contain
spaces and symbols (e.g., "Reading comprehension") for every kind of
correlation: apa_cor() gives the variables internal names while the
correlations are computed. Logical columns are correlated as 0 and 1.
The output of correlation::correlation() can also be passed as data.
The table shows its correlations and p-values, and the summary columns
are computed from the data that correlation::correlation() keeps with
its results. Note that correlation::correlation() uses Holm's method by
default, so the stars are for adjusted p-values unless
p_adjust = "none", and that its partial and multilevel correlations do
not accept variable names with spaces. For those, use
apa_cor(data, partial = TRUE) instead.
apa_cor() returns an apa7_tbl, which is displayed as an APA-style
table in documents (see apa7_tbl). apa_note() writes its note: what
kind of correlations are shown (unless they are ordinary Pearson
correlations), how the p-values were adjusted for multiple comparisons,
and what the stars or bold values mean. With apaquarto, use the
apa-note chunk option (e.g., #| apa-note: !expr apa7::apa_note(tbl)).
Otherwise, use apa_flextable(tbl, note = TRUE). Correlations computed by
group, between two sets of variables, or with Bayesian methods are not yet
supported.
In apa7 0.2.0 and earlier, apa_cor() computed the correlations with
psych::corTest(). Its adjust argument is still accepted as
p_adjust, with a warning, and use = "complete" removes incomplete
rows, with a warning. Until apa7 0.3.0, apa_cor() returned a flextable
with the note below it, and it took the arguments that style a flextable.
These arguments still work, with a warning.
apa7_tbl (tibble)
Benjamini, Y., & Hochberg, Y. (1995). Controlling the false discovery rate: A practical and powerful approach to multiple testing. Journal of the Royal Statistical Society: Series B (Methodological), 57(1), 289–300. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/j.2517-6161.1995.tb02031.x")}
Holm, S. (1979). A simple sequentially rejective multiple test procedure. Scandinavian Journal of Statistics, 6(2), 65–70.
tbl <- apa_cor(mtcars[, c("mpg", "am", "gear", "carb")])
tbl
apa_note(tbl)
# A flextable with the note below it, for documents without apaquarto
apa_flextable(tbl, note = TRUE)
# Significant correlations in bold instead of starred
apa_cor(mtcars[, c("mpg", "am", "gear", "carb")], bold_significant = TRUE)
# Partial Spearman correlations, with variable names that have spaces
d <- mtcars[, c("mpg", "wt", "hp")]
names(d) <- c("Miles per gallon", "Weight (1000 lbs)", "Gross horsepower")
apa_cor(d, method = "spearman", partial = TRUE)
# Output of correlation::correlation()
correlation::correlation(trees, method = "spearman") |>
apa_cor()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.