|
| 1 | +.surd_ts = \(data, target, agent, lag = 1, bin = 5, method = "equal", |
| 2 | + max.combs = 3, threads = 1, base = 2.0, normalize = TRUE) { |
| 3 | + mat = .convert2mat(data) |
| 4 | + return(RcppSURD(mat, target, agent, lag, bin, max.combs, |
| 5 | + threads, base, normalize, method)) |
| 6 | +} |
| 7 | + |
| 8 | +.surd_lattice = \(data, target, agent, lag = 1, bin = 5, method = "equal", |
| 9 | + max.combs = 3, threads = 1, base = 2.0, normalize = TRUE, nb = NULL) { |
| 10 | + if (is.null(nb)) nb = sdsfun::spdep_nb(data) |
| 11 | + mat = .convert2mat(data) |
| 12 | + return(RcppSURD(mat, target, agent, lag, bin, max.combs, |
| 13 | + threads, base, normalize, method, nb)) |
| 14 | +} |
| 15 | + |
| 16 | +.surd_grid = \(data, target, agent, lag = 1, bin = 5, method = "equal", |
| 17 | + max.combs = 3, threads = 1, base = 2.0, normalize = TRUE) { |
| 18 | + mat = .convert2mat(data) |
| 19 | + return(RcppSURD(mat, target, agent, lag, bin, max.combs, |
| 20 | + threads, base, normalize, method, NULL, terra::nrow(data[[1]]))) |
| 21 | +} |
| 22 | + |
| 23 | +#' SURD |
| 24 | +#' |
| 25 | +#' Synergistic-Unique-Redundant Decomposition of causality |
| 26 | +#' |
| 27 | +#' @note SURD only support numeric data. |
| 28 | +#' |
| 29 | +#' @inheritParams te |
| 30 | +#' @param lag (optional) Lag of the agent variables. |
| 31 | +#' @param bin (optional) Number of discretization bins. |
| 32 | +#' @param method (optional) Discretization method. One of |
| 33 | +#' `"sd"`, `"equal"`, `"geometric"`, `"quantile"`, |
| 34 | +#' `"natural("jenks")"`, or `"headtail"("headtails")`. |
| 35 | +#' @param max.combs (optional) Maximum combination order. |
| 36 | +#' @param threads (optional) Number of threads used. |
| 37 | +#' @param nb (optional) Neighbours list. |
| 38 | +#' |
| 39 | +#' @return A list. |
| 40 | +#' \describe{ |
| 41 | +#' \item{vars}{Character vector indicating the variable combination associated with each information component.} |
| 42 | +#' \item{types}{Character vector indicating the information type of each component.} |
| 43 | +#' \item{values}{Numeric vector giving the magnitude of each information component.} |
| 44 | +#' } |
| 45 | +#' |
| 46 | +#' @export |
| 47 | +#' @name surd |
| 48 | +#' @aliases surd,data.frame-method |
| 49 | +#' @references |
| 50 | +#' Martinez-Sanchez, A., Arranz, G. & Lozano-Duran, A. Decomposing causality into its synergistic, unique, and redundant components. Nat Commun 15, 9296 (2024). |
| 51 | +#' |
| 52 | +#' @examples |
| 53 | +#' columbus = sf::read_sf(system.file("case/columbus.gpkg", package="spEDM")) |
| 54 | +#' infoxtr::surd(columbus, 1, 2:3) |
| 55 | +#' |
| 56 | +methods::setMethod("surd", "data.frame", .surd_ts) |
| 57 | + |
| 58 | +#' @rdname surd |
| 59 | +methods::setMethod("surd", "sf", .surd_lattice) |
| 60 | + |
| 61 | +#' @rdname surd |
| 62 | +methods::setMethod("surd", "SpatRaster", .surd_grid) |
0 commit comments