stat_cor_test: Correlation analysis

View source: R/statistical.R

stat_cor_testR Documentation

Correlation analysis

Description

Function to calculate Correlation coefficient and P-value between the columns of x and the columns of y, using one of Pearson's product moment correlation coefficient, Kendall's tau or Spearman's rho.

Usage

stat_cor_test(
  x,
  y = NULL,
  use = c("pairwise.complete.obs", "everything", "all.obs", "complete.obs",
    "na.or.complete"),
  method = c("spearman", "pearson", "kendall"),
  alternative = c("two.sided", "less", "greater"),
  exact = TRUE,
  cor_test = FALSE,
  padj_method = "fdr",
  ...
)

Arguments

x, y

data.frame object. x and y must have the same nrow, every column in x or y will be coerced to a numeric vector.

use

an optional character string giving a method for computing covariances in the presence of missing values. This must be (an abbreviation of) one of the strings "everything", "all.obs", "complete.obs", "na.or.complete", or "pairwise.complete.obs". Default: "pairwise.complete.obs". See cor.

method

a character string indicating which correlation coefficient (or covariance) is to be computed. One of "pearson", "kendall", or "spearman", can be abbreviated. Default: "spearman"

alternative

indicates the alternative hypothesis and must be one of "two.sided", "greater" or "less". You can specify just the initial letter. "greater" corresponds to positive association, "less" to negative association.

exact

a logical indicating whether an exact p-value should be computed. Used for Kendall's tau and Spearman's rho. See cor.test. Default: TRUE.

cor_test

a logical value indicates whether the estimation of P-value should use cor.test instead. If FALSE, the estimation of P-value will use stats::pt() (for spearman or pearson) or stats::pnorm() (for kendall). Default: FALSE.

padj_method

See p.adjust method.

...

Other parameters passed to cor.test.

Details

See cor.test and cor.

Value

a tibble of the Correlation results. (see cor.test).

Author(s)

Yun yunyunpp96@outlook.com

Examples

stat_cor_test(mtcars)
stat_cor_test(mtcars, cor_test = TRUE)

Yunuuuu/yjtools documentation built on Jan. 29, 2024, 5:30 a.m.