|
| 1 | +#' Metacoupling Analysis |
| 2 | +#' |
| 3 | +#' @inheritParams ccd |
| 4 | +#' @param swm_peri A numeric matrix representing the **peri (local) spatial weight matrix**. |
| 5 | +#' Must be square with dimension equal to `nrow(data)`. If `NULL`, a zero matrix is used. |
| 6 | +#' @param swm_tele A numeric matrix representing the **tele (long-distance) spatial weight matrix**. |
| 7 | +#' Must be square with dimension equal to `nrow(data)`. If `NULL`, a zero matrix is used. |
| 8 | +#' |
| 9 | +#' @return A data.frame with: |
| 10 | +#' \itemize{ |
| 11 | +#' \item `Intra_C`: intra-system coupling degree |
| 12 | +#' \item `Intra_D`: intra-system coordination degree |
| 13 | +#' \item `Peri_C`: peri-coupling degree |
| 14 | +#' \item `Peri_D`: peri coordination degree |
| 15 | +#' \item `Tele_C`: tele-coupling degree |
| 16 | +#' \item `Tele_D`: tele coordination degree |
| 17 | +#' } |
| 18 | +#' |
| 19 | +#' @export |
| 20 | +#' |
| 21 | +#' @details |
| 22 | +#' Full model definitions and formulas are available at: |
| 23 | +#' \url{https://github.com/stscl/coupling/discussions/8} |
| 24 | +#' |
| 25 | +#' @note |
| 26 | +#' Input values should be normalized to `[0, 1]`. Spatial weight matrices are |
| 27 | +#' typically symmetric. |
| 28 | +#' |
| 29 | +#' @examples |
| 30 | +#' set.seed(42) |
| 31 | +#' mat = matrix(runif(20), nrow = 5) |
| 32 | +#' swm1 = apply(matrix(runif(25), 5, 5), 1, \(.x) .x / sum(.x)) |
| 33 | +#' swm2 = apply(matrix(runif(25), 5, 5), 1, \(.x) .x / sum(.x)) |
| 34 | +#' coupling::metacoupling(mat, swm1, swm2) |
| 35 | +#' |
| 36 | +metacoupling = \(data, swm_peri = NULL, swm_tele = NULL, weight = NULL, |
| 37 | + method = c("standard", "wang", "fan"), threads = 1){ |
| 38 | + mat = as.matrix(data) |
| 39 | + method = match.arg(method) |
| 40 | + if (is.null(weight)) weight = rep(1, times = ncol(mat)) / ncol(mat) |
| 41 | + if (is.null(swm_peri)) swm_peri = matrix(0, nrow(data), nrow(data)) |
| 42 | + if (is.null(swm_tele)) swm_tele = matrix(0, nrow(data), nrow(data)) |
| 43 | + return(RcppMetaCoupling(mat, swm_peri, swm_tele, weight, method, threads)) |
| 44 | +} |
0 commit comments