In the weighted case, the switching algorithm transfers a certain amount of weight from some edges to others. The package provides two settings, which we will choose according to what type of weighted graph we are working with.
These graphs have an edge between every pair of vertices, which will usually be the result of applying some function to each pair. For example, networks resulting from computing correlations of time series (where each series corresponds to a vertex, and the edge weights are the correlations between series) fall into this category.
We show an example built from correlations of currency exchange time series . In this network vertices are pairs of exchange rates, and the edge weights are the correlations of their corresponding time series, scaled to the interval \([0,1]\). In this case, the appropriate setting is the one that keeps the variance of the edge weights constant.
data(g_forex, package="clustAnalytics")
rewireCpp(g=g_forex, weight_sel="const_var", lower_bound=0, upper_bound=1)
#> This graph was created by an old(er) igraph version.
#> ℹ Call `igraph::upgrade_graph()` on it to use with the current igraph version.
#> For now we convert it on the fly...
#> IGRAPH 20f35c2 UNW- 78 5839 --
#> + attr: name (v/c), TRUE (v/c), weight (e/n)
#> + edges from 20f35c2 (vertex names):
#> [1] JPYUSD--NZDCNY AUDUSD--SGDNZD HKDCAD--SGDSEK JPYUSD--SGDJPY GBPUSD--SGDNZD
#> [6] CNYMXN--SGDNZD JPYUSD--AUDUSD JPYUSD--CNYJPY JPYUSD--MXNCAD GBPUSD--MXNCAD
#> [11] MXNJPY--SGDSEK JPYUSD--SEKGBP JPYUSD--MXNEUR JPYUSD--HKDCAD JPYUSD--CHFGBP
#> [16] JPYUSD--SEKCAD JPYUSD--SEKUSD GBPUSD--HKDCAD JPYUSD--NZDAUD HKDMXN--SGDSEK
#> [21] GBPUSD--SGDSEK JPYUSD--CHFJPY AUDUSD--CNYJPY JPYUSD--SGDCAD JPYUSD--NZDCHF
#> [26] JPYUSD--GBPEUR JPYUSD--SGDEUR GBPEUR--SGDSEK CHFAUD--SGDSEK JPYUSD--HKDMXN
#> [31] NZDCAD--SGDSEK JPYUSD--NZDCAD JPYUSD--SGDNZD AUDUSD--SEKJPY JPYUSD--SEKCNY
#> [36] MXNCHF--SGDCHF JPYUSD--AUDGBP GBPUSD--SGDCAD JPYUSD--HKDGBP JPYUSD--HKDCHF
#> + ... omitted several edgesThis describes most commonly found weighted graphs, where the weights quantify some characteristic of the edges. Multigraphs also fit here, if we reinterpret them as weighted graphs where the edge weight is the number of parallel edges between each pair of vertices.
This is the case for the famous karate club graph from Zachary.
data(karate, package="igraphdata")
rewired_karate <- rewireCpp(karate, weight_sel="max_weight")
#> This graph was created by an old(er) igraph version.
#> ℹ Call `igraph::upgrade_graph()` on it to use with the current igraph version.
#> For now we convert it on the fly...
oldpar <- par(mfrow=c(1,2), mai=c(0,0.1,0.3,0.1)) #save original parameters
plot(karate, main="karate")
plot(rewired_karate, main="rewired_karate")