TimeHiVE provides efficient R functions for hierarchical moving-window analysis of coupled time series data. The toolkit implements:
- Parallel computation of Pearson and Mann-Kendall correlations
- Optimized O(n log n) implementations of statistical tests
- Customizable visualization of time-dependent relationships
- Statistical significance testing with adjustable thresholds
The software package here proposed allows to perform analyses on time series avoiding the arbitrary choice of the time window and allowing to appreciate the whole spectrum of possible results offered by this kind of statistical tools.
Figure 1: Different Moving Average vs Original Syntetic Time Series. Color scale on y-axis is meant only to match colors in Fig. 2
Figure 2: Representation of all the possible moving averages for the Original Syntetic Time Series, moving averages analyses represented in Fig. 1 are highlighted with comments on the results.
Figure 3: Representation of two Time Series positively correlated for short periods but negatively correlated for long periods. The series are built as:
TS1 = 40 + 2*sin(t/2) - t/20 - rand(-2/3, 2/3)
and TS2 = 15 + 2*sin(t/2) + t/7 - rand(-2/3, 2/3)
. The sine component creates short-term positive correlation, while the t/n
terms drive long-term negative correlation.
Figure 4: Here we show the Moving Correlation Analysis for the coupled Time Series represented in Fig. 4, the first row shows the results for Pearson’s correlation coefficient (Top Left) and relative p-values (Top Right), the second row shows the same analysis with MK’s correlation coefficients (Bottom Left) and relative p-values (Bottom Right). The inversion of the correlation between short and long period of analysis is quite clear.
FIRST ROW: Pearson’s correlation coefficient (Top Left) and relative p-values (Top Right). SECOND ROW: same analysis with MK’s correlation coefficientes (Bottom Left) and relative p-values (Bottom Right). The inversion of the correlation between short and long period of analysis is quite clear.
You can install the development version from GitHub with:
# install.packages("remotes")
remotes::install_github("Ouroboro/TimeHiVE")
library(TimeHiVE)
# Generate example data
set.seed(123)
series1 <- sin(seq(0, 4*pi, length.out = 200)) + rnorm(200, sd = 0.2)
series2 <- cos(seq(0, 4*pi, length.out = 200)) + rnorm(200, sd = 0.3)
# Perform analysis
results <- TH_coupled(
series1 = series1,
series2 = series2,
m = 2,
s = 6,
alpha = 0.05,
mode = "both"
)
# Visualize results
TH_plotc(results, mask = TRUE, mode = "both")
TH_coupled()
: Perform hierarchical moving-window analysisTH_plotc()
: Visualize analysis resultsTH_MK_Corr()
: Mann-Kendall correlation testTH_MK_Trend()
: Mann-Kendall trend test
For detailed documentation see:
?TH_coupled
?TH_plotc
?TH_MK_Corr
?TH_MK_Trend
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create your feature branch (
git checkout -b feature/your-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/your-feature
) - Open a Pull Request
This package is licensed under the GNU General Public License v3.0 (GPL-3.0). See the LICENSE file for details.
For questions or issues, please contact:
Vladimiro Andrea Boselli
Email: boselli.v@irea.cnr.it
GitHub: @Ouroboro