| Title: | Two-Stage Detection and Attribution of Cross-Border Financial Contagion Channels |
|---|---|
| Description: | Implementation of a two-stage framework for the joint detection-and-attribution of cross-border financial contagion. Stage one detects directional information flows between equity markets via Wavelet-Quantile Transfer Entropy, combining maximal-overlap discrete wavelet decomposition (Percival and Walden, 2000, ISBN:9780521685085) with the transfer-entropy estimator of Schreiber (2000) <doi:10.1103/PhysRevLett.85.461> and quantile conditioning following Han, Linton, Oka and Whang (2016) <doi:10.1016/j.jeconom.2016.03.001>. Stage two attributes each significant directional link to one of five mutually exclusive transmission channels (Trade, Financial, Geopolitical, Behavioural, Monetary Policy) through a multi-method structural identification architecture combining instrumental-variables two-stage least squares with channel-specific external instruments (Stock and Watson, 2018) <doi:10.1111/ecoj.12593>, LASSO-based instrument selection (Belloni, Chernozhukov and Hansen, 2014) <doi:10.1093/restud/rdt044>, local projections (Jorda, 2005) <doi:10.1257/0002828053828518>, heteroskedasticity-based identification (Rigobon, 2003) <doi:10.1162/003465303772815727>, and the Cinelli-Hazlett (2020) <doi:10.1111/rssb.12348> robustness-value sensitivity bound. Bundled datasets and replication scripts reproduce the headline findings of Bhandari, Parida and Sahu (2026) <doi:10.48550/arXiv.2604.26546>; the package is general-purpose and accommodates user-supplied returns and channel proxies. |
| Authors: | Avishek Bhandari [aut, cre] (Indian Institute of Technology Bhubaneswar), Ipsita Parida [aut] (Indian Institute of Technology Bhubaneswar), Hitesh Kumar Sahu [aut] (Indian Institute of Technology Bhubaneswar) |
| Maintainer: | Avishek Bhandari <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.3 |
| Built: | 2026-05-08 17:16:59 UTC |
| Source: | https://github.com/cran/contagionchannels |
Builds the five contagion-channel composites (Trade, Financial, Geopolitical, Behavioural, Monetary Policy) from a data.frame of raw channel proxies. The construction is engineered for orthogonal identification: the trade composite uses log-returns of a broad trade-weighted dollar index (genuinely time-varying), the behavioural composite is orthogonalised against the financial composite to avoid VIX-derivative contamination, and the monetary composite uses a first-differenced policy rate to remove persistence-induced first-stage F-inflation.
build_channel_composites(proxy_grid)build_channel_composites(proxy_grid)
proxy_grid |
A data.frame with the following columns aligned on the
same daily date grid: |
A data.frame with columns Date, Trade,
Financial, Geopolitical, Behavioral, and
Monetary_Policy; each composite is z-scored within sample.
Stock, J. H., & Watson, M. W. (2018). Identification and Estimation of Dynamic Causal Effects in Macroeconomics Using External Instruments. Economic Journal, 128(610), 917-948. doi:10.1111/ecoj.12593.
Romer, C. D., & Romer, D. H. (2004). A New Measure of Monetary Shocks. American Economic Review, 94(4), 1055-1084. doi:10.1257/0002828042002651.
d <- load_paper_data() ch <- build_channel_composites(d$proxies) head(ch); cor(ch[, -1])d <- load_paper_data() ch <- build_channel_composites(d$proxies) head(ch); cor(ch[, -1])
Returns a vector where the first positions are
NA and the remaining positions are the lagged values of x.
Used throughout the package for instrument and predictor construction.
build_lag(x, lg)build_lag(x, lg)
x |
Numeric vector. |
lg |
Positive integer lag. |
Numeric vector of the same length as x.
build_lag(1:10, 3)build_lag(1:10, 3)
Builds a directed weighted network from a pairwise WQTE flow matrix by retaining only the edges whose intensity exceeds the supplied threshold. The network construction follows the standard contagion-network literature (Diebold and Yilmaz, 2014; Billio et al., 2012).
build_network(F_matrix, threshold)build_network(F_matrix, threshold)
F_matrix |
An |
threshold |
Numeric threshold for edge retention; edges with
|
An igraph object with weight edge attribute equal to the
WQTE value.
m <- matrix(runif(25, 0, 0.1), 5, 5); diag(m) <- 0 g <- build_network(m, threshold = 0.05) igraph::ecount(g)m <- matrix(runif(25, 0, 0.1), 5, 5); diag(m) <- 0 g <- build_network(m, threshold = 0.05) igraph::ecount(g)
Daily-frequency channel-proxy series aligned on the G20 trading-day
grid, used as inputs to build_channel_composites. Values
are forward-filled where lower-frequency data are available.
channel_proxieschannel_proxies
A data.frame with 5,036 rows and 14 columns:
Trading date
CBOE Volatility Index level
ICE BofA US High-Yield Option-Adjusted Spread
St. Louis Fed Financial Stress Index (STLFSI4)
Federal Reserve Broad Trade-Weighted Dollar Index (DTWEXBGS)
Caldara-Iacoviello Geopolitical Risk Index
Geopolitical-events indicator
VIX-VIX3M term-structure slope
Daily absolute change in VIX
University of Michigan Consumer Sentiment Index
Effective Federal Funds Rate
10-year Treasury yield
10-year minus 3-month Treasury yield spread
Quantitative-easing program indicator (binary)
Federal Reserve Economic Data (FRED), Yahoo Finance, Caldara-Iacoviello GPR data library.
data(channel_proxies) summary(channel_proxies[, c("vix","gpr","fed_rate")])data(channel_proxies) summary(channel_proxies[, c("vix","gpr","fed_rate")])
Computes the partial- that an unobserved confounder would need
to share with both the treatment and the outcome to drive the structural
coefficient to zero. The robustness value is bounded in [0, 1]; values
near zero indicate that even a weakly correlated confounder could explain
away the result, while values near one indicate identification-robust
findings.
cinelli_hazlett_rv(theta, se, df)cinelli_hazlett_rv(theta, se, df)
theta |
Estimated structural coefficient. |
se |
Standard error of |
df |
Residual degrees of freedom. |
A scalar in , or NA if inputs are invalid.
Cinelli, C., & Hazlett, C. (2020). Making Sense of Sensitivity: Extending Omitted Variable Bias. Journal of the Royal Statistical Society Series B, 82(1), 39-67. doi:10.1111/rssb.12348.
cinelli_hazlett_rv(theta = 0.4, se = 0.1, df = 200)cinelli_hazlett_rv(theta = 0.4, se = 0.1, df = 200)
Computes the bilateral WQTE matrix for a returns panel at one wavelet scale and one quantile, producing the directed flow matrix that serves as the Stage-1 input to the structural-attribution layer.
compute_wqte_matrix(returns, scale = 5, tau = 0.5, n_cores = 2L)compute_wqte_matrix(returns, scale = 5, tau = 0.5, n_cores = 2L)
returns |
An xts or matrix of returns (rows = time, cols = markets). |
scale |
Integer wavelet scale. Default 5. |
tau |
Quantile level. Default 0.50. |
n_cores |
Integer; number of parallel cores for |
An matrix where entry is the WQTE
from market to market at the specified scale and
quantile; row and column names are taken from colnames(returns).
Bhandari, A., & Parida, I. (2026). Wavelet-quantile transfer entropy for financial-market contagion.
d <- load_paper_data() ix <- which(zoo::index(d$returns) >= as.Date("2008-01-01") & zoo::index(d$returns) <= as.Date("2008-12-31")) F <- compute_wqte_matrix(d$returns[ix, ], scale = 5, tau = 0.50, n_cores = 2)d <- load_paper_data() ix <- which(zoo::index(d$returns) >= as.Date("2008-01-01") & zoo::index(d$returns) <= as.Date("2008-12-31")) F <- compute_wqte_matrix(d$returns[ix, ], scale = 5, tau = 0.50, n_cores = 2)
A named list of length-two character vectors specifying the start and end dates of the eight crisis sub-periods analysed in the paper.
crisis_periodscrisis_periods
A named list with eight elements:
Pre-Crisis Baseline (12 Jan 2006 - 31 Jul 2007)
Global Financial Crisis (1 Aug 2007 - 30 Jun 2009)
European Sovereign Debt Crisis (1 Dec 2009 - 30 Jun 2012)
Chinese Stock Crash (15 Jun 2015 - 31 Dec 2016)
Pre-COVID interval (1 Jan 2017 - 31 Jan 2020)
COVID-19 Pandemic (1 Feb 2020 - 31 Dec 2021)
Russia-Ukraine episode (1 Feb 2022 - 31 Dec 2023)
Middle-East tensions and tariffs (1 Jan 2024 - 18 Mar 2026)
data(crisis_periods) crisis_periods$GFCdata(crisis_periods) crisis_periods$GFC
Daily log-return panel for 18 G20 equity-market indices spanning 12 January 2006 through 18 March 2026, used in the paper replication. The panel covers 5,036 trading days. Eight developed and ten emerging markets are represented.
g20_returnsg20_returns
An xts object with 5,036 rows and 18 columns:
S&P/MERVAL log-returns
S&P/ASX 200 log-returns
IBOVESPA log-returns
S&P/TSX Composite log-returns
Shanghai Composite log-returns
CAC 40 log-returns
DAX 40 log-returns
BSE SENSEX log-returns
IDX Composite log-returns
FTSE MIB log-returns
Nikkei 225 log-returns
S&P/BMV IPC log-returns
IMOEX log-returns
JSE All Share log-returns
KOSPI log-returns
BIST 100 log-returns
FTSE 100 log-returns
S&P 500 log-returns
Yahoo Finance and Investing.com aggregator.
data(g20_returns) dim(g20_returns); head(g20_returns[, 1:5])data(g20_returns) dim(g20_returns); head(g20_returns[, 1:5])
Estimates the structural equation
via two-stage least squares, treating the five channel composites as
endogenous and instrumenting them with their own lagged values at
plus cross-channel interactions at . The
first-stage F-statistic per channel, the Sargan over-identification J-test,
and the Durbin-Wu-Hausman endogeneity test are reported.
iv_2sls_attribute(C_ij, ch_per, R_full, channel_names = CHN_DEFAULT)iv_2sls_attribute(C_ij, ch_per, R_full, channel_names = CHN_DEFAULT)
C_ij |
Numeric vector of pairwise daily co-movement
( |
ch_per |
A data.frame containing the five channel composites for
the current period (with columns named per |
R_full |
Numeric matrix of returns for the period (used to construct
the global factor |
channel_names |
Character vector of channel column names. Default
|
A list with elements theta (5-vector of structural
coefficients), partial_F (per-channel first-stage F-stats),
J_stat, J_p, dwh_F, dwh_p, and n_obs;
or NULL if the regression cannot be run.
Stock, J. H., & Watson, M. W. (2018). Identification and Estimation of Dynamic Causal Effects in Macroeconomics Using External Instruments. Economic Journal, 128(610), 917-948. doi:10.1111/ecoj.12593.
Mertens, K., & Ravn, M. O. (2013). The Dynamic Effects of Personal and Corporate Income Tax Changes in the United States. American Economic Review, 103(4), 1212-1247. doi:10.1257/aer.103.4.1212.
d <- load_paper_data() ch <- build_channel_composites(d$proxies) p <- period_subset(d$returns, ch, d$periods$GFC) src <- as.numeric(p$R[, "USA"]); tgt <- as.numeric(p$R[, "SouthKorea"]) fit <- iv_2sls_attribute(src * tgt, p$C, p$R) fit$thetad <- load_paper_data() ch <- build_channel_composites(d$proxies) p <- period_subset(d$returns, ch, d$periods$GFC) src <- as.numeric(p$R[, "USA"]); tgt <- as.numeric(p$R[, "SouthKorea"]) fit <- iv_2sls_attribute(src * tgt, p$C, p$R) fit$theta
Estimates the channel-attribution coefficients via post-double-selection
LASSO IV with the high-dimensional instrument set. Uses
hdm::rlassoIV per channel with controls for the other endogenous
regressors. Requires the optional hdm package.
lasso_iv_attribute(C_ij, ch_per, R_full, channel_names = CHN_DEFAULT)lasso_iv_attribute(C_ij, ch_per, R_full, channel_names = CHN_DEFAULT)
C_ij |
Numeric vector of pairwise daily co-movement
( |
ch_per |
A data.frame containing the five channel composites for
the current period (with columns named per |
R_full |
Numeric matrix of returns for the period (used to construct
the global factor |
channel_names |
Character vector of channel column names. Default
|
A list with elements theta and se, or NULL.
Belloni, A., Chernozhukov, V., & Hansen, C. (2014). Inference on Treatment Effects after Selection among High-Dimensional Controls. Review of Economic Studies, 81(2), 608-650. doi:10.1093/restud/rdt044.
if (requireNamespace("hdm", quietly = TRUE)) { d <- load_paper_data() ch <- build_channel_composites(d$proxies) p <- period_subset(d$returns, ch, d$periods$GFC) src <- as.numeric(p$R[, "USA"]); tgt <- as.numeric(p$R[, "SouthKorea"]) fit <- lasso_iv_attribute(src * tgt, p$C, p$R) }if (requireNamespace("hdm", quietly = TRUE)) { d <- load_paper_data() ch <- build_channel_composites(d$proxies) p <- period_subset(d$returns, ch, d$periods$GFC) src <- as.numeric(p$R[, "USA"]); tgt <- as.numeric(p$R[, "SouthKorea"]) fit <- lasso_iv_attribute(src * tgt, p$C, p$R) }
Convenience loader returning a named list with the three bundled datasets (returns, channel proxies, crisis periods) used in the paper replication.
load_paper_data()load_paper_data()
A named list with elements returns, proxies, and
periods.
d <- load_paper_data(); str(d, max.level = 1)d <- load_paper_data(); str(d, max.level = 1)
Estimates horizon-specific impulse responses of the pairwise co-movement
to each channel composite at horizons days
following Jorda (2005). The local projection at horizon estimates
separately for each channel , with the other four channels and the
lagged co-movement and global factor entering as controls.
local_projections( C_ij, ch_per, R_full, horizons = c(1, 5, 22), channel_names = CHN_DEFAULT )local_projections( C_ij, ch_per, R_full, horizons = c(1, 5, 22), channel_names = CHN_DEFAULT )
C_ij |
Numeric vector of pairwise daily co-movement
( |
ch_per |
A data.frame containing the five channel composites for
the current period (with columns named per |
R_full |
Numeric matrix of returns for the period (used to construct
the global factor |
horizons |
Integer vector of horizons. Default |
channel_names |
Character vector of channel column names. Default
|
A list with one element per horizon; each element is a
length-length(channel_names) numeric vector of LP coefficients.
Jorda, O. (2005). Estimation and Inference of Impulse Responses by Local Projections. American Economic Review, 95(1), 161-182. doi:10.1257/0002828053828518.
Plagborg-Moller, M., & Wolf, C. K. (2021). Local Projections and VARs Estimate the Same Impulse Responses. Econometrica, 89(2), 955-980. doi:10.3982/ECTA17813.
d <- load_paper_data() ch <- build_channel_composites(d$proxies) p <- period_subset(d$returns, ch, d$periods$GFC) src <- as.numeric(p$R[, "USA"]); tgt <- as.numeric(p$R[, "SouthKorea"]) lp <- local_projections(src * tgt, p$C, p$R)d <- load_paper_data() ch <- build_channel_composites(d$proxies) p <- period_subset(d$returns, ch, d$periods$GFC) src <- as.numeric(p$R[, "USA"]); tgt <- as.numeric(p$R[, "SouthKorea"]) lp <- local_projections(src * tgt, p$C, p$R)
Returns the MODWT detail coefficients of a return series at the specified scale, using the Daubechies least-asymmetric filter of length 8 (LA8). The maximal-overlap discrete wavelet transform is shift-invariant and aligned with the original time-axis, making it suited to financial returns; see Percival and Walden (2000).
modwt_detail(x, scale = 5, J = 6, filter = "la8")modwt_detail(x, scale = 5, J = 6, filter = "la8")
x |
Numeric vector of returns. |
scale |
Integer scale (1-6) corresponding to dyadic horizons of
|
J |
Integer maximum decomposition level. Default 6. |
filter |
Character; the wavelet filter family to use. Default
|
Numeric vector of detail coefficients at scale scale.
Percival, D. B., & Walden, A. T. (2000). Wavelet Methods for Time Series Analysis. Cambridge University Press.
x <- rnorm(512) d5 <- modwt_detail(x, scale = 5) length(d5)x <- rnorm(512) d5 <- modwt_detail(x, scale = 5) length(d5)
Returns a list of standard centrality and density statistics for a directed contagion network.
network_summary(g)network_summary(g)
g |
An igraph object. |
A list with elements n_edges, density,
in_degree, out_degree, betweenness, and
eigenvector.
m <- matrix(runif(25, 0, 0.1), 5, 5); diag(m) <- 0 g <- build_network(m, threshold = 0.05) network_summary(g)$densitym <- matrix(runif(25, 0, 0.1), 5, 5); diag(m) <- 0 g <- build_network(m, threshold = 0.05) network_summary(g)$density
Returns the residuals from a regression of y on x; the
residual is by construction orthogonal to x in the sample. This
is the pre-processing step used to construct the behavioural channel
composite, which is orthogonalised against the financial composite to
avoid the within-VIX decomposition that contaminates cross-channel
identification when both composites share VIX-derivative inputs.
orthogonalise_residual(y, x)orthogonalise_residual(y, x)
y |
Numeric vector to be orthogonalised. |
x |
Numeric vector against which |
Numeric vector of length length(y) containing the residuals.
a <- rnorm(100); b <- 0.5 * a + rnorm(100); cor(a, orthogonalise_residual(b, a))a <- rnorm(100); b <- 0.5 * a + rnorm(100); cor(a, orthogonalise_residual(b, a))
Selects the rows of an xts returns object and the matching rows of a channel-composite data.frame that fall within a date range.
period_subset(returns_xts, channels_df, period_dates)period_subset(returns_xts, channels_df, period_dates)
returns_xts |
An xts object of daily returns indexed by Date. |
channels_df |
A data.frame with a |
period_dates |
A character or Date vector of length 2 |
A list with elements R (xts subset) and C
(data.frame subset).
d <- load_paper_data() ch <- build_channel_composites(d$proxies) p <- period_subset(d$returns, ch, c("2008-01-01","2008-12-31")) nrow(p$C)d <- load_paper_data() ch <- build_channel_composites(d$proxies) p <- period_subset(d$returns, ch, c("2008-01-01","2008-12-31")) nrow(p$C)
Line plot of channel-attribution share evolution across crisis sub-periods.
plot_attribution_evolution(period_shares)plot_attribution_evolution(period_shares)
period_shares |
Per-period share data.frame (output from
|
A ggplot object.
Draws a stacked bar chart of channel-attribution shares across crisis
sub-periods. Returns a ggplot if ggplot2 is available, else uses
base barplot.
plot_attribution_stack(period_shares, ...)plot_attribution_stack(period_shares, ...)
period_shares |
A data.frame with columns |
... |
Additional arguments passed to |
A ggplot object (or invisibly the matrix used for base plotting).
d <- load_paper_data() ch <- build_channel_composites(d$proxies) res <- run_contagion_pipeline(d$returns, ch, d$periods, n_cores = 2) plot_attribution_stack(res$period_shares)d <- load_paper_data() ch <- build_channel_composites(d$proxies) res <- run_contagion_pipeline(d$returns, ch, d$periods, n_cores = 2) plot_attribution_stack(res$period_shares)
Top panel: mean QTE per sub-period. Bottom panel: network density per sub-period.
plot_qte_intensity(stage1_summary)plot_qte_intensity(stage1_summary)
stage1_summary |
A data.frame with columns |
A patchwork ggplot if available, else a multi-panel base plot.
Heatmap of Cinelli-Hazlett robustness values per channel and sub-period.
plot_robustness_value(rv_matrix)plot_robustness_value(rv_matrix)
rv_matrix |
Numeric matrix with rownames = periods, colnames = channels. |
A ggplot object.
Estimates the directional information flow from one wavelet-detail series
x to another y at the specified quantile, following the
quantile-regression-based transfer-entropy estimator. A positive value
indicates that conditioning on the past of x improves the
conditional-quantile prediction of y beyond what y's own
past supplies.
qte_pair(x, y, tau = 0.5)qte_pair(x, y, tau = 0.5)
x |
Numeric source series (typically a MODWT detail coefficient). |
y |
Numeric target series (typically a MODWT detail coefficient). |
tau |
Quantile level in (0,1). Default 0.50 (median). |
A scalar; NA if there are insufficient observations or the
quantile regressions fail to converge.
Schreiber, T. (2000). Measuring Information Transfer. Physical Review Letters, 85(2), 461. doi:10.1103/PhysRevLett.85.461.
Han, H., Linton, O., Oka, T., & Whang, Y.-J. (2016). The Cross- Quantilogram. Journal of Econometrics, 193(1), 251-270. doi:10.1016/j.jeconom.2016.03.001.
x <- rnorm(500); y <- 0.3 * c(0, x[-500]) + rnorm(500) qte_pair(x, y, tau = 0.5)x <- rnorm(500); y <- 0.3 * c(0, x[-500]) + rnorm(500) qte_pair(x, y, tau = 0.5)
Identifies the channel-attribution coefficients by exploiting regime shifts in the variance of returns within the period. Useful when the Sargan over-identification test rejects the joint validity of external instruments and an alternative identification strategy is required.
rigobon_id(C_ij, ch_per, R_full, channel_names = CHN_DEFAULT)rigobon_id(C_ij, ch_per, R_full, channel_names = CHN_DEFAULT)
C_ij |
Numeric vector of pairwise daily co-movement
( |
ch_per |
A data.frame containing the five channel composites for
the current period (with columns named per |
R_full |
Numeric matrix of returns for the period (used to construct
the global factor |
channel_names |
Character vector of channel column names. Default
|
A list with element theta: a length-five numeric vector of
structural coefficients, or NULL.
Rigobon, R. (2003). Identification through Heteroskedasticity. Review of Economics and Statistics, 85(4), 777-792. doi:10.1162/003465303772815727.
d <- load_paper_data() ch <- build_channel_composites(d$proxies) p <- period_subset(d$returns, ch, d$periods$GFC) src <- as.numeric(p$R[, "USA"]); tgt <- as.numeric(p$R[, "SouthKorea"]) rig <- rigobon_id(src * tgt, p$C, p$R)d <- load_paper_data() ch <- build_channel_composites(d$proxies) p <- period_subset(d$returns, ch, d$periods$GFC) src <- as.numeric(p$R[, "USA"]); tgt <- as.numeric(p$R[, "SouthKorea"]) rig <- rigobon_id(src * tgt, p$C, p$R)
Runs the full two-stage detection-and-attribution pipeline over a specified set of crisis sub-periods: Stage 1 produces a per-period WQTE flow matrix at the supplied scale and quantile, and Stage 2 attributes each significant link to one of five channels via IV/2SLS. Network density, top transmitter/receiver, and per-period channel-attribution shares are returned in a list.
run_contagion_pipeline( returns, channels, periods, scale = 5, tau = 0.5, threshold_period = names(periods)[1], edge_quantile = 0.75, n_cores = 2L )run_contagion_pipeline( returns, channels, periods, scale = 5, tau = 0.5, threshold_period = names(periods)[1], edge_quantile = 0.75, n_cores = 2L )
returns |
An xts of daily returns indexed by date. |
channels |
A data.frame of channel composites (output of
|
periods |
A named list of length-2 character or Date vectors
specifying |
scale |
Integer wavelet scale. Default 5. |
tau |
Quantile level. Default 0.50. |
threshold_period |
Name of the period in |
edge_quantile |
Numeric in (0,1); the quantile of positive WQTE in the threshold period used as the absolute threshold. Default 0.75. |
n_cores |
Integer number of parallel cores. Default |
A list with elements
Per-period list with F (flow matrix), network,
and summary.
Per-period list of attribution data.frames with one row per significant link.
Per-period mean attribution-share data.frame.
The absolute WQTE threshold used.
d <- load_paper_data() ch <- build_channel_composites(d$proxies) res <- run_contagion_pipeline(d$returns, ch, d$periods, n_cores = 2) res$period_sharesd <- load_paper_data() ch <- build_channel_composites(d$proxies) res <- run_contagion_pipeline(d$returns, ch, d$periods, n_cores = 2) res$period_shares
Detects communities using the Walktrap algorithm of Pons and Latapy (2006) on the symmetrised version of the directed contagion network.
walktrap_communities(g)walktrap_communities(g)
g |
An igraph object. |
An integer vector of community memberships, one per vertex; or
NULL if the network has too few edges.
m <- matrix(runif(25, 0, 0.1), 5, 5); diag(m) <- 0 g <- build_network(m, threshold = 0.02) walktrap_communities(g)m <- matrix(runif(25, 0, 0.1), 5, 5); diag(m) <- 0 g <- build_network(m, threshold = 0.02) walktrap_communities(g)
Returns the z-score of a numeric vector, robust to NAs and zero-variance input.
zscore(x)zscore(x)
x |
Numeric vector. |
Numeric vector of the same length as x with mean zero and
unit standard deviation; returns a zero vector if the input has no
finite variation.
zscore(rnorm(100))zscore(rnorm(100))