Package 'Kendall'

Title: Kendall Rank Correlation and Mann-Kendall Trend Test
Description: Computes the Kendall rank correlation and Mann-Kendall trend test. See documentation for use of block bootstrap when there is autocorrelation.
Authors: A.I. McLeod
Maintainer: A.I. McLeod <[email protected]>
License: GPL (>= 2)
Version: 2.2.1
Built: 2024-11-19 06:32:47 UTC
Source: CRAN

Help Index


Kendall correlation and trend tests.

Description

Compute Kendall's rank correlation and various trend tests.

Details

Package: Kendall
Type: Package
Version: 2.2
Date: 2011-05-16
License: GPL (>= 2)
LazyLoad: yes

If you just want to compute Kendall's tau or its signficance level, the base function cor and cor.test are recommended. The purpose of this package is to implement the Mann-Kendall test, the seasonal Mann-Kendall trend test as well as computing the Kendall score. See documentation for Mann-Kendall on using the block bootstrap to deal with autocorrelation.

Author(s)

A. I. McLeod

Maintainer: [email protected]

References

Hipel, K.W. and McLeod, A.I., (1994). Time Series Modelling of Water Resources and Environmental Systems.

See Also

cor, cor.test, print.Kendall, summary.Kendall, MannKendall, SeasonalMannKendall

Examples

library(boot)
data(PrecipGL)
MKtau<-function(z) MannKendall(z)$tau
tsboot(PrecipGL, MKtau, R=500, l=5, sim="fixed")

Phosphorous Concentrations in Speed River, Monthly

Description

Monthly time series of phosphorous (P) concentrations in mg/l, Speed River, Guelph, Ontario, 1972.1-1977.1."

Usage

data(GuelphP)

Format

The format is: Time-Series [1:72] from 1972 to 1978: 0.47 0.51 0.35 0.19 0.33 NA 0.365 0.65 0.825 1 ... - attr(*, "title")= chr "Phosphorous Data,Speed River,Guelph,1972.1-1977.1"

Details

See Hipel and McLeod (2005, pp.707-709 and p.986). Hipel and McLeod used intervention analysis to estimate the effect of a phosphorous removal scheme. Intervention analysis was also used to estimate the missing values.

Source

Hipel, K.W. and McLeod, A.I., (2005). Time Series Modelling of Water Resources and Environmental Systems. Electronic reprint of our book orginally published in 1994. http://www.stats.uwo.ca/faculty/aim/1994Book/.

Examples

data(GuelphP)
plot(GuelphP)
#replace missing values in the series with estimates obtained from Hipel and McLeod
# (2005, p. 986)
missingEst<-c(0.1524, 0.2144, 0.3064, 0.1342)
GuelphP2<-GuelphP
GuelphP2[is.na(GuelphP)]<-missingEst

Kendall rank correlation

Description

Computes the Kendall rank correlation and its p-value on a two-sided test of H0: x and y are independent. If there are no ties, the test is exact and in this case it should agree with the base function cor(x,y,method="kendall") and cor.test(x,y,method="kendall"). When there are ties, the normal approximation given in Kendall is used as discussed below. In the case of ties, both Kendall and cor produce the same result but cor.test produces a p-value which is not as accurate

Usage

Kendall(x, y)

Arguments

x

first variable, a vector

y

second variable, a vector the same length as x

Details

In many applications x and y may be ranks or even ordered categorical variables. In our function x and y should be numeric vectors or factors. Any observations correspondings to NA in either x or y are removed.

Kendall's rank correlation measures the strength of monotonic association between the vectors x and y. In the case of no ties in the x and y variables, Kendall's rank correlation coefficient, tau, may be expressed as τ=S/D\tau = S/D where

S=i<j(sign(x[j]x[i])sign(y[j]y[i]))S=\sum_{i<j} (sign(x[j]-x[i])*sign(y[j]-y[i]))

and D=n(n1)/2D=n(n-1)/2. S is called the score and D, the denominator, is the maximum possible value of S. When there are ties, the formula for D is more complicated (Kendall, 1974, Ch. 3) and this general forumla for ties in both reankings is implemented in our function.

The p-value of tau under the null hypothesis of no association is computed by in the case of no ties using an exact algorithm given by Best and Gipps (1974).

When ties are present, a normal approximation with continuity correction is used by taking S as normally distributed with mean zero and variance var(S), where var(S) is given by Kendall (1976, eqn 4.4, p.55). Unless ties are very extensive and/or the data is very short, this approximation is adequate. If extensive ties are present then the bootstrap provides an expedient solution (Davis and Hinkley, 1997). Alternatively an exact method based on exhaustive enumeration is also available (Valz and Thompson, 1994) but this is not implemented in this package.

An advantage of the Kendall rank correlation over the Spearman rank correlation is that the score function S nearly normally distributed for small n and the distribution of S is easier to work with.

It may also be noted that usual Pearson correlation is fairly robust and it usually agrees well in terms of statistical significance with results obtained using Kendall's rank correlation.

An error is returned if length(x) is less than 3.

Value

A list with class Kendall is returned with the following components:

tau

Kendall's tau statistic

sl

two-sided p-value

S

Kendall Score

D

denominator, tau=S/D

varS

variance of S

Note

Generic functions print.Kendall and summary.Kendall are provided.

If you want to use the output from Kendall, save the result as in out<-Kendall(x,y) and then select from the list out the value(s) needed.

Author(s)

A.I. McLeod, [email protected]

References

Best, D.J. and Gipps, P.G. (1974), Algorithm AS 71: The Upper Tail Probabilities of Kendall's Tau Applied Statistics, Vol. 23, No. 1. (1974), pp. 98-100.

Davison, A.C. and Hinkley, D.V. (1997) Bootstrap Methods and Their Application. Cambridge University Press.

Kendall, M.G. (1976). Rank Correlation Methods. 4th Ed. Griffin.

Hill, I.D. (1973), Algorithm AS 66: The Normal Integral Applied Statistics, Vol. 22, No. 3. (1973), pp. 424-427.

Valz, P. (1990). Developments in Rank Correlation Procedures with Applications to Trend Assessment in Water Resources Research, Ph.D. Thesis, Department of Statistical and Actuarial Sciences, The University of Western Ontario.

Valz, P.D. and Thompson, M.E. (1994), Exact inference for Kendall's S and Spearman's rho. Journal of Computational and Graphical Statistics, 3, 459–472.

See Also

cor, print.Kendall, summary.Kendall, MannKendall, SeasonalMannKendall

Examples

#First Example
#From Kendall (1976, p.42-43, Example 3.4)
A<-c(2.5,2.5,2.5,2.5,5,6.5,6.5,10,10,10,10,10,14,14,14,16,17)
B<-c(1,1,1,1,2,1,1,2,1,1,1,1,1,1,2,2,2)
summary(Kendall(A,B))
#Kendall obtains S=34, D=sqrt(116*60), tau=0.41

#Second Example
#From Kendall (1976, p.55, Example 4.3)
x<-c(1.5,1.5,3,4,6,6,6,8,9.5,9.5,11,12)
y<-c(2.5,2.5,7,4.5,1,4.5,6,11.5,11.5,8.5,8.5,10)
summary(Kendall(x,y))
#Kendall obtains S=34 and Var(S)=203.30

Mann-Kendall trend test

Description

This is a test for monotonic trend in a time series z[t] based on the Kendall rank correlation of z[t] and t.

Usage

MannKendall(x)

Arguments

x

a vector of data, often a time series

Details

The test was suggested by Mann (1945) and has been extensively used with environmental time series (Hipel and McLeod, 2005). For autocorrelated time series, the block bootstrap may be used to obtain an improved signficance test.

Value

A list with class Kendall.

tau

Kendall's tau statistic

sl

two-sided p-value

S

Kendall Score

D

denominator, tau=S/D

varS

variance of S

Generic function print.Kendall and summary.Kendall are provided to print the output.

Note

If you want to use the output from MannKendall, save the result as in res<-MannKendall(x,y) and then select from the list res the value(s) needed.

Author(s)

A.I. McLeod, [email protected]

References

Davison, A.C. and Hinkley, D.V. (1997) Bootstrap Methods and Their Application. Cambridge University Press.

Hipel, K.W. and McLeod, A.I., (2005). Time Series Modelling of Water Resources and Environmental Systems. Electronic reprint of our book orginally published in 1994. http://www.stats.uwo.ca/faculty/aim/1994Book/.

Mann, H.B. (1945), Nonparametric tests against trend, Econometrica, 13, 245-259.

See Also

Kendall, SeasonalMannKendall tsboot

Examples

# Annual precipitation entire Great Lakes
# The time series plot with lowess smooth suggests an upward trend
# The autocorrelation in this data does not appear significant.
# The Mann-Kendall trend test confirms the upward trend.
data(PrecipGL)
plot(PrecipGL)
lines(lowess(time(PrecipGL),PrecipGL),lwd=3, col=2)
acf(PrecipGL)
MannKendall(PrecipGL)
#
#Use block bootstrap 
library(boot)
data(PrecipGL)
MKtau<-function(z) MannKendall(z)$tau
tsboot(PrecipGL, MKtau, R=500, l=5, sim="fixed")
#
# Deseasonalize a monthly time series and use the block bootstrap
library(boot)
data(manaus)
z<-matrix(manaus, ncol=12, byrow=12)
zm<-apply(z, MARGIN=2, FUN=mean)
zs<-apply(z, MARGIN=2, FUN=sd)
z2<-sweep(z, MARGIN=2, STATS=zm) #subtract monthly means
z3<-sweep(z2, MARGIN=2, STATS=zs, FUN="/") #divide by monthly sd
zds<-c(t(z3)) 
attributes(zds)<-attributes(manaus)
plot(zds)
#do Mann-Kendall trend test
MannKendall(zds)
#check robustness by applying block bootstrap
MKtau<-function(z) MannKendall(z)$tau
tsboot(zds, MKtau, R=500, l=12, sim="fixed")
#the significance level has dropped!
#it is significant now at about 2 sd

Annual precipitation, inches, Great Lakes, 1900-1986

Description

Annual precipitation, 1900-1986, Entire Great Lakes

Usage

data(PrecipGL)

Format

The format is: Time-Series [1:87] from 1900 to 1986: 31.7 29.8 31.7 33.1 31.3 ...

Source

Appendix A of H. Roberts (1992) "Data Analysis for Managers" published by Scientific Press.

Original Source: Great Lake Water Levels, U.S. Dept of Commerce, Rockville MD U.S. Lake Survey, Detroit, MI, US Army Corps of Engineers

Examples

data(PrecipGL)
plot(PrecipGL)

print Method for Class 'Kendall'

Description

The value of Kendall's tau and its two-sided p-value are displayed.

Usage

## S3 method for class 'Kendall'
print(x, ...)

Arguments

x

output from Kendall, MannKendall or SeasonalMannKendall

...

any additional arguments

Value

NULL

Note

If you want to use the output from Kendall or the other functions, save the result as in res<-Kendall(x,y) and then select from res the value(s) needed.

Author(s)

A.I. McLeod, [email protected]

See Also

summary.Kendall, Kendall, MannKendall,SeasonalMannKendall, summary.Kendall

Examples

x<-1:10
y<-rnorm(10)
Kendall(x,y)
#is equivalent to
out<-Kendall(x,y)
print(out)

Mann-Kendall trend test for monthly environmental time series

Description

Hirst et al. (1982) suggested this test for monthly water quality time series. The test is also discussed by Hipel and McLeod (2005).

The score is computed separately for each month.

The purpose of this test is to test for monotonic trend. A common misconception is to look for trends in the individual monthly time series. Usually this does not make a lot of sense, in the context of environmental time series, since if there is a real trend of interest in the series it would not be expected to be greatly changed by seasonality. If indeed one were interested in detecting a trend a particular month then one could use the MannKendall trend test for that particular month or group of months.

Usage

SeasonalMannKendall(x)

Arguments

x

a vector or a time series comprised of consecutive monthly values

Value

A list with class Kendall.

tau

Kendall's tau statistic

sl

two-sided p-value

S

Kendall Score

D

Denominator, tau=S/D

varS

variance of S

Generic function print.Kendall and summary.Kendall are provided.

Note

If you want to use the output from SeasonalMannKendall, save the result as in res<-SeasonalMannKendall(x,y) and then select from the list res the value(s) needed.

Author(s)

A.I. McLeod, [email protected]

References

Hirsch, R.M., Slack, J.R. and Smith, R.A. (1982), Techniques for trend assessment for monthly water quality data, Water Resources Research 18, 107-121.

Hipel, K.W. and McLeod, A.I., (2005). Time Series Modelling of Water Resources and Environmental Systems. Electronic reprint of our book orginally published in 1994. http://www.stats.uwo.ca/faculty/aim/1994Book/.

See Also

MannKendall

Examples

#test for monotonic trend in monthly average river height data
#for the Rio Negro at Manaus. This data is included in the 
#package boot.
library(boot) 
data(manaus)
SeasonalMannKendall(manaus)

summary Method for Class 'Kendall'

Description

In addition to the value of Kendall's tau and its two-sided p-value are displayed, the Kendall score, its variance and the value of the denominator for Kendall tau are printed.

Usage

## S3 method for class 'Kendall'
summary(object, ...)

Arguments

object

output from Kendall, MannKendall or SeasonalMannKendall

...

any additional arguments

Value

NULL

Note

If you want to use the output from Kendall or the other functions, save the result as in res<-Kendall(x,y) and then select from res the value(s) needed.

Author(s)

A.I. McLeod, [email protected]

See Also

summary.Kendall, Kendall, MannKendall,SeasonalMannKendall, print.Kendall

Examples

x<-1:10
y<-rnorm(10)
out<-Kendall(x,y)
out
summary(out)