Learn R Programming

⚠️There's a newer version (0.2.1) of this package.Take me there.

Pattern Causality

Overview

The goal of patterncausality is to measure the causality in the complex system. The core of this algorithm is measure the strength of each causality status like positive, negative, and dark in the view of complex system, this method could be used for many different fields like financial market, ecosystem, medical diagnosis and so on.

This algorithm has a lot of advantages.

  • You can find the hidden pattern in the complex system.
  • You can measure the causality in different fields.
  • You can search for the best parameters for the complex system.

Installation

You can install the development version of patterncausality from GitHub with:

# install.packages("devtools")
devtools::install_github("skstavroglou/pattern_causality")

You can also install the package from CRAN with:

install.packages("patterncausality")

Example

Application in climate

We can import the existing data.

library(patterncausality)
data(climate)
head(climate)
#>         Date      AO    AAO   NAO   PNA
#> 1 1979-01-01 -2.2328 0.2088 -1.38 -0.69
#> 2 1979-02-01 -0.6967 0.3563 -0.67 -1.82
#> 3 1979-03-01 -0.8141 0.8992  0.78  0.38
#> 4 1979-04-01 -1.1568 0.6776 -1.71  0.09
#> 5 1979-05-01 -0.2501 0.7237 -1.03  1.35
#> 6 1979-06-01  0.9332 1.7000  1.60 -1.64

This dataset contains 4 time series of climate index, we could use the patterncausality in this dataset.

Then we need to determine the E and tao.

dataset <- climate[, -1] # remove the date column
parameter <- optimalParametersSearch(Emax = 5, tauMax = 5, metric = "euclidean", dataset = dataset)
Totalof which Positiveof which Negativeof which Dark
E=2tau=10.55436140.55194770.44743610.0006162144
E=2tau=20.57274140.57361000.42328280.0031071596
E=2tau=30.57118380.54690690.45132700.0017660870
E=3tau=10.33052960.34571690.24709290.4071902523
E=3tau=20.35000000.40371380.25475240.3415338782
E=3tau=30.35700930.36576380.26905360.3651826225

Of course, we can also change the distance style to calculate the distance matrix. Then according the combo that produces the highest percentages collectively, we can choose the best parameters here.

After the parameters are confirmed, we could calculate the pattern causality.

X <- climate$AO
Y <- climate$AAO
pc <- pcLightweight(X, Y, E = 3, tau = 2, metric = "euclidean", h = 1, weighted = TRUE, tpb=FALSE)
print(pc)
#>       total positive  negative     dark
#> 1 0.2841121 0.326087 0.2318841 0.442029

Then the percentage of each status will be showed below.

If we wonder the status in each time point, we can run the code.

X <- climate$AO
Y <- climate$AAO
detail <- pcFullDetails(X, Y, E = 2, tau = 1, metric = "euclidean", h = 3, weighted = TRUE)
predict_status <- detail$spectrumOfCausalityPredicted
real_status <- detail$spectrumOfCausalityReal

Then the status series will be saved in predict_status and real_status.

Conclusion

After calculating the causality, we can get the result here.

PairstotalpositivenegativedarkDataset
AAPL –> MSFT0.26986650.38812790.13698630.4748858stock
MSFT –> AAPL0.27598870.40758930.13883930.4535714stock
AO –> AAO0.28411210.3260870.23188410.442029climate
AAO –> AO0.28037380.36029410.26470590.375climate
AO –> P0.30841120.11920530.45033110.4304636AUCO
P –> AO0.33084110.33742330.25153370.4110429AUCO

About the authors

Stavros is lecturer in credit risk and fin-tech at the University of Edinburgh Business School and is the main creator for the algorithm of the pattern causality.

Athanasios is professor in econometrics and business statistics of Monash Business School and is the main author of the pattern causality.

Hui is MPhil student in econometrics and business statistics of Monash Business School and is the author and maintainer of the patterncausality package.

References

  • Stavroglou, S. K., Pantelous, A. A., Stanley, H. E., & Zuev, K. M. (2019). Hidden interactions in financial markets. Proceedings of the National Academy of Sciences, 116(22), 10646-10651.

  • Stavroglou, S. K., Pantelous, A. A., Stanley, H. E., & Zuev, K. M. (2020). Unveiling causal interactions in complex systems. Proceedings of the National Academy of Sciences, 117(14), 7599-7605.

  • Stavroglou, S. K., Ayyub, B. M., Kallinterakis, V., Pantelous, A. A., & Stanley, H. E. (2021). A novel causal risk‐based decision‐making methodology: The case of coronavirus. Risk Analysis, 41(5), 814-830.

Copy Link

Version

Install

install.packages('patterncausality')

Monthly Downloads

137

Version

0.1.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Hui Wang

Last Published

August 22nd, 2024

Functions in patterncausality (0.1.2)

predictionY

Predict Signature and Pattern Vectors
natureOfCausality

Evaluate the Nature of Causality in Dynamic Complex Systems
projectedNNsInfo

Projected Nearest Neighbors Information
stateSpace

Construct State Space Matrix from Time Series
stock

Stock index
projectedNNsInfo_Lite

Projected Nearest Neighbors Information (Lite Version)
signatureSpace

Create Signature Space from Embedded Matrix
distanceMatrix

Compute Distance Matrix for an Embedded Matrix
firstCausalityPoint

First Causality Point Function
firstCausalityPointCHECK

First Causality Point Check Function
distanceVector

Calculate Distances Between a Reference Point and Multiple Candidates
convertSignatureToValue

Convert Signature to Predicted Values
fillPCMatrix

Calculate and Record Causality Strengths
climate

Climate index
dataBank

Data Bank Initialization Function
convertSignatureToValueOutOfSample

Convert Out-of-Sample Signature to Predicted Values
pastNNsInfo_Lite

Finding Nearest Neighbors and Keeping their Topological Information (Lite Version)
pcAccuracy

PC Accuracy Evaluation Function
patternSpace

Create Pattern Space from Signature Matrix
patternHashing

Pattern Hashing Function
pastNNsInfo

Finding Nearest Neighbors and Keeping their Topological Information
metricDistance

Calculate Generalized Minkowski Distance Between Two Vectors
optimalParametersSearch

Optimal Parameters Search for Causality Analysis
pcFullDetails

Pattern Causality Mark II: Full Details
pcLightweight

Pattern Causality Lightweight Function
AUCO

A data from Illapel