Learn R Programming

rcompanion (version 2.4.36)

spearmanRho: Spearman's rho, Kendall's tau, Pearson's r

Description

Calculates Spearmans's rho, Kendall's tau, or Pearson's r with confidence intervals by bootstrap

Usage

spearmanRho(
  formula = NULL,
  data = NULL,
  x = NULL,
  y = NULL,
  method = "spearman",
  ci = FALSE,
  conf = 0.95,
  type = "perc",
  R = 1000,
  histogram = FALSE,
  digits = 3,
  reportIncomplete = FALSE,
  ...
)

Value

A single statistic, rho, tau, or r. Or a small data frame consisting of rho, tau, or r, and the lower and upper confidence limits.

Arguments

formula

A formula indicating the two paired variables, e.g. ~ x + y. The variables should be vectors of the same length.

data

The data frame to use.

x

If no formula is given, the values for one variable.

y

The values for the other variable.

method

One of "spearman", "kendall", or "pearson". Passed to cor.

ci

If TRUE, returns confidence intervals by bootstrap. May be slow.

conf

The level for the confidence interval.

type

The type of confidence interval to use. Can be any of "norm", "basic", "perc", or "bca". Passed to boot.ci.

R

The number of replications to use for bootstrap.

histogram

If TRUE, produces a histogram of bootstrapped values.

digits

The number of significant digits in the output.

reportIncomplete

If FALSE (the default), NA will be reported in cases where there are instances of the calculation of the statistic failing during the bootstrap procedure.

...

Additional arguments passed to the cor function.

Author

Salvatore Mangiafico, mangiafico@njaes.rutgers.edu

Details

This function is a wrapper for stats::cor with the addition of confidence intervals.

The input should include either formula and data; or x, and y.

Currently, the function makes no provisions for NA values in the data. It is recommended that NAs be removed beforehand.

When the returned statistic is close to -1 or close to 1, or with small sample size, the confidence intervals determined by this method may not be reliable, or the procedure may fail.

References

https://rcompanion.org/handbook/I_10.html

Examples

Run this code
data(Catbus)
spearmanRho( ~ Steps + Rating, data=Catbus)

Run the code above in your browser using DataLab