Basic ‘kendallknight’ usage

Examples

Following the example from Real Statistics Using Excel, consider the following data for life expectancy in years and cigarettes per day:

arcade
#>    year doctorates revenue
#> 1  2000        861   1.196
#> 2  2001        830   1.176
#> 3  2002        809   1.269
#> 4  2003        867   1.240
#> 5  2004        948   1.307
#> 6  2005       1129   1.435
#> 7  2006       1453   1.601
#> 8  2007       1656   1.654
#> 9  2008       1787   1.803
#> 10 2009       1611   1.734

The Kendall’s correlation coefficient is computed as follows:

kendall_cor(arcade$doctorates, arcade$revenue)
#> [1] 0.8222222

The obtained value reveals there is a negative correlation between life expectancy and cigarettes per day. Furthermore, it is of interest to test the null hypothesis that the correlation is zero.

It is possible to test the hypothesis \(H_0:\: \tau = 0\) versus \(H_1:\: \tau \neq 0\) by using a two-tailed test with following code:

# two.sided is the default argument
kendall_cor_test(
  arcade$doctorates,
  arcade$revenue,
  alternative = "two.sided"
)
#> 
#>  Kendall's rank correlation tau
#> 
#> data:  arcade$doctorates and arcade$revenue
#> tau = 0.82222, p-value = 0.0003577
#> alternative hypothesis: true tau is not equal to 0
#> 95 percent confidence interval:
#>  0.3352653 1.0000000

Based on the obtained p-value and a significance level of 0.05, the null hypothesis is rejected. Therefore, there is evidence to suggest that the correlation is not zero.

It is also possible to test the hypothesis \(H_0:\: \tau = 0\) versus \(H_1:\: \tau < 0\) by using a one-tailed test with following code:

kendall_cor_test(
  arcade$doctorates,
  arcade$revenue,
  alternative = "less"
)
#> 
#>  Kendall's rank correlation tau
#> 
#> data:  arcade$doctorates and arcade$revenue
#> tau = 0.82222, p-value = 0.9999
#> alternative hypothesis: true tau is less than 0
#> 95 percent confidence interval:
#>  -1  1

Based on the obtained p-value and a significance level of 0.05, the null hypothesis is rejected. Therefore, there is evidence to suggest that the correlation is negative.

It is also possible to test the hypothesis \(H_0:\: \tau = 0\) versus \(H_1:\: \tau > 0\) by using a one-tailed test with following code:

kendall_cor_test(
  arcade$doctorates,
  arcade$revenue,
  alternative = "greater"
)
#> 
#>  Kendall's rank correlation tau
#> 
#> data:  arcade$doctorates and arcade$revenue
#> tau = 0.82222, p-value = 0.0001788
#> alternative hypothesis: true tau is greater than 0
#> 95 percent confidence interval:
#>  0.3352653 1.0000000

Based on the obtained p-value and a significance level of 0.05, the null hypothesis is not rejected. Therefore, there is no evidence to suggest that the correlation is positive.

mirror server hosted at Truenetwork, Russian Federation.