November 4, 2019

In class example

x = c(1,    5,  9,  7,  4,  6,  8,  2,  3)
y = c(4,    3,  6,  8,  2,  7,  9,  1,  5)
cor(x,y, method = "spearman")
## [1] 0.7166667
cor.test(x,y, method = "spearman")
## 
##  Spearman's rank correlation rho
## 
## data:  x and y
## S = 34, p-value = 0.03687
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##       rho 
## 0.7166667

In class example

How good is the normal approximation?

x = c(1,5,9,7,4,6,8,2,3)
y = c(4,3,6,8,2,7,9,1,5)
n = length(x)
r_s = cor(x,y, method = "spearman")
(normal.p.value = 2*(1 - pnorm(sqrt(length(x)-1)*r_s)))
## [1] 0.04265838
(t.p.value = 2*(1 - pt((r_s*sqrt(n-2))/sqrt(1-r_s^2),df = n-2)))
## [1] 0.02981804
  • The exact P-value is 0.03687. Which one is closer?

In class example

x = c(1,    5,  9,  7,  4,  6,  8,  2,  3)
y = c(4,    3,  6,  8,  2,  7,  9,  1,  5)
cor.test(x,y, method = "kendall")
## 
##  Kendall's rank correlation tau
## 
## data:  x and y
## T = 28, p-value = 0.04462
## alternative hypothesis: true tau is not equal to 0
## sample estimates:
##       tau 
## 0.5555556

In class example

Using the Normal approximation: \[ Z = 3 \sqrt{n(n-1)}\tau/\sqrt{2(2n+5)} \]

x = c(1,5,9,7,4,6,8,2,3)
y = c(4,3,6,8,2,7,9,1,5)
n = length(x)
T = cor(x,y, method = "kendall")
Z = 3*sqrt(n*(n-1))*T/sqrt(2*(2*n+5))
normal.p.value = 2*(1 - pnorm(Z))
cat("P value = ", normal.p.value, "\n")
## P value =  0.03705622
  • Exact P-value = 0.04462.

Divorce Example - Mann’s Test (Kendall’s)

year = seq(1945,1985,by=5)
divorce.rate = c(3.5,   2.6,    2.3,    2.2,    2.5,    3.6,
                 4.8,   5.2,    5)
cor.test(year,divorce.rate, method = "kendall")
## 
##  Kendall's rank correlation tau
## 
## data:  year and divorce.rate
## T = 27, p-value = 0.07518
## alternative hypothesis: true tau is not equal to 0
## sample estimates:
## tau 
## 0.5

Divorce Example - Daniel’s Test (Separman’s)

year = seq(1945,1985,by=5)
divorce.rate = c(3.5,   2.6,    2.3,    2.2,    2.5,    3.6,    
                 4.8,   5.2,    5)
cor.test(year,divorce.rate, method = "spearman")
## 
##  Spearman's rank correlation rho
## 
## data:  year and divorce.rate
## S = 36, p-value = 0.04325
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho 
## 0.7