| Title: | Univariate and Multivariate Trend Testing |
|---|---|
| Description: | With foundations on the work by Goutali and Chebana (2024) <doi:10.1016/j.envsoft.2024.106090>, this package contains various univariate and multivariate trend tests. The main functions regard the Multivariate Dependence Trend and Multivariate Overall Trend tests as proposed by Goutali and Chebana (2024), as well as a plotting function that proves useful as a summary and complement of the tests. Although many packages and methods carry univariate tests, the Mann-Kendall and Spearman's rho test implementations are included in the package with an adapted version to hydrological formulation (e.g. as in Rao and Hamed 1998 <doi:10.1016/S0022-1694(97)00125-X> or Chebana 2022 <doi:10.1016/C2021-0-01317-1>). For better understanding of the example use of the functions, three datasets are included. These are synthetic data and shouldn't be used beyond that purpose. |
| Authors: | Dorsaf Goutali [aut, cre], Fateh Chebana [aut] |
| Maintainer: | Dorsaf Goutali <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.3 |
| Built: | 2026-05-31 08:37:11 UTC |
| Source: | https://github.com/cran/MultivariateTrendAnalysis |
Synthetic data generated using copulas and marginal distributions, with the purpose of exampling the functions of the package. Three options are given: "noTrend", "marginalTrend", and "dependenceStructure".
The generated "noTrend" data follows a Clayton copula with fixed Kendall Tau ().
"marginalTrend", follows the same copula, however the variables follow a Generalized Extreme Value
distribution with fixed scale and shape parameters (),
the location is linearly non-stationary with and .
Finally "dependenceStructure" presents trend in the dependence structure, the data
was generated from a Clayton copula with a linear non-stationary parameter.
For more information we refer the reader to the source material by Goutali and Chebana (2024).
generate_data( trend = c("noTrend", "marginalTrend", "dependenceStructure"), n = 100 )generate_data( trend = c("noTrend", "marginalTrend", "dependenceStructure"), n = 100 )
trend |
Character vector, the trend of the generated data. Options are "noTrend", "marginalTrend", and "dependenceStructure". |
n |
Integer, the number of data points to be generated. Must be between 10 and 200, default is 100. |
A dataset of dimensions with the generated data.
Goutali, D., and Chebana, F. (2024). Multivariate overall and dependence trend tests, applied to hydrology, Environmental Modelling & Software, 179, doi:10.1016/j.envsoft.2024.106090
# NO TREND generate_data("noTrend", n = 50) # TREND IN BOTH MARGINALS generate_data("marginalTrend", n = 50) # TREND IN DEPENDENCE STRUCTURE generate_data("dependenceStructure", n = 50)# NO TREND generate_data("noTrend", n = 50) # TREND IN BOTH MARGINALS generate_data("marginalTrend", n = 50) # TREND IN DEPENDENCE STRUCTURE generate_data("dependenceStructure", n = 50)
Computes the test statistic for the multivariate dependence trend (MDT) test and the p-value.
MDT_test(data, width, alpha = 0.05, Nbs = 1000)MDT_test(data, width, alpha = 0.05, Nbs = 1000)
data |
Numeric matrix, a two dimensional data set where each column is a variable. |
width |
Numeric value, the width to be used for the moving window algorithm. Should be bigger than 1 and smaller than the number of observations, see details. |
alpha |
Numeric value, significance level for the test. Must be between 0 and 1, default is 0.05 |
Nbs |
Positive Integer, number of samples to be used for bootstrapping. Default is 1000. |
The multivariate dependence trend (MDT) test allows to check for trend in the data series dependence
structure.
The moving window technique has been employed in order to take into account the dependence evolution,
represented by Kendall's , according to time.
The test proposes a null hypothesis of no trend, against an alternative hypothesis of a monotonic trend in the dependence structure. Goutali and Chebana (2024) propose the following test statistic:
Let and
be two variables of a data series, the test statistic of the MDT test is given by:
where is the empirical version of bivariate Kendall's . The
series of the Kendall's obtained through moving window with width
is , this series has length . is the time order of the rolling window series.
The choice of width is a trade-off. A small increases the number of
rolling windows for reliable analysis, while a large is necessary to have
sufficient values to identify the dependence structure. The p-value is computed using a bootstrap procedure.
Named list containing:
statistic, the MDT test statistic.
p.value, computed p-value computed using bootstrap.
result, the result of the test. If TRUE the trend is considered significant.
Goutali, D., and Chebana, F. (2024). Multivariate overall and dependence trend tests, applied to hydrology, Environmental Modelling & Software, 179, doi:10.1016/j.envsoft.2024.106090
kendall.tau : Function from the package VGAM used for computing the bivariate Kendall's .
rollapply : Function from the package zoo used to apply the moving window technique.
samp.bootstrap: Function from the resample package, used to generate the samples
necessary to perform bootstrapping.
# CASE 1: Only trend in the dependence structure # Sample data: DependenceStructure <- generate_data("dependenceStructure") width <- 10 # Perform the mdt test: mdt <- MDT_test(DependenceStructure, width, alpha = 0.05, Nbs = 1000) print(mdt) # CASE 2: Only trend in the marginal distributions # Sample data: MarginalTrend <- generate_data("marginalTrend") # Perform the mdt test: mdt <- MDT_test(MarginalTrend, width) print(mdt) # CASE 3: No trend # Sample data: NoTrend <- generate_data("noTrend") # Perform the mdt test: mdt <- MDT_test(NoTrend, width) print(mdt)# CASE 1: Only trend in the dependence structure # Sample data: DependenceStructure <- generate_data("dependenceStructure") width <- 10 # Perform the mdt test: mdt <- MDT_test(DependenceStructure, width, alpha = 0.05, Nbs = 1000) print(mdt) # CASE 2: Only trend in the marginal distributions # Sample data: MarginalTrend <- generate_data("marginalTrend") # Perform the mdt test: mdt <- MDT_test(MarginalTrend, width) print(mdt) # CASE 3: No trend # Sample data: NoTrend <- generate_data("noTrend") # Perform the mdt test: mdt <- MDT_test(NoTrend, width) print(mdt)
The functions performs the univariate Mann-Kendall test statistic to each variable of a data series.
mkComponent(data)mkComponent(data)
data |
Numeric matrix representing the data series, each column should be a component. |
Let be a dataset of components and observations.
The Mann-Kendall's (MK) test statistic for a variable of the dataset is given by:
where is the sign function:
This test statistic is normal distributed, with mean and variance:
,
A numeric vector with the univariate MK test statistic for each component of the data series.
Hamed, K.H., Rao, A.R., 1998. A modified Mann-Kendall trend test for autocorrelated data. J. Hydrol. 204 (1–4), 182–196.
Kendall, M., (1975). Rank Correlation Methods; Griffin: London.
# Sample data (Both marginal distributions have trend): dataMarginalTrend <- generate_data("marginalTrend", n = 50) # Perform multivariate MK test on sample data: mkComponent(dataMarginalTrend)# Sample data (Both marginal distributions have trend): dataMarginalTrend <- generate_data("marginalTrend", n = 50) # Perform multivariate MK test on sample data: mkComponent(dataMarginalTrend)
The functions performs the univariate Mann-Kendall test.
mkUnivariate(x)mkUnivariate(x)
x |
Numeric vector representing a data series. |
The univariate Mann-Kendall (MK) test is used to detect monotonic trends in a univariate data series.
It tests the null hypothesis () of no trend, against an alternative.
Let be a data series of length , the MK test statistic is
given by:
where is the sign function:
Under the test statistic is asymptotically normally distributed with mean and
variance:
A named list
statistic, the estimated Mann-Kendall test statistics.
p.value, the estimated p-value for the test.
Hamed, K.H., Rao, A.R., 1998. A modified Mann-Kendall trend test for autocorrelated data. J. Hydrol. 204 (1–4), 182–196.
Kendall, M., (1975). Rank Correlation Methods; Griffin: London.
mkComponent: The multivariate extension of this test.
# Sample data (Both marginal distributions have trend): dataMarginalTrend <- generate_data("marginalTrend", n = 50) # Perform two tailed MK test on sample data: mkUnivariate(dataMarginalTrend[, 1]) mkUnivariate(dataMarginalTrend[, 2])# Sample data (Both marginal distributions have trend): dataMarginalTrend <- generate_data("marginalTrend", n = 50) # Perform two tailed MK test on sample data: mkUnivariate(dataMarginalTrend[, 1]) mkUnivariate(dataMarginalTrend[, 2])
Computes the test statistic for the multivariate overall trend (MOT) test and the p-value.
MOT_test(data, covar = NULL, width, alpha = 0.05, Nbs = 1000)MOT_test(data, covar = NULL, width, alpha = 0.05, Nbs = 1000)
data |
Numeric matrix, a two dimensional data set where each column is a variable of the series. |
covar |
Numeric vector, time order of the data series. If none given |
width |
Integer, the width to be used for the moving window algorithm. Should be bigger than 1 and smaller than the number of observations, see details. |
alpha |
Numeric value, significance level for the test. Must be between 0 and 1, default is 0.05 |
Nbs |
Positive Integer, number of samples to be used for bootstrapping. Default is 1000. |
The multivariate overall trend (MOT) test allows to check for trend in
the marginals and dependence structure of a multivariate distribution.
The moving window technique has been employed in order to take into account the dependence evolution,
represented by Kendall's , according to time.
The test evaluates a null hypothesis of no trend in the data series, against an alternative hypothesis of a monotonic trend. Goutali and Chebana (2024) propose the following test statistic:
Let and be variables in a data series,
and the time order, the test statistic is given by:
where is the empirical version of bivariate Kendall's . The
series of the Kendall's obtained through moving window is ,
and is the time order of the moving window series.
The choice of width is a trade-off. A small increases the number of
rolling windows for reliable analysis, while a large is necessary to have
sufficient values to identify the dependence structure. The p-value is computed
using a bootstrap procedure.
A named list:
statistic, computed MOT test statistic.
p.value, computed p-value computed using bootstrap.
result, the result of the test. If TRUE the trend is considered significant.
Goutali, D., and Chebana, F. (2024). Multivariate overall and dependence trend tests, applied to hydrology, Environmental Modelling & Software, 179, doi:10.1016/j.envsoft.2024.106090
kendall.tau: Function from the package VGAM used for computing the bivariate Kendall's .
rollapply: Function from the package zoo used to apply the moving window technique.
samp.bootstrap: Function from the resample package, used to generate the samples
necessary to perform bootstrapping.
# CASE 1: Only trend in the dependence structure # Sample data: DependenceStructure <- generate_data("dependenceStructure", n = 50) width <- 10 # Perform the mot test: mot <- MOT_test(DependenceStructure, covar = NULL, width, alpha = 0.05, Nbs = 1000) print(mot) # CASE 2: Only trend in the marginal distributions # Sample data: MarginalTrend <- generate_data("marginalTrend", n = 50) # Perform the mot test: mot <- MOT_test(MarginalTrend, width = width) print(mot) # CASE 3: No trend # Sample data: NoTrend <- generate_data("noTrend", n = 50) # Perform the mot test: mot <- MOT_test(NoTrend, width = width) print(mot)# CASE 1: Only trend in the dependence structure # Sample data: DependenceStructure <- generate_data("dependenceStructure", n = 50) width <- 10 # Perform the mot test: mot <- MOT_test(DependenceStructure, covar = NULL, width, alpha = 0.05, Nbs = 1000) print(mot) # CASE 2: Only trend in the marginal distributions # Sample data: MarginalTrend <- generate_data("marginalTrend", n = 50) # Perform the mot test: mot <- MOT_test(MarginalTrend, width = width) print(mot) # CASE 3: No trend # Sample data: NoTrend <- generate_data("noTrend", n = 50) # Perform the mot test: mot <- MOT_test(NoTrend, width = width) print(mot)
Informative plots on the given data series in regards to univariate and multivariate trend testing.
plotTrend( data, covar = NULL, width, graph = c("summary", "variable1", "variable2", "window"), color = c("blue", "dark", "green", "warm") )plotTrend( data, covar = NULL, width, graph = c("summary", "variable1", "variable2", "window"), color = c("blue", "dark", "green", "warm") )
data |
Numeric matrix, a two dimensional data set where each column is a variable. |
covar |
Numeric vector, optional covariate vector, must be the same length as |
width |
Integer, the width to be used for the moving window algorithm. Should be bigger than 1 and smaller than the number of observations. |
graph |
Character vector, what will be plotted. Options are:
Default is "summary". |
color |
Character vector, plot color theme. Options are: "blue", "dark", "green", and "warm". |
The function is able to do three plots: "window" returns the scatter plot of
Kendall with the moving window technique, "variable1" and "variable2"
return the line plots for each variable against the covariate or "Time", finally
"summary" returns the previous plot combined in the same display.
Four color profiles are available .
The specified plot.
Goutali, D., and Chebana, F. (2024). Multivariate overall and dependence trend tests, applied to hydrology, Environmental Modelling & Software, 179, doi:10.1016/j.envsoft.2024.106090
kendall.tau : Function from the package VGAM used for computing the bivariate Kendall's .
rollapply : Function from the package zoo used to apply the moving window technique.
# Sample data: dataDependenceStructure <- generate_data("dependenceStructure", 50) dataMarginalTrend <- generate_data("marginalTrend", 50) dataNoTrend <- generate_data("noTrend", 50) # Plot Trend summary: plotTrend(dataDependenceStructure, covar = NULL, width = 10, graph = "summary", color = "blue") plotTrend(dataMarginalTrend, covar = NULL, width = 10, graph = "summary", color = "green") plotTrend(dataNoTrend, covar = NULL, width = 10, graph = "summary", color = "warm") # Plot a variable plotTrend(dataMarginalTrend, width = 10, graph = "variable1", color = "green") # Plot the evolution of Kendall tau plotTrend(dataDependenceStructure, width = 10, graph = "window", color = "warm")# Sample data: dataDependenceStructure <- generate_data("dependenceStructure", 50) dataMarginalTrend <- generate_data("marginalTrend", 50) dataNoTrend <- generate_data("noTrend", 50) # Plot Trend summary: plotTrend(dataDependenceStructure, covar = NULL, width = 10, graph = "summary", color = "blue") plotTrend(dataMarginalTrend, covar = NULL, width = 10, graph = "summary", color = "green") plotTrend(dataNoTrend, covar = NULL, width = 10, graph = "summary", color = "warm") # Plot a variable plotTrend(dataMarginalTrend, width = 10, graph = "variable1", color = "green") # Plot the evolution of Kendall tau plotTrend(dataDependenceStructure, width = 10, graph = "window", color = "warm")
The functions performs the univariate Spearman's rho test.
srUnivariate(x)srUnivariate(x)
x |
Numeric vector representing a data series. |
The Spearman's Rank test is a non-parametric trend test based on rank-order,
It tests a null hypothesis of no trend against an alternative.
Given a data series of length , the test statistic is given
by
where is the rank of the i-th observation in the data series.
Under the null hypothesis D has asymptotically normal distribution, with ,
and variance
A named list
statistic, the estimated Spearman's rho test statistics
p.value, the estimated p-value for the test.
Sneyers, R., 1990. On the Statistical Analysis of Series of Observations. World Meteorol. Organ.
# Sample data (Both marginal distributions have trend): dataMarginalTrend <- generate_data("marginalTrend", n = 50) # Perform SR test on sample data: srUnivariate(dataMarginalTrend[, 1]) srUnivariate(dataMarginalTrend[, 2])# Sample data (Both marginal distributions have trend): dataMarginalTrend <- generate_data("marginalTrend", n = 50) # Perform SR test on sample data: srUnivariate(dataMarginalTrend[, 1]) srUnivariate(dataMarginalTrend[, 2])
Performs multivariate and univariate trend tests on the given data series and returns a data frame with the results.
summaryTrend(data, width, covar = NULL)summaryTrend(data, width, covar = NULL)
data |
Numeric matrix, a two dimensional data set where each column is a variable. |
width |
Numeric value, the width to be used for the moving window algorithm. Should be bigger than 1 and smaller than the number of observations. |
covar |
Numeric vector, time order of the data series. If none give |
The function performs the Multivariate Dependence Trend and Multivariate Overall Trend tests as described by Goutali and Chebana (2024), as well as the univariate Mann-Kendall (MK) test to each variable and returns a data frame with the results.
This functions performs the test with the default values for alpha = 0.05 and Nbs = 1000,
for a more precise testing you can use the functions described in see also.
The results dataframe, a column for the respective test statistic, a column for the p-value, and four rows each for a test MDT, MOT, and MK for each variable.
Goutali, D., and Chebana, F. (2024). Multivariate overall and dependence trend tests, applied to hydrology, Environmental Modelling & Software, 179, doi:10.1016/j.envsoft.2024.106090
MDT_test: Function used to perform the MDT test.
MOT_test: Function used to compute the MOT test.
mkUnivariate: Function used to perform the univariate MK test.
# Summary for data with trend in the Dependence Structure: DependenceStructure <- generate_data("dependenceStructure", 50) summaryTrend(DependenceStructure, covar = NULL, width = 10) # Summary for data with trend in the Marginals: MarginalTrend <- generate_data("marginalTrend", 50) summaryTrend(MarginalTrend, covar = NULL, width = 10) # Summary for data without trend: NoTrend <- generate_data("noTrend", 50) summaryTrend(NoTrend, covar = NULL, width = 10)# Summary for data with trend in the Dependence Structure: DependenceStructure <- generate_data("dependenceStructure", 50) summaryTrend(DependenceStructure, covar = NULL, width = 10) # Summary for data with trend in the Marginals: MarginalTrend <- generate_data("marginalTrend", 50) summaryTrend(MarginalTrend, covar = NULL, width = 10) # Summary for data without trend: NoTrend <- generate_data("noTrend", 50) summaryTrend(NoTrend, covar = NULL, width = 10)