Package 'pspearman'

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-03-27 08:34:42 UTC
Source: CRAN

Help Index


Distribution function of Spearman's rho

Description

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.

Usage

pspearman(s, n, lower.tail = TRUE,
        approximation = c("exact", "AS89", "t-distribution"))

Arguments

s

The observed value of S statistics sum((rank(x) - rank(y))^2).

n

The number of observations.

lower.tail

If TRUE (the default), the probability of S <= s is computed. If FALSE, the probability of S >= s is computed.

approximation

Selection of the method of approximation of the distribution function.

Details

See spearman.test for more detail.

Value

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).

Examples

pspearman(36, 10, approximation="exact") # [1] 0.005265377
  pspearman(36, 10, approximation="AS89")  # [1] 0.005825634

Spearman's rank correlation test with precomputed null distribution

Description

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.

Usage

spearman.test(x, y,
    alternative = c("two.sided", "less", "greater"),
    approximation = c("exact", "AS89", "t-distribution"))

Arguments

x, y, alternative

have the same meaning as in cor.test. See the corresponding help page.

approximation

selection of the method to approximate the null distribution

Details

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.

Value

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.

Examples

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