Time Series Analysis Package

MKTEST Method

  • rc = TSA.MKTEST (y, <seasonality> ,<alpha>, <sum>, <sigma>, <z>, <crit>, <pval>);

The MKTEST function runs a Mann-Kendall test or a seasonal Mann-Kendall test.

Required Arguments

You must specify the following arguments, separated by commas:

y

specifies the input time series array.

Optional Arguments

You can also specify the following arguments, separated by commas. If you want to use a default value for any of these arguments, enter a space for it.

seasonality

specifies the seasonality of the series. You can specify an integer, or you can specify _SEASONALITY_. The predefined symbol _SEASONALITY_ is the length of the seasonal cycle that is computed by using the seasonality or the time ID interval that you specify in a PROC TSMODEL step or a runTimeCode action call. For more information about predefined symbols, see the section "Predefined Symbols" in Chapter 16, TSMODEL Procedure (SAS Visual Forecasting: Forecasting Procedures). For more information about seasonality, see the section "Seasonality in Models" in Chapter 17, Forecasting Details (SAS Visual Forecasting: Time Series Packages). The default value is 1.

alpha

specifies the significance level of the test. The default value is 0.05.

Returned Values

The MKTEST function returns the following values:

rc

returns one of the following scalar return codes:

rc Test Result
1 Series has a monotonic trend
0 Series has no trend
< 0 Computational failure

Optional Returned Values

You can also specify the following arguments, separated by commas, to request additional returned values. If you do not want the value to be returned, enter a space for it.

sum

returns the sum of the signs.

sigma

returns the standard deviation of the sum of the signs.

z

returns the Z-transformation of the sum of the signs.

crit

returns the test critical value of the Z-transformation.

pval

returns the p-value.

Details

When the specified seasonality is 1, the MKTEST function runs the Mann-Kendall test on a univariate time series and outputs the corresponding statistics. The Mann-Kendall test is a nonparametric test that is commonly used to detect monotonic trends in series. The null hypothesis, upper H 0, is that the data come from a population that has independent realizations and the data are identically distributed. The alternative hypothesis, upper H Subscript upper A, is that the data follow a monotonic trend. Given the series y Subscript t, t equals 1 comma ellipsis comma n, the Mann-Kendall test statistic S is calculated as

StartLayout 1st Row  upper S equals sigma-summation Underscript i equals 1 Endscripts Overscript n minus 1 Endscripts sigma-summation Underscript j equals i plus 1 Endscripts Overscript n Endscripts normal s normal g normal n left-parenthesis y Subscript j Baseline minus y Subscript i Baseline right-parenthesis EndLayout

where

StartLayout 1st Row  sgn left-parenthesis x right-parenthesis equals StartLayout Enlarged left-brace 1st Row 1st Column 1 2nd Column if 3rd Column x greater-than 0 2nd Row 1st Column 0 2nd Column if 3rd Column x equals 0 3rd Row 1st Column negative 1 2nd Column if 3rd Column x less-than 0 EndLayout EndLayout

Under the null hypothesis, the mean of S is upper E left-parenthesis upper S right-parenthesis equals 0, and the variance sigma squared is

StartLayout 1st Row  sigma squared equals left-parenthesis n left-parenthesis n minus 1 right-parenthesis left-parenthesis 2 n plus 5 right-parenthesis minus sigma-summation Underscript k equals 1 Endscripts Overscript p Endscripts n Subscript k Baseline left-parenthesis n Subscript k Baseline minus 1 right-parenthesis left-parenthesis 2 n Subscript k Baseline plus 5 right-parenthesis right-parenthesis slash 18 EndLayout

where p is the number of tied groups in the data set and n Subscript k is the number of data points in the kth tied group.

When the specified seasonality is greater than 1, the MKTEST function runs a seasonal Mann-Kendall test on a univariate time series. The null hypothesis, upper H 0, is that, for each season, the data come from a population that has independent realizations and the data are identically distributed. The alternative hypothesis, upper H Subscript upper A, is that the data follow a monotonic trend in one or more seasons. For the gth season,

StartLayout 1st Row  upper S Subscript g Baseline equals sigma-summation Underscript i equals 1 Endscripts Overscript n Subscript g Baseline minus 1 Endscripts sigma-summation Underscript j equals i plus 1 Endscripts Overscript n Subscript g Baseline Endscripts normal s normal g normal n left-parenthesis y Subscript j g Baseline minus y Subscript i g Baseline right-parenthesis EndLayout

and the corresponding variance is

StartLayout 1st Row  sigma Subscript g Superscript 2 Baseline equals left-parenthesis n Subscript g Baseline left-parenthesis n Subscript g Baseline minus 1 right-parenthesis left-parenthesis 2 n Subscript g Baseline plus 5 right-parenthesis minus sigma-summation Underscript k equals 1 Endscripts Overscript p Subscript g Baseline Endscripts n Subscript k g Baseline left-parenthesis n Subscript k g Baseline minus 1 right-parenthesis left-parenthesis 2 n Subscript k g Baseline plus 5 right-parenthesis right-parenthesis slash 18 EndLayout

where p Subscript g is the number of tied groups in the data set and n Subscript k g is the number of data points in the kth tied group. The seasonal Mann-Kendall statistic, S, for the entire series of m seasons is calculated according to

StartLayout 1st Row  upper S equals sigma-summation Underscript g equals 1 Endscripts Overscript m Endscripts upper S Subscript g EndLayout

The corresponding seasonal variance sigma squared is

StartLayout 1st Row  sigma squared equals sigma-summation Underscript g equals 1 Endscripts Overscript m Endscripts sigma Subscript g Superscript 2 EndLayout

The following Z-transformation of the statistic S approximately follows a standard normal distribution:

StartLayout 1st Row  upper Z equals StartLayout Enlarged left-brace 1st Row 1st Column StartFraction upper S minus 1 Over sigma EndFraction 2nd Column if 3rd Column upper S greater-than 0 2nd Row 1st Column 0 2nd Column if 3rd Column upper S equals 0 3rd Row 1st Column StartFraction upper S plus 1 Over sigma EndFraction 2nd Column if 3rd Column upper S less-than 0 EndLayout EndLayout

The test result is obtained by comparing the Z-transformation to the critical value.

The Mann-Kendall test requires at least three nonmissing observations. The constant series is regarded as no trend by the Mann-Kendall test. If any season has fewer than three nonmissing observations, the seasonal Mann-Kendall test ignores it. If no season has enough nonmissing observations, the seasonal Mann-Kendall test cannot be performed. If any season has a constant series, this season is also ignored. If all seasons have constant series, the whole series is regarded as having no trend by the seasonal Mann-Kendall test.

Examples

This example uses the TSMODEL procedure to run the Mann-Kendall test on the time series array Air:

proc tsmodel data=mylib.air outscalar = mylib.scalars;
   id date interval=month;
   var air;
   outscalar rc sum sig z crit pval;
   require tsa;
   submit;
   declare object tsa(tsa);
   rc = tsa.mktest(air,1,0.05,sum,sig,z,crit,pval);
   endsubmit;
run;
Last updated: July 09, 2026