Title: | Pattern Causality Algorithm |
---|---|
Description: | A comprehensive package for detecting and analyzing causal relationships in complex systems using pattern-based approaches. Key features include state space reconstruction, pattern identification, and causality strength evaluation. |
Authors: | Stavros Stavroglou [aut] |
Maintainer: | Hui Wang <[email protected]> |
License: | GPL-3 | file LICENSE |
Version: | 0.2.1 |
Built: | 2025-02-15 12:58:50 UTC |
Source: | https://github.com/skstavroglou/pattern_causality |
Raw rodent and rainfall data collected from the Las Chinchillas National Reserve near Illapel, Coquimbo Region of Chile. This dataset provides ecological time series for studying species interactions and environmental effects.
AUCO
AUCO
A data frame with rodent and rainfall data.
Illapel Ecological Dataset
Las Chinchillas National Reserve Research Station
data(AUCO) head(AUCO) summary(AUCO)
data(AUCO) head(AUCO) summary(AUCO)
A comprehensive time series dataset containing various climate indices used for pattern causality analysis. This dataset includes multiple climate indicators measured over time.
climate_indices
climate_indices
A data frame with 100 rows and 5 columns:
Date; Date of the measurement
Numeric; Arctic Oscillation index
Numeric; Antarctic Oscillation index
Numeric; North Atlantic Oscillation index
Numeric; Pacific/North American index
Climate Indices Dataset
https://www.cpc.ncep.noaa.gov/
data(climate_indices) head(climate_indices) summary(climate_indices)
data(climate_indices) head(climate_indices) summary(climate_indices)
A generic interface for computing distances between observations using either built-in or custom distance metrics.
distanceMetric(x, method = "euclidean", ...) ## Default S3 method: distanceMetric(x, method = "euclidean", ...) ## S3 method for class 'custom' distanceMetric(x, method, ...)
distanceMetric(x, method = "euclidean", ...) ## Default S3 method: distanceMetric(x, method = "euclidean", ...) ## S3 method for class 'custom' distanceMetric(x, method, ...)
x |
Input data matrix or vector |
method |
Custom function to compute distances |
... |
Additional arguments passed to methods |
Generic Interface for Distance Metrics
A distance object or matrix containing pairwise distances
distanceMetric(default)
: Default method using stats::dist
distanceMetric(custom)
: Custom distance metric implementation
## Not run: # Using default method x <- matrix(rnorm(100), ncol=2) d1 <- distanceMetric(x, "euclidean") # Using custom method custom_dist <- function(x) as.dist(crossprod(x)) d2 <- distanceMetric(x, method=custom_dist) ## End(Not run)
## Not run: # Using default method x <- matrix(rnorm(100), ncol=2) d1 <- distanceMetric(x, "euclidean") # Using custom method custom_dist <- function(x) as.dist(crossprod(x)) d2 <- distanceMetric(x, method=custom_dist) ## End(Not run)
A comprehensive dataset containing daily stock prices for 29 companies listed in the Dow Jones Industrial Average (DJIA). The dataset includes opening, closing, high, and low prices for each stock.
DJS
DJS
A data frame with daily stock prices for 29 companies.
Dow Jones Stock Price Dataset
Yahoo Finance
data(DJS) head(DJS) summary(DJS)
data(DJS) head(DJS) summary(DJS)
Searches for the optimal embedding dimension (E) and time delay (tau) to maximize the accuracy of causality predictions in a dataset. This function implements a grid search approach to evaluate different parameter combinations.
optimalParametersSearch( Emax, tauMax, metric = "euclidean", distance_fn = NULL, state_space_fn = NULL, dataset, h = 0, weighted = FALSE, relative = TRUE, verbose = FALSE )
optimalParametersSearch( Emax, tauMax, metric = "euclidean", distance_fn = NULL, state_space_fn = NULL, dataset, h = 0, weighted = FALSE, relative = TRUE, verbose = FALSE )
Emax |
Positive integer > 2; maximum embedding dimension to test |
tauMax |
Positive integer; maximum time delay to test |
metric |
Character string; distance metric for causality analysis ('euclidean', 'manhattan', 'maximum'). Defaults to "euclidean". Ignored if |
distance_fn |
Optional custom distance function; takes two numeric vectors as input and returns a numeric distance. (default: NULL) |
state_space_fn |
Optional custom function for state space reconstruction; takes a numeric vector and parameters E and tau as input and returns a reconstructed state space. (default: NULL) |
dataset |
Numeric matrix; each column represents a time series. |
h |
Positive integer; prediction horizon. |
weighted |
Logical; if TRUE, weighted causality analysis is performed. |
relative |
Logical; if TRUE calculates relative changes ((new-old)/old), if FALSE calculates absolute changes (new-old) in signature space. Default is TRUE. |
verbose |
Logical; if TRUE, prints progress information. (default: FALSE) |
Search for Optimal Parameters in Pattern Causality Analysis
This function evaluates each combination of embedding dimension and time delay for their effectiveness in detecting different types of causality:
Total causality: Overall causal relationship strength
Positive causality: Direct positive influences
Negative causality: Direct negative influences
Dark causality: Complex or indirect causal relationships
A pc_params
object containing:
accuracy_summary: A data frame summarizing the accuracy for each parameter combination.
computation_time: The time taken for the analysis.
parameters: A list of the input parameters used.
data(climate_indices) dataset <- climate_indices[, -1] optimalParams <- optimalParametersSearch( Emax = 3, tauMax = 3, metric = "euclidean", dataset = dataset, h = 1, weighted = FALSE ) print(optimalParams)
data(climate_indices) dataset <- climate_indices[, -1] optimalParams <- optimalParametersSearch( Emax = 3, tauMax = 3, metric = "euclidean", dataset = dataset, h = 1, weighted = FALSE ) print(optimalParams)
Creates a pattern causality cross-validation object containing results
from repeated sampling analysis.
This function constructs an object of class pc_cv
to store the results
of cross-validation analysis.
pc_cv(samples = NULL, results = NULL, parameters = NULL)
pc_cv(samples = NULL, results = NULL, parameters = NULL)
samples |
Numeric vector of sample sizes used. |
results |
Matrix containing causality results for each sample. |
parameters |
List of analysis parameters. |
An object of class "pc_cv".
Creates a pattern causality effect object that contains information about
the received and exerted influences for different causality types.
This function constructs an object of class pc_effect
to store the results
of effect analysis.
pc_effect(positive = NULL, negative = NULL, dark = NULL, items = NULL)
pc_effect(positive = NULL, negative = NULL, dark = NULL, items = NULL)
positive |
Data frame containing positive causality effects. |
negative |
Data frame containing negative causality effects. |
dark |
Data frame containing dark causality effects. |
items |
Names of items in the analysis. |
An object of class "pc_effect".
Creates a pattern causality matrix object.
This function constructs an object of class pc_matrix
containing the positive,
negative, and dark causality matrices, along with item names.
pc_matrix( positive = NULL, negative = NULL, dark = NULL, items = NULL, verbose = TRUE )
pc_matrix( positive = NULL, negative = NULL, dark = NULL, items = NULL, verbose = TRUE )
positive |
Positive causality matrix. |
negative |
Negative causality matrix. |
dark |
Dark causality matrix. |
items |
Names of items in the matrices. |
verbose |
Logical, whether to print progress information. |
An object of class "pc_matrix".
data(climate_indices) dataset <- climate_indices[, -1] pc_matrix_obj <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = FALSE) print(pc_matrix_obj)
data(climate_indices) dataset <- climate_indices[, -1] pc_matrix_obj <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = FALSE) print(pc_matrix_obj)
Creates an object containing parameter optimization results for pattern causality analysis
pc_params(accuracy_summary, computation_time, parameters)
pc_params(accuracy_summary, computation_time, parameters)
accuracy_summary |
Data frame containing accuracy results for different parameter combinations |
computation_time |
Time taken for optimization |
parameters |
List of optimization parameters |
Pattern Causality Parameter Optimization Results
An object of class "pc_params"
Evaluates the causality prediction accuracy across multiple time series within a dataset using the PC Mk. II Light method. This function analyzes pairwise causality relationships and computes different types of causality measures.
pcAccuracy( dataset, E, tau, metric = "euclidean", h, weighted, distance_fn = NULL, state_space_fn = NULL, relative = TRUE, verbose = FALSE )
pcAccuracy( dataset, E, tau, metric = "euclidean", h, weighted, distance_fn = NULL, state_space_fn = NULL, relative = TRUE, verbose = FALSE )
dataset |
A matrix or data frame where each column represents a time series |
E |
Integer; embedding dimension for state space reconstruction (E > 1) |
tau |
Integer; time delay for state space reconstruction (tau > 0) |
metric |
Character; distance metric to use, one of "euclidean", "manhattan", or "maximum" |
h |
Integer; prediction horizon, indicating forecast distance (h >= 0) |
weighted |
Logical; whether to use weighted approach in calculating causality strengths |
distance_fn |
Optional custom distance function for computing distances (default: NULL) |
state_space_fn |
Optional custom function for state space reconstruction (default: NULL) |
relative |
Logical; if TRUE calculates relative changes ((new-old)/old), if FALSE calculates absolute changes (new-old) in signature space. Default is TRUE. |
verbose |
Logical; whether to display progress information (default: FALSE) |
Calculate Pattern Causality Accuracy
An object of class "pc_accuracy" containing:
parameters: List of input parameters (E, tau, metric, h, weighted)
total: Mean total causality across all pairs
positive: Mean positive causality across all pairs
negative: Mean negative causality across all pairs
dark: Mean dark causality across all pairs
matrices: Raw causality matrices for each type
pcMatrix
for analyzing individual causality matrices
pcLightweight
for pairwise causality analysis
data(climate_indices) data <- climate_indices[, -1] results <- pcAccuracy(dataset = data, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = TRUE) print(results)
data(climate_indices) data <- climate_indices[, -1] results <- pcAccuracy(dataset = data, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = TRUE) print(results)
Analyzes pattern causality relationships between multiple time series in X and multiple time series in Y by computing pairwise causality measures and organizing them into a matrix.
pcCrossMatrix( X, Y, E, tau, metric = "euclidean", h, weighted = TRUE, distance_fn = NULL, state_space_fn = NULL, relative = TRUE, verbose = FALSE, n_cores = 1 )
pcCrossMatrix( X, Y, E, tau, metric = "euclidean", h, weighted = TRUE, distance_fn = NULL, state_space_fn = NULL, relative = TRUE, verbose = FALSE, n_cores = 1 )
X |
Matrix or data frame of time series for the cause |
Y |
Matrix or data frame of time series for the effect |
E |
Integer; embedding dimension |
tau |
Integer; time delay |
metric |
Character; distance metric ("euclidean", "manhattan", "maximum") |
h |
Integer; prediction horizon |
weighted |
Logical; whether to use weighted causality |
distance_fn |
Optional custom distance function |
state_space_fn |
Optional custom state space reconstruction function |
relative |
Logical; if TRUE calculates relative changes ((new-old)/old), if FALSE calculates absolute changes (new-old) in signature space. Default is TRUE. |
verbose |
Logical; whether to print progress |
n_cores |
Integer; number of cores for parallel computation |
Compute Cross Pattern Causality Matrix Analysis
The function performs these key steps:
Validates input data and parameters
Computes pairwise causality measures between X and Y
Organizes results into a causality matrix
Provides summary statistics for each causality type
A pc_matrix object containing causality matrices
vars: Vector autoregression analysis
tseries: Time series analysis tools
forecast: Time series forecasting methods
Evaluates the robustness of pattern causality measures through repeated sampling analysis. This function performs cross-validation by analyzing multiple subsets of the data to assess the stability of causality relationships.
pcCrossValidation( X, Y, E, tau, metric = "euclidean", h, weighted, distance_fn = NULL, state_space_fn = NULL, numberset, random = TRUE, bootstrap = 1, verbose = FALSE, n_cores = 1, relative = TRUE )
pcCrossValidation( X, Y, E, tau, metric = "euclidean", h, weighted, distance_fn = NULL, state_space_fn = NULL, numberset, random = TRUE, bootstrap = 1, verbose = FALSE, n_cores = 1, relative = TRUE )
X |
Numeric vector representing the first time series. |
Y |
Numeric vector representing the second time series. |
E |
Integer specifying the embedding dimension. |
tau |
Integer specifying the time delay. |
metric |
Character string specifying the distance metric to use. |
h |
Integer specifying the prediction horizon. |
weighted |
Logical indicating whether to use weighted calculations. |
distance_fn |
Optional custom distance function. |
state_space_fn |
Optional custom state space function. |
numberset |
Numeric vector of sample sizes to analyze. |
random |
Logical indicating whether to use random sampling (default: TRUE). |
bootstrap |
Integer specifying the number of bootstrap iterations (default: 1). |
verbose |
Logical indicating whether to display progress messages. |
n_cores |
Integer specifying the number of cores to use for parallel computation (default: 1). |
relative |
Logical; if TRUE calculates relative changes ((new-old)/old), if FALSE calculates absolute changes (new-old) in signature space. Default is TRUE. |
Perform Pattern Causality Cross-Validation Analysis
The function implements these key steps:
Validates input parameters and data
Performs stratified sampling of time series data
When random=TRUE and bootstrap>1, performs bootstrap sampling
Computes pattern causality measures for each sample
Aggregates results across all samples
When bootstrap sampling is enabled (random=TRUE and bootstrap>1), the function returns statistics including mean, 5% quantile, 95% quantile, and median for each sample size.
A pc_cv object containing:
samples: Vector of sample sizes used
results: Array of causality results
parameters: List of analysis parameters
The results array structure depends on the bootstrap parameter:
If bootstrap>1: A three-dimensional array where first dimension represents sample sizes, second dimension contains statistics (mean, quantiles, median), and third dimension represents causality types (positive, negative, dark)
If bootstrap=1: A three-dimensional array where first dimension represents sample sizes, second dimension contains single values, and third dimension represents causality types (positive, negative, dark)
plot.pc_cv
for visualizing cross-validation results
print.pc_cv
for printing cross-validation results
summary.pc_cv
for summarizing cross-validation results
data(climate_indices) X <- climate_indices$AO Y <- climate_indices$AAO # Basic cross-validation cv_result <- pcCrossValidation( X, Y, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = FALSE, numberset = c(100, 200, 300) ) # Cross-validation with bootstrap cv_result_boot <- pcCrossValidation( X, Y, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = FALSE, numberset = c(100, 200, 300), random = TRUE, bootstrap = 100 )
data(climate_indices) X <- climate_indices$AO Y <- climate_indices$AAO # Basic cross-validation cv_result <- pcCrossValidation( X, Y, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = FALSE, numberset = c(100, 200, 300) ) # Cross-validation with bootstrap cv_result_boot <- pcCrossValidation( X, Y, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = FALSE, numberset = c(100, 200, 300), random = TRUE, bootstrap = 100 )
Analyzes pattern causality matrices to compute and summarize the directional effects of different causality types (positive, negative, dark) between system components.
pcEffect(pcmatrix, verbose = FALSE)
pcEffect(pcmatrix, verbose = FALSE)
pcmatrix |
An object of class "pc_matrix" containing causality matrices |
verbose |
Logical; whether to display computation progress (default: FALSE) |
Calculate Pattern Causality Effect Analysis
The function performs these key steps:
Processes raw causality matrices
Computes received and exerted influence for each component
Calculates net causality effect (difference between received and exerted)
Normalizes results to percentage scale
An object of class "pc_effect" containing:
positive: Data frame of positive causality effects
negative: Data frame of negative causality effects
dark: Data frame of dark causality effects
items: Vector of component names
summary: Summary statistics for each causality type
vars: Vector autoregression for multivariate time series
lmtest: Testing linear regression models
causality: Causality testing and modeling
pcMatrix
for generating causality matrices
plot.pc_effect
for visualizing causality effects
data(climate_indices) dataset <- climate_indices[, -1] pcmatrix <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE) effects <- pcEffect(pcmatrix) print(effects) plot(effects)
data(climate_indices) dataset <- climate_indices[, -1] pcmatrix <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE) effects <- pcEffect(pcmatrix) print(effects) plot(effects)
Implements an advanced pattern causality algorithm to explore the causal relationships between two time series datasets. This function provides comprehensive analysis of causality patterns, including state space reconstruction, pattern identification, and causality strength evaluation.
pcFullDetails( X, Y, E, tau, h, weighted, metric = "euclidean", distance_fn = NULL, state_space_fn = NULL, relative = TRUE, verbose = FALSE )
pcFullDetails( X, Y, E, tau, h, weighted, metric = "euclidean", distance_fn = NULL, state_space_fn = NULL, relative = TRUE, verbose = FALSE )
X |
Numeric vector; the first time series data |
Y |
Numeric vector; the second time series data |
E |
Integer; embedding dimension for state space reconstruction |
tau |
Integer; time delay between data points |
h |
Integer; prediction horizon for causality analysis |
weighted |
Logical; whether to weight causality strength |
metric |
Character; distance metric ('euclidean', 'manhattan', or 'maximum') |
distance_fn |
Optional custom distance function for computing distances (default: NULL) |
state_space_fn |
Optional custom function for state space reconstruction (default: NULL) |
relative |
Logical; if TRUE calculates relative changes ((new-old)/old), if FALSE calculates absolute changes (new-old) in signature space. Default is TRUE. |
verbose |
Logical; if TRUE, prints computation progress (default: FALSE) |
Calculate Full Details Pattern Causality Analysis
The function implements these key steps:
State Space Reconstruction: Creates shadow attractors using embedding
Pattern Analysis: Converts time series into signature and pattern spaces
Nearest Neighbor Analysis: Identifies and analyzes local dynamics
Causality Evaluation: Computes predicted and actual causality matrices
Results Validation: Provides detailed diagnostics and quality metrics
A pc_full_details object containing:
backtest_time: Time points used for backtesting
valid_time: Valid time points for analysis
causality_real: Real causality spectrum
causality_pred: Predicted causality spectrum
state_spaces: State space reconstructions
neighbors: Nearest neighbor information
patterns: Pattern and signature information
matrices: Causality matrices
predictions: Predicted and actual values
weighted: A logical indicating if weighted calculations were used
E: Embedding dimension used for the analysis
Implements a computationally efficient version of the Pattern Causality Model Mk. II for analyzing causal interactions between two time series. This function uses pattern and signature spaces to assess causality through reconstructed state spaces and hashed pattern analysis.
pcLightweight( X, Y, E, tau, h, weighted, metric = "euclidean", distance_fn = NULL, state_space_fn = NULL, relative = TRUE, verbose = FALSE )
pcLightweight( X, Y, E, tau, h, weighted, metric = "euclidean", distance_fn = NULL, state_space_fn = NULL, relative = TRUE, verbose = FALSE )
X |
A numeric vector representing the first time series |
Y |
A numeric vector representing the second time series |
E |
Integer; embedding dimension for state space reconstruction (E > 1) |
tau |
Integer; time delay for state space reconstruction (tau > 0) |
h |
Integer; prediction horizon for future projections (h >= 0) |
weighted |
Logical; whether to use weighted causality strength calculations |
metric |
Character string specifying the distance metric; one of "euclidean", "manhattan", or "maximum" |
distance_fn |
Custom distance function for state space reconstruction |
state_space_fn |
Custom function for state space transformation |
relative |
Logical; if TRUE calculates relative changes ((new-old)/old), if FALSE calculates absolute changes (new-old) in signature space. Default is TRUE. |
verbose |
Logical; whether to display progress information (default: FALSE) |
Calculate Pattern Causality Using Lightweight Algorithm
The function implements these key steps:
State space reconstruction using embedding parameters
Pattern and signature space transformation
Nearest neighbor analysis in reconstructed spaces
Causality strength calculation using prediction accuracy
Classification of causality types (positive/negative/dark)
An object of class "pc_fit" containing:
total: Total causality strength (0-1)
positive: Proportion of positive causality (0-1)
negative: Proportion of negative causality (0-1)
dark: Proportion of dark causality (0-1)
pcFullDetails
for detailed analysis
pcMatrix
for analyzing multiple time series
data(climate_indices) X <- climate_indices$AO Y <- climate_indices$AAO result <- pcLightweight(X, Y, E = 3, tau = 1, metric = "euclidean", h = 2, weighted = TRUE, verbose = FALSE) print(result) summary(result) plot(result)
data(climate_indices) X <- climate_indices$AO Y <- climate_indices$AAO result <- pcLightweight(X, Y, E = 3, tau = 1, metric = "euclidean", h = 2, weighted = TRUE, verbose = FALSE) print(result) summary(result) plot(result)
Analyzes pattern causality relationships between multiple time series by computing pairwise causality measures and organizing them into matrices.
pcMatrix( dataset, E, tau, metric = "euclidean", h, weighted = TRUE, distance_fn = NULL, state_space_fn = NULL, relative = TRUE, verbose = FALSE, n_cores = 1 )
pcMatrix( dataset, E, tau, metric = "euclidean", h, weighted = TRUE, distance_fn = NULL, state_space_fn = NULL, relative = TRUE, verbose = FALSE, n_cores = 1 )
dataset |
Matrix or data frame of time series |
E |
Integer; embedding dimension |
tau |
Integer; time delay |
metric |
Character; distance metric ("euclidean", "manhattan", "maximum") |
h |
Integer; prediction horizon |
weighted |
Logical; whether to use weighted causality |
distance_fn |
Optional custom distance function |
state_space_fn |
Optional custom state space reconstruction function |
relative |
Logical; if TRUE calculates relative changes ((new-old)/old), if FALSE calculates absolute changes (new-old) in signature space. Default is TRUE. |
verbose |
Logical; whether to print progress |
n_cores |
Integer; number of cores for parallel computation |
Compute Pattern Causality Matrix Analysis
The function performs these key steps:
Validates input data and parameters
Computes pairwise causality measures
Organizes results into causality matrices
Provides summary statistics for each causality type
A pc_matrix object containing causality matrices
vars: Vector autoregression analysis
tseries: Time series analysis tools
forecast: Time series forecasting methods
Visualizes the positive, negative and dark causality components over time
plot_causality(x, type, ...)
plot_causality(x, type, ...)
x |
An object containing pattern causality results |
type |
The type of causality to plot ("total", "positive", "negative", or "dark") |
... |
Additional arguments passed to plotting functions |
Invisibly returns the ggplot object
Visualizes the positive, negative and dark causality components over time
## S3 method for class 'pc_full_details' plot_causality(x, type, ...)
## S3 method for class 'pc_full_details' plot_causality(x, type, ...)
x |
A pc_full_details object |
type |
The type of causality to plot ("total", "positive", "negative", or "dark") |
... |
Additional arguments passed to plotting functions |
Invisibly returns the ggplot object
Visualizes the positive, negative, and dark causality components as a barplot.
This function takes a pc_fit
object and generates a barplot showing the
strength of each causality component.
plot_components(x, ...)
plot_components(x, ...)
x |
An object containing pattern causality results, typically a |
... |
Additional arguments passed to the underlying plotting functions. |
NULL invisibly.
data(climate_indices) X <- climate_indices$AO Y <- climate_indices$AAO pc_result <- pcLightweight(X, Y, E = 3, tau = 2, metric = "euclidean", h = 1, weighted = TRUE) plot_components(pc_result)
data(climate_indices) X <- climate_indices$AO Y <- climate_indices$AAO pc_result <- pcLightweight(X, Y, E = 3, tau = 2, metric = "euclidean", h = 1, weighted = TRUE) plot_components(pc_result)
Visualizes the positive, negative, and dark causality components as a barplot for a pc_fit
object.
This function generates a barplot showing the strength of each causality component.
## S3 method for class 'pc_fit' plot_components(x, ...)
## S3 method for class 'pc_fit' plot_components(x, ...)
x |
A |
... |
Additional arguments passed to the underlying plotting functions. |
NULL.
Visualizes the total pattern causality strength as a barplot.
This function takes a pc_fit
object and generates a barplot showing the
overall causality strength.
plot_total(x, ...)
plot_total(x, ...)
x |
An object containing pattern causality results, typically a |
... |
Additional arguments passed to the underlying plotting functions. |
NULL invisibly.
Stavroglou et al. (2020) doi:10.1073/pnas.1918269117
plot_components
for visualizing individual causality components.
data(climate_indices) X <- climate_indices$AO Y <- climate_indices$AAO pc_result <- pcLightweight(X, Y, E = 3, tau = 2, metric = "euclidean", h = 1, weighted = TRUE) plot_total(pc_result)
data(climate_indices) X <- climate_indices$AO Y <- climate_indices$AAO pc_result <- pcLightweight(X, Y, E = 3, tau = 2, metric = "euclidean", h = 1, weighted = TRUE) plot_total(pc_result)
Visualizes the total causality strength as a barplot for a pc_fit
object.
This function generates a barplot showing the total causality strength and its complement.
## S3 method for class 'pc_fit' plot_total(x, ...)
## S3 method for class 'pc_fit' plot_total(x, ...)
x |
A |
... |
Additional arguments passed to the underlying plotting functions. |
NULL.
Visualizes the pattern causality cross-validation results. This function generates a line plot showing the causality strengths for different sample sizes.
## S3 method for class 'pc_cv' plot(x, fr = FALSE, separate = FALSE, ...)
## S3 method for class 'pc_cv' plot(x, fr = FALSE, separate = FALSE, ...)
x |
A |
fr |
Boolean for frame display. |
separate |
Boolean for separate plots. |
... |
Additional arguments passed to the |
Invisibly returns the input object.
data(climate_indices) X <- climate_indices$AO Y <- climate_indices$AAO numbersets <- c(100, 150, 200) cv_results <- pcCrossValidation(X, Y, 3, 2, "euclidean", 1, FALSE, numberset = numbersets) plot(cv_results)
data(climate_indices) X <- climate_indices$AO Y <- climate_indices$AAO numbersets <- c(100, 150, 200) cv_results <- pcCrossValidation(X, Y, 3, 2, "euclidean", 1, FALSE, numberset = numbersets) plot(cv_results)
Generates a plot to visualize the effects of positive, negative, or dark causality. Displays the influence exerted versus influence received for each item. This function generates a scatter plot showing the influence exerted versus influence received for each item, colored by the difference between exerted and received influence.
## S3 method for class 'pc_effect' plot( x, status = "positive", add_label = TRUE, point_size = 3, label_size = 3, ... )
## S3 method for class 'pc_effect' plot( x, status = "positive", add_label = TRUE, point_size = 3, label_size = 3, ... )
x |
A |
status |
Status of the effect to plot ("positive", "negative", or "dark"). |
add_label |
Logical, whether to add labels to the plot. |
point_size |
Numeric value for point size (default: 3). |
label_size |
Numeric value for label text size (default: 3). |
... |
Additional arguments passed to plotting functions. |
Invisibly returns the ggplot object.
data(climate_indices) dataset <- climate_indices[, -1] pc_matrix_obj <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = FALSE) effects <- pcEffect(pc_matrix_obj) plot(effects, status = "positive")
data(climate_indices) dataset <- climate_indices[, -1] pc_matrix_obj <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = FALSE) effects <- pcEffect(pc_matrix_obj) plot(effects, status = "positive")
Generates a combined plot of total causality and causality components for a pc_fit
object.
This function combines the visualizations from plot_total
and plot_components
into a single plot.
## S3 method for class 'pc_fit' plot(x, ...)
## S3 method for class 'pc_fit' plot(x, ...)
x |
A |
... |
Additional arguments passed to the underlying plotting functions. |
NULL invisibly.
Creates a heatmap visualization of the pattern causality matrix for positive,
negative, or dark causality relationships.
This function generates a heatmap using ggplot2
to visualize the specified
causality matrix.
## S3 method for class 'pc_matrix' plot( x, status, width = 0.85, height = 0.75, radius = grid::unit(3, "pt"), alpha = 0.53, show_text = FALSE, show_legend_title = FALSE, ... )
## S3 method for class 'pc_matrix' plot( x, status, width = 0.85, height = 0.75, radius = grid::unit(3, "pt"), alpha = 0.53, show_text = FALSE, show_legend_title = FALSE, ... )
x |
A |
status |
The type of causality to plot ("positive", "negative", or "dark"). |
width |
Numeric value specifying the width of the bars (default: 0.85). |
height |
Numeric value specifying the height of the bars (default: 0.75). |
radius |
Grid unit specifying the corner radius of the bars. |
alpha |
Numeric value specifying the transparency (default: 0.53). |
show_text |
Logical, whether to show numerical values on the plot. |
show_legend_title |
Logical, whether to display the legend title. |
... |
Additional arguments passed to plotting functions. |
A ggplot object invisibly.
Stavroglou et al. (2020) doi:10.1073/pnas.1918269117
data(climate_indices) dataset <- climate_indices[, -1] pc_matrix_obj <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = FALSE) plot(pc_matrix_obj, status = "positive")
data(climate_indices) dataset <- climate_indices[, -1] pc_matrix_obj <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = FALSE) plot(pc_matrix_obj, status = "positive")
Visualizes the state space reconstruction in 3D. This function generates a 3D scatter plot of the reconstructed state space.
## S3 method for class 'pc_state' plot(x, style = 2, verbose = FALSE, ...)
## S3 method for class 'pc_state' plot(x, style = 2, verbose = FALSE, ...)
x |
A |
style |
Integer; plot style (1 or 2). |
verbose |
Logical; whether to print verbose output. |
... |
Additional arguments passed to the plotting functions. |
Invisibly returns the input object.
Print Method for Pattern Causality Accuracy Results
## S3 method for class 'pc_accuracy' print(x, verbose = FALSE, ...)
## S3 method for class 'pc_accuracy' print(x, verbose = FALSE, ...)
x |
A pc_accuracy object |
verbose |
Logical; whether to display detailed information (default: FALSE) |
... |
Additional arguments passed to print |
Invisibly returns the input object
Prints the pattern causality cross-validation results. This function displays the parameters used for cross-validation, the sample sizes, and the summary statistics.
## S3 method for class 'pc_cv' print(x, ...)
## S3 method for class 'pc_cv' print(x, ...)
x |
A |
... |
Additional arguments passed to the |
Invisibly returns the input object.
data(climate_indices) X <- climate_indices$AO Y <- climate_indices$AAO numberset <- c(100, 150, 200) cv_results <- pcCrossValidation(X, Y, 3, 2, "euclidean", 1, FALSE, numberset = numberset) print(cv_results)
data(climate_indices) X <- climate_indices$AO Y <- climate_indices$AAO numberset <- c(100, 150, 200) cv_results <- pcCrossValidation(X, Y, 3, 2, "euclidean", 1, FALSE, numberset = numberset) print(cv_results)
Prints the pattern causality effect analysis results. This function displays the received and exerted influences for each item for positive, negative, and dark causality types.
## S3 method for class 'pc_effect' print(x, ...)
## S3 method for class 'pc_effect' print(x, ...)
x |
A |
... |
Additional arguments passed to the |
Invisibly returns the input object.
data(climate_indices) dataset <- climate_indices[, -1] pc_matrix_obj <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = FALSE) effects <- pcEffect(pc_matrix_obj) print(effects)
data(climate_indices) dataset <- climate_indices[, -1] pc_matrix_obj <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = FALSE) effects <- pcEffect(pc_matrix_obj) print(effects)
Prints the pattern causality analysis results from a pc_fit
object.
This function displays the total, positive, negative, and dark causality strengths.
## S3 method for class 'pc_fit' print(x, ...)
## S3 method for class 'pc_fit' print(x, ...)
x |
A |
... |
Additional arguments passed to the |
Invisibly returns the input object.
Prints the pattern causality matrix object. This function displays the specified causality matrix (or all matrices) with a preview of the first 5 rows and columns.
## S3 method for class 'pc_matrix' print(x, type = "all", ...)
## S3 method for class 'pc_matrix' print(x, type = "all", ...)
x |
A |
type |
The type of matrix to print ("all" or "positive", "negative", "dark"). |
... |
Additional arguments passed to the |
Invisibly returns the input object.
data(climate_indices) dataset <- climate_indices[, -1] pc_matrix_obj <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = FALSE) print(pc_matrix_obj, type = "positive")
data(climate_indices) dataset <- climate_indices[, -1] pc_matrix_obj <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = FALSE) print(pc_matrix_obj, type = "positive")
Print Method for Pattern Causality Parameter Results
## S3 method for class 'pc_params' print(x, verbose = FALSE, ...)
## S3 method for class 'pc_params' print(x, verbose = FALSE, ...)
x |
A pc_params object |
verbose |
Logical; whether to display detailed information |
... |
Additional arguments passed to print |
Invisibly returns the input object
Prints the state space reconstruction results. This function displays the parameters used for state space reconstruction and a preview of the reconstructed points.
## S3 method for class 'pc_state' print(x, ...)
## S3 method for class 'pc_state' print(x, ...)
x |
A |
... |
Additional arguments passed to the |
Invisibly returns the input object.
Print Method for Pattern Causality Accuracy Summary
## S3 method for class 'summary.pc_accuracy' print(x, ...)
## S3 method for class 'summary.pc_accuracy' print(x, ...)
x |
A summary.pc_accuracy object |
... |
Additional arguments passed to print |
Invisibly returns the input object
Reconstructs the state space of a time series using delay embedding, creating a matrix where each row represents a point in the reconstructed space.
stateSpace(ts, E, tau, verbose = FALSE)
stateSpace(ts, E, tau, verbose = FALSE)
ts |
Numeric vector; time series data |
E |
Integer; embedding dimension (E > 1) |
tau |
Integer; time delay (tau > 0) |
verbose |
Logical; whether to display progress information |
State Space Reconstruction Analysis
The function implements Takens' embedding theorem to reconstruct state space:
Creates delay vectors using specified embedding dimension (E)
Applies time delay (tau) between consecutive elements
Handles boundary conditions and missing values
An object of class "pc_state" containing:
matrix: The reconstructed state space matrix
parameters: List of reconstruction parameters
original: Original time series data
nonlinearTseries: Nonlinear time series analysis
tseriesChaos: Chaos theory analysis tools
fractal: Fractal analysis methods
ts <- c(1:100) result <- stateSpace(ts, E = 3, tau = 2) plot(result)
ts <- c(1:100) result <- stateSpace(ts, E = 3, tau = 2) plot(result)
A generic interface for reconstructing state spaces from time series data using either built-in or custom methods.
stateSpaceMethod(x, E, tau, ...) ## Default S3 method: stateSpaceMethod(x, E, tau, ...) ## S3 method for class 'custom' stateSpaceMethod(x, E, tau, method, ...)
stateSpaceMethod(x, E, tau, ...) ## Default S3 method: stateSpaceMethod(x, E, tau, ...) ## S3 method for class 'custom' stateSpaceMethod(x, E, tau, method, ...)
x |
Input time series |
E |
Embedding dimension (positive integer) |
tau |
Time delay (positive integer) |
... |
Additional arguments passed to methods |
method |
Custom function for state space reconstruction |
Generic Interface for State Space Reconstruction
A list containing the reconstructed state space components
stateSpaceMethod(default)
: Default state space reconstruction
stateSpaceMethod(custom)
: Custom state space reconstruction
## Not run: # Using default method x <- rnorm(100) s1 <- stateSpaceMethod(x, E=3, tau=2) # Using custom method custom_space <- function(x, E, tau) { list(matrix=embed(x, E)) } s2 <- stateSpaceMethod(x, E=3, tau=2, method=custom_space) ## End(Not run)
## Not run: # Using default method x <- rnorm(100) s1 <- stateSpaceMethod(x, E=3, tau=2) # Using custom method custom_space <- function(x, E, tau) { list(matrix=embed(x, E)) } s2 <- stateSpaceMethod(x, E=3, tau=2, method=custom_space) ## End(Not run)
Summary Method for Pattern Causality Accuracy Results
## S3 method for class 'pc_accuracy' summary(object, ...)
## S3 method for class 'pc_accuracy' summary(object, ...)
object |
A pc_accuracy object |
... |
Additional arguments passed to summary |
A summary object for pc_accuracy
Provides a summary of the pattern causality cross-validation results. This function calculates and displays summary statistics for the cross-validation results, including sample statistics, causality statistics, and convergence.
## S3 method for class 'pc_cv' summary(object, ...)
## S3 method for class 'pc_cv' summary(object, ...)
object |
A |
... |
Additional arguments passed to the |
Invisibly returns the input object.
data(climate_indices) X <- climate_indices$AO Y <- climate_indices$AAO numberset <- c(100, 150, 200) cv_results <- pcCrossValidation(X, Y, 3, 2, "euclidean", 1, FALSE, numberset = numberset) summary(cv_results)
data(climate_indices) X <- climate_indices$AO Y <- climate_indices$AAO numberset <- c(100, 150, 200) cv_results <- pcCrossValidation(X, Y, 3, 2, "euclidean", 1, FALSE, numberset = numberset) summary(cv_results)
Provides a summary of the pattern causality effect analysis results. This function displays the summary statistics for the effects, including the number of components and the strongest effects.
## S3 method for class 'pc_effect' summary(object, ...)
## S3 method for class 'pc_effect' summary(object, ...)
object |
A |
... |
Additional arguments passed to the |
Invisibly returns the input object.
data(climate_indices) dataset <- climate_indices[, -1] pc_matrix_obj <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = FALSE) effects <- pcEffect(pc_matrix_obj) summary(effects)
data(climate_indices) dataset <- climate_indices[, -1] pc_matrix_obj <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = FALSE) effects <- pcEffect(pc_matrix_obj) summary(effects)
Provides a summary of the pattern causality analysis results from a pc_fit
object.
This function displays a table of causality strengths for total, positive, negative, and dark components.
## S3 method for class 'pc_fit' summary(object, ...)
## S3 method for class 'pc_fit' summary(object, ...)
object |
A |
... |
Additional arguments passed to the |
Invisibly returns the input object.
Provides a summary of the pattern causality matrix object. This function calculates and displays descriptive statistics (mean, SD, min, max) for each causality matrix (positive, negative, dark).
## S3 method for class 'pc_matrix' summary(object, ...)
## S3 method for class 'pc_matrix' summary(object, ...)
object |
A |
... |
Additional arguments passed to the |
Invisibly returns the input object.
data(climate_indices) dataset <- climate_indices[, -1] pc_matrix_obj <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = FALSE) summary(pc_matrix_obj)
data(climate_indices) dataset <- climate_indices[, -1] pc_matrix_obj <- pcMatrix(dataset, E = 3, tau = 1, metric = "euclidean", h = 1, weighted = TRUE, verbose = FALSE) summary(pc_matrix_obj)
Summary Method for Pattern Causality Parameter Results
## S3 method for class 'pc_params' summary(object, ...)
## S3 method for class 'pc_params' summary(object, ...)
object |
A pc_params object |
... |
Additional arguments passed to summary |
A summary object for pc_params
Provides a summary of the state space reconstruction results. This function displays the dimensions, number of points, parameters, summary statistics for each dimension, and the number of missing values.
## S3 method for class 'pc_state' summary(object, ...)
## S3 method for class 'pc_state' summary(object, ...)
object |
A |
... |
Additional arguments passed to the |
Invisibly returns the input object.
Validates the Output Format from Custom Distance and State Space Functions to ensure compatibility with the package's internal processing.
validate_custom_fn_output(output, fn_name)
validate_custom_fn_output(output, fn_name)
output |
The output from a custom function to validate |
fn_name |
The name of the function type being validated ("distance_fn" or "state_space_fn") |
Validate Custom Function Output
Nothing. Throws an error if validation fails.
# Example 1: Validating custom distance function output custom_dist <- function(x) { # Create distance matrix dist_mat <- as.matrix(dist(x)) # Validate output validate_custom_fn_output(dist_mat, "distance_fn") return(dist_mat) } # Example 2: Validating custom state space function output custom_state_space <- function(x, E, tau) { # Create state space matrix n <- length(x) - (E-1)*tau state_mat <- matrix(nrow = n, ncol = E) for(i in 1:E) { state_mat[,i] <- x[1:n + (i-1)*tau] } # Create output list result <- list(matrix = state_mat, parameters = list(E = E, tau = tau)) # Validate output validate_custom_fn_output(result, "state_space_fn") return(result) } # Using the custom functions x <- sin(seq(0, 4*pi, length.out = 100)) dist_result <- custom_dist(x) space_result <- custom_state_space(x, E = 3, tau = 2)
# Example 1: Validating custom distance function output custom_dist <- function(x) { # Create distance matrix dist_mat <- as.matrix(dist(x)) # Validate output validate_custom_fn_output(dist_mat, "distance_fn") return(dist_mat) } # Example 2: Validating custom state space function output custom_state_space <- function(x, E, tau) { # Create state space matrix n <- length(x) - (E-1)*tau state_mat <- matrix(nrow = n, ncol = E) for(i in 1:E) { state_mat[,i] <- x[1:n + (i-1)*tau] } # Create output list result <- list(matrix = state_mat, parameters = list(E = E, tau = tau)) # Validate output validate_custom_fn_output(result, "state_space_fn") return(result) } # Using the custom functions x <- sin(seq(0, 4*pi, length.out = 100)) dist_result <- custom_dist(x) space_result <- custom_state_space(x, E = 3, tau = 2)