np.cor.test {nptest} | R Documentation |
Nonparametric Tests of Correlation Coefficients
Description
Denoting the Pearson product-moment correlation coefficient as
\rho = Cov(X, Y) / \sqrt{Var(X) Var(Y)}
this function implements permutation tests of H_0: \rho = \rho_0
where \rho_0
is the user-specified null value. Can also implement tests of partial correlations, semi-partial (or part) correlations, and independence.
Usage
np.cor.test(x, y, z = NULL,
alternative = c("two.sided", "less", "greater"),
rho = 0, independent = FALSE, partial = TRUE,
R = 9999, parallel = FALSE, cl = NULL,
perm.dist = TRUE, na.rm = TRUE)
Arguments
x |
|
y |
|
z |
Optional |
alternative |
Alternative hypothesis. Must be either "two.sided" ( |
rho |
Null hypothesis value |
independent |
If |
partial |
Only applicable if |
R |
Number of resamples for the permutation test (positive integer). |
parallel |
Logical indicating if the |
cl |
Cluster for parallel computing, which is used when |
perm.dist |
Logical indicating if the permutation distribution should be returned. |
na.rm |
If |
Details
Default use of this function tests the Pearson correlation between X
and Y
using the studentized test statistic proposed by DiCiccio and Romano (2017). If independent = TRUE
, the classic (unstudentized) test statistic is used to test the null hypothesis of independence.
If Z
is provided, the partial or semi-partial correlation between X
and Y
controlling for Z
is tested. For the semi-partial correlation, the effect of Z
is partialled out of X
.
Value
statistic |
Test statistic value. |
p.value |
p-value for testing |
perm.dist |
Permutation distribution of |
alternative |
Alternative hypothesis. |
null.value |
Null hypothesis value for |
independent |
Independence test? |
R |
Number of resamples. |
exact |
Exact permutation test? See Note. |
estimate |
Sample estimate of correlation coefficient |
Note
The permutation test will be exact when the requested number of resamples R
is greater than factorial(n)
minus one. In this case, the permutation distribution perm.dist
contains all factorial(n)
possible values of the test statistic.
If z = NULL
, the result will be the same as using np.reg.test
with method = "perm"
.
If z
is supplied and partial = TRUE
, the result will be the same as using np.reg.test
with method = "KC"
and homosced = FALSE
.
Author(s)
Nathaniel E. Helwig <helwig@umn.edu>
References
DiCiccio, C. J., & Romano, J. P. (2017). Robust permutation tests for correlation and regression coefficients. Journal of the American Statistical Association, 112(519), 1211-1220. doi: 10.1080/01621459.2016.1202117
Helwig, N. E. (2019). Statistical nonparametric mapping: Multivariate permutation tests for location, correlation, and regression problems in neuroimaging. WIREs Computational Statistics, 11(2), e1457. doi: 10.1002/wics.1457
Pitman, E. J. G. (1937b). Significance tests which may be applied to samples from any populations. ii. the correlation coefficient test. Supplement to the Journal of the Royal Statistical Society, 4(2), 225-232. doi: 10.2307/2983647
See Also
plot.np.cor.test
S3 plotting method for visualizing the results
Examples
# generate data
rho <- 0.5
val <- c(sqrt(1 + rho), sqrt(1 - rho))
corsqrt <- matrix(c(val[1], -val[2], val), 2, 2) / sqrt(2)
set.seed(1)
n <- 10
z <- cbind(rnorm(n), rnorm(n)) %*% corsqrt
x <- z[,1]
y <- z[,2]
# test H0: rho = 0
set.seed(0)
np.cor.test(x, y)
# test H0: X and Y are independent
set.seed(0)
np.cor.test(x, y, independent = TRUE)