Title: | Spearman's Rank Correlation Test |
---|---|
Description: | Spearman's rank correlation test with precomputed exact null distribution for n <= 22. |
Authors: | Petr Savicky <[email protected]> |
Maintainer: | Petr Savicky <[email protected]> |
License: | GPL-3 |
Version: | 0.3-1 |
Built: | 2024-10-28 07:00:51 UTC |
Source: | CRAN |
This function provides three types of approximations of the distribution
function of Spearman's rho. Besides the two approximations
used in cor.test(,method="spearman")
, which are AS89 and the t-distribution,
this function allows to use precomputed null distribution for n <= 22
.
See spearman.test
for the details of the algorithm used to compute this
null distribution.
pspearman(s, n, lower.tail = TRUE, approximation = c("exact", "AS89", "t-distribution"))
pspearman(s, n, lower.tail = TRUE, approximation = c("exact", "AS89", "t-distribution"))
s |
The observed value of S statistics |
n |
The number of observations. |
lower.tail |
If TRUE (the default), the probability of |
approximation |
Selection of the method of approximation of the distribution function. |
See spearman.test
for more detail.
Depending on lower.tail
, either the probability of S <= s
or of S >= s
is computed, where S is the statistics
sum((rank(x) - rank(y))^2)
.
pspearman(36, 10, approximation="exact") # [1] 0.005265377 pspearman(36, 10, approximation="AS89") # [1] 0.005825634
pspearman(36, 10, approximation="exact") # [1] 0.005265377 pspearman(36, 10, approximation="AS89") # [1] 0.005825634
This function is a modification of the part of the function cor.test()
, which
evaluates Spearman's rank correlation test. Besides the two approximations
used in cor.test(,method="spearman")
, which are AS89 and the t-distribution,
this function allows to use precomputed null distribution for n <= 22
.
spearman.test(x, y, alternative = c("two.sided", "less", "greater"), approximation = c("exact", "AS89", "t-distribution"))
spearman.test(x, y, alternative = c("two.sided", "less", "greater"), approximation = c("exact", "AS89", "t-distribution"))
x , y , alternative
|
have the same meaning as in |
approximation |
selection of the method to approximate the null distribution |
Calculation of the exact null distribution of Spearman's rank correlation statistics
is exponentially hard in n
. This package uses precomputed exact distribution
for n <= 22
obtained using Ryser's formula applied to an appropriate monomial
permanent as described in
M.A. van de Wiel and A. Di Bucchianico,
Fast computation of the exact null distribution of Spearman's rho and Page's L statistic
for samples with and without ties, J. Stat. Plann. Inf. 92 (2001), pp. 133-145.
using code written by the author of the package. The resulting distributions are
identical to those computed by an independent program kindly provided by M.A. van de Wiel.
A list with class "htest"
with the same structure as the value
of the function cor.test(method="spearman")
. Except of the
p-value, also the contents is identical.
x <- 1:10 y <- c(5:1, 6, 10:7) out1 <- spearman.test(x, y) out2 <- spearman.test(x, y, approximation="AS89") out3 <- cor.test(x, y, method="spearman") out1$p.value # [1] 0.05443067 this is the exact value out2$p.value # [1] 0.05444507 approximation obtained from AS89 out3$p.value # [1] 0.05444507 ditto
x <- 1:10 y <- c(5:1, 6, 10:7) out1 <- spearman.test(x, y) out2 <- spearman.test(x, y, approximation="AS89") out3 <- cor.test(x, y, method="spearman") out1$p.value # [1] 0.05443067 this is the exact value out2$p.value # [1] 0.05444507 approximation obtained from AS89 out3$p.value # [1] 0.05444507 ditto