Skip to content

Commit

Permalink
update for CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghui5801 committed Jan 9, 2025
1 parent f34a0a9 commit 639bd25
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 164 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Authors@R: c( person("Stavros", "Stavroglou", role = c("aut"),
email = "[email protected]",
comment = c(ORCID = "0009-0006-0095-0243")))
Maintainer: Hui Wang <[email protected]>
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. Compared to existing packages: 'vars' provides linear vector autoregression but lacks nonlinear pattern detection; 'nonlinearTseries' offers general nonlinear analysis tools but no specific causality measures; 'rEDM' focuses on empirical dynamic modeling without pattern recognition; 'tseriesChaos' implements chaos theory methods but not pattern-based causality; 'CausalImpact' implements Bayesian structural time series models; 'pcalg' focuses on graphical causal models. This package uniquely combines these approaches with novel pattern recognition techniques for robust causality detection.
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.
License: GPL-3 | file LICENSE
Depends: R (>= 4.1.0)
Imports:
Expand Down
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ S3method(summary,pc_neighbors)
S3method(summary,pc_params)
S3method(summary,pc_state)
export(distanceMetric)
export(natureOfCausality)
export(optimalParametersSearch)
export(patternSpace)
export(pcAccuracy)
export(pcCrossMatrix)
export(pcCrossValidation)
Expand All @@ -53,7 +51,6 @@ export(pc_params)
export(plot_causality)
export(plot_components)
export(plot_total)
export(signatureSpace)
export(stateSpace)
export(stateSpaceMethod)
export(validate_custom_fn_output)
Expand Down
3 changes: 2 additions & 1 deletion R/natureOfCausality.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
#' \code{\link{pcFullDetails}} for detailed analysis
#' \code{\link{pcMatrix}} for causality matrix computation
#'
#' @export
#' @keywords internal
#' @noRd
#'
#' @examples
#' \donttest{
Expand Down
3 changes: 2 additions & 1 deletion R/patternSpace.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#' patternSpaceMatrix <- patternSpace(signatureMatrix)
#' print(patternSpaceMatrix)
#'
#' @export
#' @keywords internal
#' @noRd
patternSpace <- function(SM) {
# Input validation
if (!is.matrix(SM) || !is.numeric(SM)) {
Expand Down
13 changes: 7 additions & 6 deletions R/pattern_utils.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' Print Pattern Causality Pattern Analysis Results
#' @keywords internal
#' @noRd
print.pc_pattern <- function(x, ...) {
Expand All @@ -10,14 +11,14 @@ print.pc_pattern <- function(x, ...) {

#' @keywords internal
#' @noRd
summary.pc_pattern <- function(x, ...) {
summary.pc_pattern <- function(object, ...) {
structure(
list(
n_patterns = nrow(x$patterns),
dimension = ncol(x$patterns),
hash_range = range(x$hashes),
pattern_stats = summary(as.vector(x$patterns)),
hash_stats = summary(x$hashes)
n_patterns = nrow(object$patterns),
dimension = ncol(object$patterns),
hash_range = range(object$hashes),
pattern_stats = summary(as.vector(object$patterns)),
hash_stats = summary(object$hashes)
),
class = "summary.pc_pattern"
)
Expand Down
39 changes: 36 additions & 3 deletions R/pc_full_details_utils.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Validate inputs for pattern causality analysis
#' Validate Inputs for Pattern Causality Analysis
#' @keywords internal
#' @noRd
validate_inputs <- function(X, Y, E, tau, metric, h, weighted, distance_fn = NULL) {
Expand Down Expand Up @@ -563,12 +563,45 @@ plot_causality.default <- function(x, type, ...) {

#' Validate Custom Function Output
#'
#' Validates the output format from custom distance and state space functions
#' @title Validate Custom Function Output for Pattern Causality Analysis
#' @description Validates the Output Format from Custom Distance and State Space Functions
#' to ensure compatibility with the package's internal processing.
#'
#' @param output The output from a custom function to validate
#' @param fn_name The name of the function type being validated ("distance_fn" or "state_space_fn")
#' @return Nothing. Throws an error if validation fails.
#' @keywords internal
#'
#' @examples
#' # 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)
#'
#' @export
validate_custom_fn_output <- function(output, fn_name) {
if(fn_name == "distance_fn" && !is.matrix(output)) {
Expand Down
5 changes: 2 additions & 3 deletions R/pc_lightweight_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ compute_causality_measures <- function(results, weighted) {

#' Analyze Pattern Causality Between Time Series
#'
#' @title Pattern Causality Analysis
#' @description Internal function that performs the main causality analysis loop
#' by analyzing patterns and signatures in reconstructed state spaces.
#' @title Analyze Pattern Causality Between Time Series Using State Space Reconstruction
#' @description Internal Function That Performs the Main Causality Analysis Loop
#'
#' @param spaces List containing state and pattern spaces
#' @param matrices List containing initialized analysis matrices
Expand Down
9 changes: 5 additions & 4 deletions R/signatureSpace.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' Calculate Signature Space Matrix
#'
#' @title Calculate Signature Space Matrix from State Space
#' @description Calculates the signature space matrix from a state space matrix by
#' computing differences between successive elements in each row. This transformation
#' @title Calculate Signature Space Matrix From State Space
#' @description Calculates the Signature Space Matrix From a State Space Matrix By
#' Computing Differences Between Successive Elements in Each Row. This transformation
#' helps capture the dynamic patterns in the time series data.
#'
#' @param M A state space matrix where each row represents a point in state space
Expand All @@ -17,7 +17,8 @@
#' embedding functions, but this implementation is specifically tailored for
#' pattern causality analysis.
#'
#' @export
#' @keywords internal
#' @noRd
signatureSpace <- function(M) {
# Input validation
if(!is.matrix(M)) {
Expand Down
2 changes: 1 addition & 1 deletion inst/CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ bibentry(
),
year = "2024",
note = "Available at SSRN",
url = "https://ssrn.com/abstract=4966221",
url = "https://www.ssrn.com/abstract=4966221",
doi = "10.2139/ssrn.4966221"
)
66 changes: 0 additions & 66 deletions man/natureOfCausality.Rd

This file was deleted.

38 changes: 0 additions & 38 deletions man/patternSpace.Rd

This file was deleted.

34 changes: 0 additions & 34 deletions man/signatureSpace.Rd

This file was deleted.

41 changes: 38 additions & 3 deletions man/validate_custom_fn_output.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 639bd25

Please sign in to comment.