| corx | R Documentation |
Compute ordinary or partial correlations and format them for an APA-style table. Unrounded coefficients, p-values, and observation counts are also available separately.
corx(
data,
x = NULL,
y = NULL,
z = NULL,
method = c("pearson", "spearman", "kendall"),
stars = c(0.05, 0.01, 0.001),
p_adjust = c("none", "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr"),
round = 2,
remove_lead = TRUE,
triangle = NULL,
caption = NULL,
note = NULL,
describe = FALSE,
grey_nonsig = TRUE,
call_only = FALSE
)
data |
A data frame or matrix with at least three rows. Selected columns must be numeric or integer. Numeric columns with value labels are accepted; character and factor columns are not. |
x |
Column selection for the rows of the result. The default, |
y |
Column selection for the columns of the result, using the same syntax
as |
z |
Column selection for control variables, using the same syntax as
|
method |
Correlation method: |
stars |
Numeric p-value thresholds, listed from largest to smallest.
Each threshold a p-value falls strictly below adds one star. Use |
p_adjust |
Multiple-testing adjustment passed to |
round |
Number of decimal places in the formatted table. The default is 2. This does not round the stored coefficients or p-values. |
remove_lead |
Logical. If |
triangle |
Which part of a square matrix with the same variables in the
same order on both axes to show in the formatted table: |
caption |
Optional character string printed above the table and used as the default plot title. |
note |
Optional character string printed below the table. If |
describe |
Descriptive statistics to append for each row variable.
Use |
grey_nonsig |
Logical. If |
call_only |
Logical. If |
Ordinary Pearson correlations use the two-sided t test with n - 2 degrees
of freedom. Ordinary rank correlations use the asymptotic p-values from
stats::cor.test(). Partial correlations use ppcor::pcor.test().
Missing data. Each pair uses only the rows observed for both variables
and all controls. The n matrix records this count, even when it is zero.
Ordinary correlations based on fewer than two observations have missing
coefficients and p-values. With exactly two observations, ordinary Pearson
and Spearman correlations have a coefficient but no p-value. Partial tests
require at least three observations beyond the number of controls (two for
Kendall); otherwise both the coefficient and p-value are missing.
Multiple comparisons. The adjustment is applied to distinct unordered
variable pairs in the matrix. Self-correlations are excluded and their
p-values are left unchanged. If a pair appears in both orientations, both
cells receive the same adjusted p-value. The display selected by triangle
does not change the set of comparisons.
A list of class corx with the following components:
call: The matched function call.
apa: The formatted character matrix.
r: The unrounded matrix of correlation coefficients.
p: The matrix of p-values, adjusted if requested.
n: The matrix of observation counts.
caption, note: The text displayed with the table.
With call_only = TRUE, the result is an unclassed list containing the
matched call, the function's evaluation environment (env), and the
calling environment (parent_env).
corx-methods, print.corx(), plot.corx(), plot_mds(), to_table(),
to_clipboard().
fit <- corx(mtcars, x = c(mpg, cyl, disp), y = c(drat, qsec),
z = wt, caption = "Controlling for weight",
describe = list(M = function(x) mean(x, na.rm = TRUE)))
fit
coef(fit)
fit$p
corx(iris[, 1:4], describe = c(median, IQR = iqr, n), triangle = "lower")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.