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:

cigarettes
#>    life_expectancy cigarettes_per_day
#> 1               78                  4
#> 2               78                 23
#> 3               60                 25
#> 4               53                 48
#> 5               85                 17
#> 6               84                  8
#> 7               73                  4
#> 8               78                 26
#> 9               78                 23
#> 10              75                 19
#> 11              65                 24
#> 12              72                 35
#> 13              58                 29
#> 14              92                  4
#> 15              65                 14

The Kendall’s correlation coefficient is computed as follows:

kendall_cor(cigarettes$life_expectancy, cigarettes$cigarettes_per_day)
#> [1] -0.5427752

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 H0τ = 0 versus H1τ ≠ 0 by using a two-tailed test with following code:

# two.sided is the default argument
kendall_cor_test(
  cigarettes$life_expectancy,
  cigarettes$cigarettes_per_day,
  alternative = "two.sided"
)
#> $statistic
#> [1] -0.5427752
#> 
#> $p_value
#> [1] 0.006514513
#> 
#> $alternative
#> [1] "alternative hypothesis: true tau is not equal to 0"

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 H0τ = 0 versus H1τ < 0 by using a one-tailed test with following code:

kendall_cor_test(
  cigarettes$life_expectancy,
  cigarettes$cigarettes_per_day,
  alternative = "less"
)
#> $statistic
#> [1] -0.5427752
#> 
#> $p_value
#> [1] 0.003257256
#> 
#> $alternative
#> [1] "alternative hypothesis: true tau is less than 0"

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 H0τ = 0 versus H1τ > 0 by using a one-tailed test with following code:

kendall_cor_test(
  cigarettes$life_expectancy,
  cigarettes$cigarettes_per_day,
  alternative = "greater"
)
#> $statistic
#> [1] -0.5427752
#> 
#> $p_value
#> [1] 0.9978403
#> 
#> $alternative
#> [1] "alternative hypothesis: true tau is greater than 0"

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.