Title: | Mann-Kendall correlation and Theil-Sen slope for possibly autocorrelated time series |
---|---|
Description: | A re-do of part of the fume package to be (hopefully) feasible for larger data sets. |
Authors: | Ken Butler [aut, cre] |
Maintainer: | Ken Butler <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1 |
Built: | 2025-02-19 03:13:29 UTC |
Source: | https://github.com/nxskok/mkac |
Detrend a time series by subtracting Theil-Sen slope
detrend(x)
detrend(x)
x |
numeric, a time series return time series detrended |
Ken Butler, [email protected]
y=c(2,3,5,6) detrend(y)
y=c(2,3,5,6) detrend(y)
Calculate S statistic for Kendall correlation with time (+1 for concordance, -1 for discordance)
kendall_S(x)
kendall_S(x)
x |
numeric, a time series |
number of concordances minus number of discordances
Ken Butler, [email protected]
kendall_S(c(2,3,5,4))
kendall_S(c(2,3,5,4))
Kendall test statistic for testing time trend (no autocorrelation)
kendall_Z(x)
kendall_Z(x)
x |
numeric, a time series |
test statistic
Ken Butler, [email protected]
kendall_Z(c(2,3,5,4))
kendall_Z(c(2,3,5,4))
Mann-Kendall correlation test, unadjusted and adjusted for autocorrelation, with P-values
kendall_Z_adjusted(x, ...)
kendall_Z_adjusted(x, ...)
x |
numeric, a time series |
... |
optional arguments to "acf", eg. lag.max (see sample_size_ratio) |
list: unadjusted and adjusted Z statistics, effective sample size ratio, unadjusted and adjusted P-values
Ken Butler, [email protected]
set.seed(457299) x=rnorm(100) # uncorrelated (no adjustment needed) x=x+0.02*(1:100) # with trend kendall_Z_adjusted(x) # ar(1) data set.seed(457298) xx=stats::arima.sim(list(ar=0.8),100) # autocorrelated, needs adjusting kendall_Z_adjusted(xx) # P-value adjusted is much less significant
set.seed(457299) x=rnorm(100) # uncorrelated (no adjustment needed) x=x+0.02*(1:100) # with trend kendall_Z_adjusted(x) # ar(1) data set.seed(457298) xx=stats::arima.sim(list(ar=0.8),100) # autocorrelated, needs adjusting kendall_Z_adjusted(xx) # P-value adjusted is much less significant
ratio of actual to effective sample sizes for possibly autocorrelated time series
sample_size_ratio(x, ...)
sample_size_ratio(x, ...)
x |
numeric, a time series |
... |
optional parameters for acf() |
sample size ratio (a number)
Ken Butler, [email protected]
set.seed(457298) xx=stats::arima.sim(list(ar=0.8),100) # posoitively autocorrelated, sample size ratio > 1 sample_size_ratio(xx)
set.seed(457298) xx=stats::arima.sim(list(ar=0.8),100) # posoitively autocorrelated, sample size ratio > 1 sample_size_ratio(xx)
display calculations for sum in adjustment for autocorrelation (mainly for debugging)
sum_df(x, ...)
sum_df(x, ...)
x |
numeric, a time series |
... |
optional arguments for acf |
data frame showing terms in sum
Ken Butler, [email protected]
set.seed(457298) xx=stats::arima.sim(list(ar=0.8),100) # posoitively autocorrelated, sample size ratio > 1 sum_df(xx)
set.seed(457298) xx=stats::arima.sim(list(ar=0.8),100) # posoitively autocorrelated, sample size ratio > 1 sum_df(xx)
Theil-Sen slope with time
theil_sen_slope(y, x = 1:length(y))
theil_sen_slope(y, x = 1:length(y))
y |
numeric, a time series |
x |
numeric, the time points of the time series (optional, defaults to 1, 2, ...) |
the Theil-Sen slope, a number
Ken Butler, [email protected]
theil_sen_slope(c(2,3,5,10)) theil_sen_slope(y = c(2,3,5,10), x = 1:4) theil_sen_slope(y = c(2,3,5,10), x = c(1, 2, 3, 5))
theil_sen_slope(c(2,3,5,10)) theil_sen_slope(y = c(2,3,5,10), x = 1:4) theil_sen_slope(y = c(2,3,5,10), x = c(1, 2, 3, 5))
plot time series with smooth trend
ts_plot(x, time = 1:length(x))
ts_plot(x, time = 1:length(x))
x |
numeric, a time series |
time |
numeric, the time points of the time series (default '1:n' where 'n' is length of series) |
a ggplot plot
Ken Butler, [email protected]
set.seed(457299) x=rnorm(100) # uncorrelated x=x+0.02*(1:100) # with trend ts_plot(x)
set.seed(457299) x=rnorm(100) # uncorrelated x=x+0.02*(1:100) # with trend ts_plot(x)
Variance of Kendall correlation S statistic under null hypothesis of no trend and assuming independence
var_kendall_S(x)
var_kendall_S(x)
x |
numeric, a time series (only its length is used) |
the variance (a number)
Ken Butler, [email protected]
var_kendall_S(rnorm(100))
var_kendall_S(rnorm(100))