Skip to contents

Two robust alternatives to Pearson's correlation that limit the influence of outlying values in either variable: the winsorized correlation and the percentage bend correlation.

Usage

winsorCor(
  x,
  y,
  conf.level = NA,
  sides = c("two.sided", "left", "right"),
  trim = 0.2,
  na.rm = FALSE,
  ...
)

percBendCor(
  x,
  y,
  conf.level = NA,
  sides = c("two.sided", "left", "right"),
  beta = 0.2,
  na.rm = FALSE,
  ...
)

Arguments

x, y

numeric vectors of the same length.

conf.level

confidence level of the interval. If set to NA (the default), only the point estimate is returned.

sides

character string specifying the sidedness of the confidence interval (one of "two.sided" (default), "left" or "right"). See ConfidenceIntervals(). The open side is \(\pm 1\).

trim

the fraction (0 to < 0.5) of observations winsorized at each end of x and of y. Default 0.2.

na.rm

logical. Should incomplete pairs be removed? Defaults to FALSE, in which case a missing value gives NA.

...

arguments for the bootstrap, see Details.

beta

the bend constant in \([0, 0.5]\), default 0.2.

Value

if conf.level = NA, a numeric scalar. Otherwise a named numeric vector with elements est, lci and uci. The result is NA if fewer than three complete pairs are available or if one variable is constant after winsorizing (resp. bending).

Details

Winsorized correlation (winsorCor()). Both variables are winsorized separately - in each, the \(g = \lfloor\gamma n\rfloor\) smallest values are set to the \((g+1)\)-th smallest and the \(g\) largest to the \((g+1)\)-th largest, \(\gamma\) = trim - and Pearson's correlation of the winsorized pairs is returned. With trim = 0 this is Pearson's correlation. The winsorized covariance matrix of several variables is varX(x, trim = ), so cov2cor(varX(m, trim = 0.2)) gives the whole correlation matrix.

Percentage bend correlation (percBendCor(), Wilcox 1994). Each variable is centered at its percentage bend location and scaled by \(\hat\omega\), the \(\lfloor(1-\beta)n\rfloor\)-th smallest absolute deviation from the median; the standardized values are then clipped to \([-1, 1]\) and correlated: $$r_{pb} = \frac{\sum a_i b_i}{\sqrt{\sum a_i^2 \sum b_i^2}}.$$ beta controls the bend: larger values give more resistance and less efficiency under normality. beta = 0.2 (the default) is Wilcox's recommendation; values above 0.5 are not sensible.

Neither coefficient estimates Pearson's \(\rho\) in general; each estimates its own population analogue, which is zero under independence and which coincides with \(\rho\) only in special cases.

Confidence intervals are obtained by resampling pairs (Wilcox 2022, sec. 9.3), as no reliable analytic interval exists. The default is the percentile interval; further arguments passed through ...:

R

number of bootstrap replicates (default 999)

type

interval type: "perc" (default), "basic", "norm" or "bca"

parallel, ncpus

as in boot::boot()

A test of independence can be based on \(T = r\sqrt{(n-2)/(1-r^2)}\), which is approximately \(t_{n-2}\) for percBendCor() and \(t_{h-2}\), \(h = n - 2g\), for winsorCor() (Wilcox 2022, sec. 9.3).

Random number generation

Confidence intervals resample and therefore advance R's global random number generator. Call base::set.seed() beforehand for reproducible intervals.

References

Wilcox, R. R. (1994) The percentage bend correlation coefficient. Psychometrika, 59, 601-616.

Wilcox, R. R. (2022) Introduction to Robust Estimation and Hypothesis Testing, 5th ed. Academic Press.

See also

Examples

set.seed(4)
x <- rnorm(30)
y <- x + rnorm(30)
y[30] <- -15                 # one wild value

pearsonCor(x, y)             # dragged down by a single pair
#> [1] 0.1041612
winsorCor(x, y)
#> [1] 0.5979955
percBendCor(x, y)
#> [1] 0.5928576

# bootstrap intervals
set.seed(1)
winsorCor(x, y, conf.level = 0.95, R = 499)
#>       est       lci       uci 
#> 0.5979955 0.2707263 0.8301336 
percBendCor(x, y, conf.level = 0.95, R = 499)
#>       est       lci       uci 
#> 0.5928576 0.3053113 0.7974624 

# winsorized correlation matrix
cov2cor(varX(swiss, trim = 0.2))
#>                   Fertility Agriculture Examination   Education    Catholic
#> Fertility         1.0000000   0.1781708  -0.6502017 -0.34571722  0.56985651
#> Agriculture       0.1781708   1.0000000  -0.4941116 -0.58495809  0.33588733
#> Examination      -0.6502017  -0.4941116   1.0000000  0.63048369 -0.64644303
#> Education        -0.3457172  -0.5849581   0.6304837  1.00000000 -0.28291421
#> Catholic          0.5698565   0.3358873  -0.6464430 -0.28291421  1.00000000
#> Infant.Mortality  0.3923164  -0.1343626  -0.1049860 -0.04670688  0.06117161
#>                  Infant.Mortality
#> Fertility              0.39231642
#> Agriculture           -0.13436265
#> Examination           -0.10498603
#> Education             -0.04670688
#> Catholic               0.06117161
#> Infant.Mortality       1.00000000