Title: | Weighted and Directed Networks |
Version: | 1.2.3 |
Date: | 2024-03-03 |
Maintainer: | Yelie Yuan <yelie.yuan@uconn.edu> |
Description: | Assortativity coefficients, centrality measures, and clustering coefficients for weighted and directed networks. Rewiring unweighted networks with given assortativity coefficients. Generating general preferential attachment networks. |
Depends: | R (≥ 4.1.0) |
License: | GPL (≥ 3.0) |
Encoding: | UTF-8 |
Imports: | CVXR, igraph, Matrix, rARPACK, RcppXPtrUtils, stats, wdm |
LinkingTo: | Rcpp, RcppArmadillo |
BugReports: | https://gitlab.com/wdnetwork/wdnet/-/issues |
URL: | https://gitlab.com/wdnetwork/wdnet |
RoxygenNote: | 7.2.3 |
Suggests: | testthat (≥ 3.0.0) |
NeedsCompilation: | yes |
Packaged: | 2024-03-03 16:06:10 UTC; yelie |
Author: | Yelie Yuan [aut, cre], Tiandong Wang [aut], Jun Yan [aut], Panpan Zhang [aut] |
Repository: | CRAN |
Date/Publication: | 2024-03-03 17:10:02 UTC |
wdnet: Weighted and Directed Networks
Description
This package provides functions to conduct network analysis
Assortativity, centrality, clustering coefficient for weighted and directed networks
Rewire an unweighted network with given assortativity coefficient(s)
Preferential attachment (PA) network generation
wdnet networks
wdnet networks have a class wdnet
. It is a
list containing the following components:
A logical value
directed
indicating if the network is directed.A logical value
weighted
indicating if the network is weighted.A two-column matrix
edgelist
representing the edges.A data frame
node.attr
that includes node attributes, such as node strengths.A data frame
edge.attr
that includes edge attributes, such as edge weights.
Creating a wdnet
Object
To generate a preferential attachment (PA) network, use
rpanet()
.To create a
wdnet
object from an edge list and edge weights, useedgelist_to_wdnet()
.To create a
wdnet
object from an adjacency matrix, useadj_to_wdnet()
.To convert an
igraph
object to awdnet
object, useigraph_to_wdnet()
.
Further information
The development version of this package is available on Gitlab (https://gitlab.com/wdnetwork/wdnet).
Author(s)
Maintainer: Yelie Yuan yelie.yuan@uconn.edu
Authors:
Tiandong Wang td_wang@fudan.edu.cn
Jun Yan jun.yan@uconn.edu
Panpan Zhang panpan.zhang@vumc.org
See Also
Useful links:
Add components to the control list
Description
'+' is used to combine components to control the PA network generation
process. Available components are rpa_control_scenario()
,
rpa_control_edgeweight()
, rpa_control_newedge()
,
rpa_control_preference()
and rpa_control_reciprocal()
.
Usage
## S3 method for class 'rpacontrol'
e1 + e2
Arguments
e1 |
A list of class |
e2 |
A list of class |
Value
A list of class rpacontrol
with components from e1
and
e2
.
Examples
control <- rpa_control_scenario(alpha = 0.5, beta = 0.5) +
rpa_control_preference(
ftype = "customized",
spref = "pow(outs, 2) + 1",
tpref = "pow(ins, 2) + 1"
)
control <- rpa_control_scenario(alpha = 1) +
rpa_control_edgeweight(
sampler = function(n) rgamma(n, shape = 5, scale = 0.2)
)
Converts an adjacency matrix to edgelist and edgeweight using the
igraph
package.
Description
Converts an adjacency matrix to edgelist and edgeweight using the
igraph
package.
Usage
adj_to_edgelist(adj, directed = TRUE, weighted = TRUE)
Arguments
adj |
Adjacency matrix of a network. |
directed |
Logical, whether the network is directed. This value is
passed to |
weighted |
Logical, whether the network is weighted. |
Value
A list of edgelist, edgeweight and directed.
Creates a wdnet
object using an adjacency matrix
Description
Creates a wdnet
object using an adjacency matrix
Usage
adj_to_wdnet(adj, directed = TRUE, weighted = TRUE, nodegroup, ...)
Arguments
adj |
An adjacency matrix used to extract |
directed |
Logical, whether the network is directed (TRUE) or undirected
(FALSE). If |
weighted |
Logical, whether the network is weighted (TRUE) or unweighted (FALSE). |
nodegroup |
A numeric vector of node groups. |
... |
Additional components to be added to the |
Value
A wdnet
object with the specified adj
.
Examples
adj <- matrix(c(0, 1, 2, 0), nrow = 2, ncol = 2, byrow = TRUE)
adj_to_wdnet(adj = adj, directed = TRUE, weighted = FALSE)
Compute the assortativity coefficient(s) for a network.
Description
Compute the assortativity coefficient(s) for a network.
Usage
assortcoef(netwk, edgelist, edgeweight, adj, directed, f1, f2)
Arguments
netwk |
A |
edgelist |
A two-column matrix representing edges. |
edgeweight |
A numeric vector of edge weights with the same length as
the number of rows in edgelist. If |
adj |
The adjacency matrix of a network. |
directed |
Logical. Indicates whether the edges in |
f1 |
A vector representing the first feature of existing nodes. The
number of nodes should be equal to the length of both |
f2 |
A vector representing the second feature of existing nodes. Defined
for directed networks. If |
Value
Assortativity coefficient for undirected networks, or a list of four assortativity coefficients for directed networks.
Note
When the adjacency matrix is binary (i.e., directed but unweighted
networks), assortcoef
returns the assortativity coefficient proposed
in Foster et al. (2010).
References
Foster, J.G., Foster, D.V., Grassberger, P. and Paczuski, M. (2010). Edge direction and the structure of networks. Proceedings of the National Academy of Sciences of the United States, 107(24), 10815–10820.
Yuan, Y. Zhang, P. and Yan, J. (2021). Assortativity coefficients for weighted and directed networks. Journal of Complex Networks, 9(2), cnab017.
Examples
set.seed(123)
control <- rpa_control_edgeweight(
sampler = function(n) rgamma(n, shape = 5, scale = 0.2)
)
netwk <- rpanet(nstep = 10^4, control = control)
ret <- assortcoef(netwk)
ret <- assortcoef(
edgelist = netwk$edgelist,
edgeweight = netwk$edge.attr$weight,
directed = TRUE
)
Centrality measures
Description
Computes the centrality measures of the nodes in a weighted and directed network.
Usage
centrality(
netwk,
adj,
edgelist,
edgeweight,
directed = TRUE,
measure = c("degree", "closeness", "wpr"),
degree.control = list(alpha = 1, mode = "out"),
closeness.control = list(alpha = 1, mode = "out", method = "harmonic", distance =
FALSE),
wpr.control = list(gamma = 0.85, theta = 1, prior.info = NULL)
)
Arguments
netwk |
A |
adj |
An adjacency matrix of a weighted and directed network. |
edgelist |
A two-column matrix representing edges of a directed network. |
edgeweight |
A vector representing the weight of edges. |
directed |
Logical. Indicates whether the edges in |
measure |
Which measure to use: "degree" (degree-based centrality), "closeness" (closeness centrality), or "wpr" (weighted PageRank centrality)? |
degree.control |
A list of parameters passed to the degree centrality measure:
|
closeness.control |
A list of parameters passed to the closeness centrality measure:
|
wpr.control |
A list of parameters passed to the weighted PageRank centrality measure:
|
Value
A list of node names and associated centrality measures
Note
The degree-based centrality measure is an extension of function
strength
in package igraph
and an alternative of function
degree_w
in package tnet
.
The closeness centrality measure is an extension of function
closeness
in package igraph
and function closeness_w
in package tnet
. The method of computing distances between vertices
is the Dijkstra's algorithm.
The weighted PageRank centrality measure is an extension of function
page_rank
in package igraph
.
References
Dijkstra, E.W. (1959). A note on two problems in connexion with graphs. Numerische Mathematik, 1, 269–271.
Newman, M.E.J. (2003). The structure and function of complex networks. SIAM review, 45(2), 167–256.
Opsahl, T., Agneessens, F., Skvoretz, J. (2010). Node centrality in weighted networks: Generalizing degree and shortest paths. Social Networks, 32, 245–251.
Zhang, P., Wang, T. and Yan, J. (2022) PageRank centrality and algorithms for weighted, directed networks with applications to World Input-Output Tables. Physica A: Statistical Mechanics and its Applications, 586, 126438.
Zhang, P., Zhao, J. and Yan, J. (2020+) Centrality measures of networks with application to world input-output tables
Examples
## Generate a network according to the Erd\"{o}s-Renyi model of order 20
## and parameter p = 0.3
edge_ER <- rbinom(400, 1, 0.3)
weight_ER <- sapply(edge_ER, function(x) x * sample(3, 1))
adj_ER <- matrix(weight_ER, 20, 20)
mydegree <- centrality(
adj = adj_ER,
measure = "degree", degree.control =
list(alpha = 0.8, mode = "in")
)
myclose <- centrality(
adj = adj_ER,
measure = "closeness", closeness.control =
list(alpha = 0.8, mode = "out", method = "harmonic", distance = FALSE)
)
mywpr <- centrality(
adj = adj_ER,
measure = "wpr", wpr.control =
list(gamma = 0.85, theta = 0.75)
)
Closeness centrality
Description
Compute the closeness centrality measures of the vertices in a weighted and directed network represented through its adjacency matrix.
Usage
closeness_c(
adj,
alpha = 1,
mode = "out",
method = "harmonic",
distance = FALSE
)
Arguments
adj |
is an adjacency matrix of a weighted and directed network |
alpha |
is a tuning parameter. The value of alpha must be nonnegative. By convention, alpha takes a value from 0 to 1 (default). |
mode |
which mode to compute: "out" (default) or "in"? For undirected networks, this setting is irrelevant. |
method |
which method to use: "harmonic" (default) or "standard"? |
distance |
whether to consider the entries in the adjacency matrix as
distances or strong connections. The default setting is |
Value
a list of node names and associated closeness centrality measures
Note
Function closeness_c
is an extension of function
closeness
in package igraph
and function closeness_w
in package tnet
. The method of computing distances between vertices
is the Dijkstra's algorithm.
References
Dijkstra, E.W. (1959). A note on two problems in connexion with graphs. Numerische Mathematik, 1, 269–271.
Newman, M.E.J. (2003). The structure and function of complex networks. SIAM review, 45(2), 167–256.
Opsahl, T., Agneessens, F., Skvoretz, J. (2010). Node centrality in weighted networks: Generalizing degree and shortest paths. Social Networks, 32, 245–251.
Zhang, P., Zhao, J. and Yan, J. (2020+) Centrality measures of networks with application to world input-output tables
Directed clustering coefficient
Description
Compute the clustering coefficient of a weighted and directed network.
Usage
clustcoef(
netwk,
edgelist,
edgeweight,
adj,
directed = TRUE,
method = c("Clemente", "Fagiolo"),
isolates = 0
)
Arguments
netwk |
A |
edgelist |
A two-column matrix, each row represents a directed edge of the network. |
edgeweight |
A vector representing the weight of edges. |
adj |
An adjacency matrix of a weighted and directed network. |
directed |
Logical. Indicates whether the edges in |
method |
Which method used to compute clustering coefficients: Clemente and Grassi (2018) or Fagiolo (2007). |
isolates |
Binary, defines how to treat vertices with degree zero and
one. If 0, then their clustering coefficient is returned as 0 and are
included in the averaging. Otherwise, their clustering coefficient is |
Value
Lists of local clustering coefficients (in terms of a vector), global
clustering coefficient (in terms of a scalar) and number of weighted
directed triangles (in terms of a vector) based on total
, in
,
out
, middleman (middle
), or cycle
triplets.
Note
Self-loops (if exist) are removed prior to the computation of
clustering coefficient. When the adjacency matrix is symmetric (i.e.,
undirected but possibly unweighted networks), clustcoef
returns
local and global clustering coefficients proposed by Barrat et al. (2010).
References
Barrat, A., Barthelemy, M., Pastor-Satorras, R. and Vespignani, A. (2004). The architecture of complex weighted networks. Proceedings of National Academy of Sciences of the United States of America, 101(11), 3747–3752.
Clemente, G.P. and Grassi, R. (2018). Directed clustering in weighted networks: A new perspective. Chaos, Solitons & Fractals, 107, 26–38.
Fagiolo, G. (2007). Clustering in complex directed networks. Physical Review E, 76, 026107.
Examples
## Generate a network according to the Erd\"{o}s-Renyi model of order 20
## and parameter p = 0.3
edge_ER <- rbinom(400, 1, 0.3)
weight_ER <- sapply(edge_ER, function(x) x * sample(3, 1))
adj_ER <- matrix(weight_ER, 20, 20)
mycc <- clustcoef(adj = adj_ER, method = "Clemente")
system.time(mycc)
Compile preference functions via RcppXPtrUtils
.
Description
Compile preference functions via RcppXPtrUtils
.
Usage
compile_pref_func(preference, directed)
Arguments
preference |
A list for defining the preference functions. |
directed |
Logical, whether to compile the preference functions for directed networks. If missing, the preference functions for both directed and undirected networks will be compiled. |
Value
Returns the input list and their corresponding external pointers.
Creates a wdnet
object from input data.
Description
This function creates a wdnet
object from edgelist
and
edgeweight
or adj
or returns the existing wdnet
object.
For internal usage.
Usage
create_wdnet(
netwk,
edgelist,
edgeweight,
nodegroup,
directed,
adj,
weighted,
...
)
Arguments
netwk |
A |
edgelist |
A two-column matrix representing edges. |
edgeweight |
A vector representing the weights of the edges. |
nodegroup |
A numeric vector of node groups. |
directed |
A logical value indicating whether the network is directed.
Required if |
adj |
An adjacency matrix. |
weighted |
A logical value indicating whether the network is weighted. |
... |
Additional components to be added to the wdnet list. |
Value
A wdnet
object.
Parameters passed to CVXR::solve().
Description
Defined for the convex optimization problems for solving eta
.
Usage
cvxr_control(
solver = "ECOS",
ignore_dcp = FALSE,
warm_start = FALSE,
verbose = FALSE,
parallel = FALSE,
gp = FALSE,
feastol = 1e-05,
reltol = 1e-05,
abstol = 1e-05,
num_iter = NULL,
...
)
Arguments
solver |
(Optional) A string indicating the solver to use. Defaults to "ECOS". |
ignore_dcp |
(Optional) A logical value indicating whether to override the DCP check for a problem. |
warm_start |
(Optional) A logical value indicating whether the previous solver result should be used to warm start. |
verbose |
(Optional) A logical value indicating whether to print additional solver output. |
parallel |
(Optional) A logical value indicating whether to solve in parallel if the problem is separable. |
gp |
(Optional) A logical value indicating whether the problem is a geometric program. Defaults to FALSE. |
feastol |
The feasible tolerance on the primal and dual residual. Defaults to 1e-5. |
reltol |
The relative tolerance on the duality gap. Defaults to 1e-5. |
abstol |
The absolute tolerance on the duality gap. Defaults to 1e-5. |
num_iter |
The maximum number of iterations. |
... |
Additional options that will be passed to the specific solver. In general, these options will override any default settings imposed by CVXR. |
Value
A list containing the parameters.
Examples
control <- cvxr_control(solver = "OSQP", abstol = 1e-5)
Degree-based centrality
Description
Compute the degree centrality measures of the vertices in a weighted and directed network represented through its adjacency matrix.
Usage
degree_c(adj, alpha = 1, mode = "out")
Arguments
adj |
is an adjacency matrix of a weighted and directed network |
alpha |
is a tuning parameter. The value of alpha must be nonnegative. By convention, alpha takes a value from 0 to 1 (default). |
mode |
which mode to compute: "out" (default) or "in"? For undirected networks, this setting is irrelevant. |
Value
a list of node names and associated degree centrality measures
Note
Function degree_c
is an extension of function strength
in
package igraph
and an alternative of function degree_w
in
package tnet
. Function degree_c
uses adjacency matrix as
input.
References
Opsahl, T., Agneessens, F., Skvoretz, J. (2010). Node centrality in weighted networks: Generalizing degree and shortest paths. Social Networks, 32, 245–251.
Zhang, P., Zhao, J. and Yan, J. (2020+) Centrality measures of networks with application to world input-output tables
Degree preserving rewiring.
Description
Rewire a given network to have predetermined assortativity coefficient(s) while preserving node degree.
Usage
dprewire(
netwk,
edgelist,
directed,
adj,
target.assortcoef = list(outout = NULL, outin = NULL, inout = NULL, inin = NULL),
control = list(iteration = 200, nattempts = NULL, history = FALSE, cvxr_control =
cvxr_control(), eta.obj = function(x) 0),
eta
)
Arguments
netwk |
A |
edgelist |
A two column matrix, each row represents an edge of the network. |
directed |
Logical, whether the network is directed or not. It will be
ignored if |
adj |
An adjacency matrix of an unweighted network. |
target.assortcoef |
For directed networks, it is a list represents the
predetermined value or range of assortativity coefficients. For undirected
networks, it is a constant between -1 to 1. It will be ignored if
|
control |
A list of parameters for controlling the rewiring process and
the process for solving
|
eta |
A matrix represents the target network structure. If specified,
|
Details
The algorithm first solves for an appropriate eta
using
target.assortcoef
, eta.obj
, and cvxr_control
, then
proceeds to the rewiring process and rewire the network towards the solved
eta
. If eta
is given, the algorithm will skip the first step.
This function only works for unweighted networks.
Each rewiring attempt samples two rows from edgelist
, for instance
Edge 1:(v_1, v_2) and Edge 2:(v_3, v_4). For directed networks, if the
rewiring attempt is accepted, the sampled edges are rewired as (v_1, v_4),
(v_3, v_2); for undirected networks, the algorithm try to rewire the sampled
edges as {v_1, v_4}, {v_3, v_2} (type 1) or {v_1, v_3}, {v_2, v_4}
(type 2), each with probability 1/2.
Value
Rewired network; assortativity coefficient(s) after each iteration; rewiring history (including the index of sampled edges and rewiring result) and solver results.
Examples
set.seed(123)
netwk1 <- rpanet(1e4, control = rpa_control_scenario(
alpha = 0.4, beta = 0.3, gamma = 0.3
))
## rewire a directed network
target.assortcoef <- list("outout" = -0.2, "outin" = 0.2)
ret1 <- dprewire(
netwk = netwk1,
target.assortcoef = target.assortcoef,
control = list(iteration = 200)
)
plot(ret1$assortcoef$Iteration, ret1$assortcoef$"outout")
plot(ret1$assortcoef$Iteration, ret1$assortcoef$"outin")
## rewire an undirected network
netwk2 <- rpanet(1e4,
control = rpa_control_scenario(
alpha = 0.3, beta = 0.1, gamma = 0.3, xi = 0.3
),
initial.network = list(
directed = FALSE)
)
ret2 <- dprewire(
netwk = netwk2,
target.assortcoef = 0.3,
control = list(
iteration = 300, eta.obj = CVXR::norm2,
history = TRUE
)
)
plot(ret2$assortcoef$Iteration, ret2$assortcoef$Value)
Range of assortativity coefficients.
Description
The assortativity coefficient of a given network may not reach all the values between -1 and 1 via degree preserving rewiring. This function calculates the range of assortativity coefficients achievable through degree preserving rewiring. The algorithm is designed for unweighted networks.
Usage
dprewire.range(
netwk,
edgelist,
adj,
directed,
which.range = c("outout", "outin", "inout", "inin"),
control = cvxr_control(),
target.assortcoef = list(outout = NULL, outin = NULL, inout = NULL, inin = NULL)
)
Arguments
netwk |
A |
edgelist |
A two-column matrix, where each row represents an edge of the network. |
adj |
An adjacency matrix of an unweighted network. |
directed |
Logical, whether the network is directed or not. It will be
ignored if |
which.range |
The type of interested assortativity coefficient. For directed networks, it takes one of the values: "outout", "outin", "inout" and "inin". It will be ignored if the network is undirected. |
control |
A list of parameters passed to |
target.assortcoef |
A list of constraints, it contains the predetermined
value or range imposed on assortativity coefficients other than
|
Details
The ranges are computed using convex optimization. The optimization problems
are defined and solved via the R
package CVXR
. For undirected
networks, the function returns the range of the assortativity coefficient.
For directed networks, the function computes the range of which.range
while other assortativity coefficients are restricted through
target.assortcoef
.
Value
Returns the range of the selected assortativity coefficient and the results from the solver.
Examples
set.seed(123)
netwk <- rpanet(5e3,
control =
rpa_control_scenario(alpha = 0.5, beta = 0.5)
)
ret1 <- dprewire.range(
netwk = netwk, which.range = "outin",
target.assortcoef = list("outout" = c(-0.3, 0.3), "inout" = 0.1)
)
ret1$range
Degree preserving rewiring for directed networks
Description
Degree preserving rewiring towards the target structure eta
.
Usage
dprewire_directed(
edgelist,
eta,
iteration = 200,
nattempts,
rewire.history = FALSE
)
Arguments
edgelist |
A two-column matrix, each row represents a directed edge from the first column to the second column. |
eta |
A matrix generated by |
iteration |
An integer, the number of rewiring iterations, with each
iteration consisting of |
nattempts |
An integer, the number of rewiring attempts for each
iteration. Default value equals the number of rows in |
rewire.history |
Logical, whether the rewiring history should be returned. |
Value
Rewired edgelist, degree based assortativity coefficients after each iteration, rewiring history (including the index of sampled edges and rewiring result). For each rewiring attempt, two rows are sampled form the edgelist, for example Edge1:(v_1, v_2) and Edge2:(v_3, v_4). If the rewiring attempt is accepted, the sampled edges are replaced as (v_1, v_4), (v_3, v_2).
Degree preserving rewiring process for directed networks.
Description
Degree preserving rewiring process for directed networks.
Usage
dprewire_directed_cpp(
iteration,
nattempts,
tnode,
sout,
sin,
tout,
tin,
index_s,
index_t,
eta,
rewire_history
)
Arguments
iteration |
Integer, number of iterations for rewiring attempts. |
nattempts |
Integer, number of rewiring attempts per iteration. |
tnode |
Vector, target node sequence - 1. |
sout |
Vector, source nodes' out-degree. |
sin |
Vector, source nodes' in-degree. |
tout |
Vector, target nodes' out-degree. |
tin |
Vector, target nodes' in-degree. |
index_s |
Index of source nodes' out- and in-degree.
|
index_t |
Index of target nodes' out- and in-degree. |
eta |
Matrix, target structure eta generated by
|
rewire_history |
Logical, whether the rewiring history should be returned. |
Value
Returns target node sequence, four directed assortativity coefficients after each iteration, and rewire history.
Degree preserving rewiring for undirected networks
Description
Degree preserving rewiring towards the target structure eta
.
Usage
dprewire_undirected(
edgelist,
eta,
iteration = 200,
nattempts,
rewire.history = FALSE
)
Arguments
edgelist |
A two column matrix, each row represents an undirected edge. |
eta |
A matrix generated by |
iteration |
An integer, number of rewiring iterations, each iteration
consists of |
nattempts |
An integer, number of rewiring attempts for each iteration.
The default value equals the number of rows in |
rewire.history |
Logical, whether the rewiring history should be returned. |
Value
Rewired edgelist, assortativity coefficient after each iteration, and
rewiring history (including the index of sampled edges and rewiring
result). For each rewiring attempt, two rows are sampled from the
edgelist
, for example Edge1:{v_1, v_2} and Edge2:{v_3, v_4}, the
function try to rewire the sampled edges as {v_1, v_4}, {v_3, v_2}
(rewire type 1) or {v_1, v_3}, {v_2, v_4} (rewire type 2) with
probability 1/2.
Degree preserving rewiring process for undirected networks.
Description
Degree preserving rewiring process for undirected networks.
Usage
dprewire_undirected_cpp(
iteration,
nattempts,
node1,
node2,
degree1,
degree2,
index1,
index2,
e,
rewire_history
)
Arguments
iteration |
Integer, number of iterations for rewiring attempts. |
nattempts |
Integer, number of rewiring attempts per iteration. |
node1 |
Vector, first column of edgelist. |
node2 |
Vector, second column of edgelist. |
degree1 |
Vector, degree of node1 and node2. |
degree2 |
Vector, degree of node2 and node1. degree1 and degree2 are used to calculate assortativity coefficient, i.e., degree correlation. |
index1 |
Index of the first column of edgelist.
|
index2 |
Index of the second column of edgelist. |
e |
Matrix, target structure (eta) generated by
|
rewire_history |
Logical, whether the rewiring history should be returned. |
Value
Returns node sequences, assortativity coefficient after each iteration, and rewiring history.
Compute the assortativity coefficient of a weighted and directed network.
Description
Compute the assortativity coefficient of a weighted and directed network.
Usage
dw_assort(adj, type = c("outin", "inin", "outout", "inout"))
Arguments
adj |
is an adjacency matrix of a weighted and directed network. |
type |
which type of assortativity coefficient to compute: "outin" (default), "inin", "outout" or "inout"? |
Value
a scalar of assortativity coefficient
Note
When the adjacency matrix is binary (i.e., directed but unweighted
networks), dw_assort
returns the assortativity coefficient proposed
in Foster et al. (2010).
References
Foster, J.G., Foster, D.V., Grassberger, P. and Paczuski, M. (2010). Edge direction and the structure of networks. Proceedings of the National Academy of Sciences of the United States, 107(24), 10815–10820.
Yuan, Y. Zhang, P. and Yan, J. (2021). Assortativity coefficients for weighted and directed networks. Journal of Complex Networks, 9(2), cnab017.
Feature based assortativity coefficient
Description
Node feature based assortativity coefficients for weighted and directed networks.
Usage
dw_feature_assort(netwk, f1, f2)
Arguments
netwk |
A |
f1 |
A vector, represents the first feature of existing nodes. Number of
nodes |
f2 |
A vector, represents the second feature of existing nodes. Defined
for directed networks. If |
Value
Directed weighted assortativity coefficients between source nodes'
f1
(or f2
) and target nodes' f2
(or f1
).
Examples
set.seed(123)
adj <- matrix(rbinom(400, 1, 0.2) * sample(1:3, 400, replace = TRUE), 20, 20)
f1 <- runif(20)
f2 <- abs(rnorm(20))
ret <- assortcoef(adj = adj, f1 = f1, f2 = f2)
Convert edgelist and edgeweight to adjacency matrix.
Description
Convert edgelist and edgeweight to adjacency matrix.
Usage
edgelist_to_adj(edgelist, edgeweight, directed = TRUE)
Arguments
edgelist |
A two column matrix representing edges. |
edgeweight |
A vector representing the weight of edges. If |
directed |
Logical, whether the network is directed. |
Value
Returns an adjacency matrix.
Creates a wdnet
object using edgelist
.
Description
Creates a wdnet
object using edgelist
.
Usage
edgelist_to_wdnet(edgelist, edgeweight, directed, nodegroup, ...)
Arguments
edgelist |
A two-column matrix representing the edges. |
edgeweight |
A numeric vector of edge weights with the same length as
the number of rows in edgelist. If |
directed |
Logical, whether the network is directed (TRUE) or undirected (FALSE). |
nodegroup |
A numeric vector of node groups. |
... |
Additional components to be added to the |
Value
A wdnet
object with the specified edgelist
,
edgeweight
and directed
.
Examples
edgelist <- matrix(c(1, 2, 2, 3, 3, 1), ncol = 2, byrow = TRUE)
edgeweight <- c(1, 2, 3)
nodegroup <- c(1, 1, 2)
netwk <- edgelist_to_wdnet(
edgelist = edgelist,
edgeweight = edgeweight,
directed = TRUE,
nodegroup = nodegroup
)
Fill edgeweight into the adjacency matrix.
Defined for function edgelist_to_adj
.
Description
Fill edgeweight into the adjacency matrix.
Defined for function edgelist_to_adj
.
Usage
fill_weight_cpp(adj, edgelist, edgeweight)
Arguments
adj |
An adjacency matrix. |
edgelist |
A two column matrix represents the edgelist. |
edgeweight |
A vector represents the weight of edges. |
Value
Adjacency matrix with edge weight.
Fill missing nodes in the node sequence. Defined for wdnet::rpanet
.
Description
Fill missing nodes in the node sequence. Defined for wdnet::rpanet
.
Usage
find_node_cpp(nodes, edges)
Arguments
nodes |
Source/target nodes, missing nodes are denoted as 0. |
edges |
Sampled edges according to preferential attachment. |
Value
Source/target nodes.
Fill missing values in node sequence. Defined for wdnet::rpanet
.
Description
Fill missing values in node sequence. Defined for wdnet::rpanet
.
Usage
find_node_undirected_cpp(node1, node2, start_edge, end_edge)
Arguments
node1 |
Nodes in the first column of edgelist, i.e., |
node2 |
Nodes in the second column of edgelist, i.e., |
start_edge |
Index of sampled edges, corresponds to the missing nodes in node1 and node2. |
end_edge |
Index of sampled edges, corresponds to the missing nodes in node1 and node2. |
Value
Node sequence.
Get the constraints for the optimization problem. This function is defined
for get_eta_directed()
.
Description
Get the constraints for the optimization problem. This function is defined
for get_eta_directed()
.
Usage
get_constr(constrs, target.assortcoef, rho)
Arguments
constrs |
A list of constraints. |
target.assortcoef |
A list of target assortativity levels. |
rho |
A list of variable objects. |
Value
A list of updated constraints.
Get the node-level joint distributions and some empirical distributions with given edgelist.
Description
Get the node-level joint distributions and some empirical distributions with given edgelist.
Usage
get_dist(edgelist, directed = TRUE, joint_dist = FALSE)
Arguments
edgelist |
A two-column matrix representing the directed edges of a network. |
directed |
Logical, whether the network is directed. |
joint_dist |
Logical, whether to return edge-level distributions. |
Value
A list of distributions and degree vectors.
Compute edge-level distributions for directed networks with respect to desired assortativity level(s).
Description
Compute edge-level distributions for directed networks with respect to desired assortativity level(s).
Usage
get_eta_directed(
edgelist,
target.assortcoef = list(outout = NULL, outin = NULL, inout = NULL, inin = NULL),
eta.obj = function(x) 0,
which.range,
control = cvxr_control()
)
Arguments
edgelist |
A two-column matrix representing the directed edges of a network. |
target.assortcoef |
A list representing the predetermined value or range of assortativity coefficients. |
eta.obj |
A convex function of |
which.range |
Character, "outout", "outin", "inout" or "inin"s, represents the interested degree based assortativity coefficient. |
control |
A list of parameters passed to |
Value
Assortativity coefficients and joint distributions. If
which.range
is specified, the range of the interested coefficient
and the corresponding joint distributions will be returned, provided the
predetermined target.assortcoef
is satisfied.
Compute edge-level distribution for undirected networks with respect to desired assortativity level.
Description
Compute edge-level distribution for undirected networks with respect to desired assortativity level.
Usage
get_eta_undirected(
edgelist,
target.assortcoef = NULL,
eta.obj = function(x) 0,
control = cvxr_control()
)
Arguments
edgelist |
A two column matrix representing the undirected edges of a network. |
target.assortcoef |
Numeric, represents the predetermined assortativity
coefficient. If |
eta.obj |
A convex function of |
control |
A list of parameters passed to |
Value
Assortativity level and corresponding edge-level distribution.
Get the value of an object from the optimization problem. This function is
defined for get_eta_directed()
.
Description
Get the value of an object from the optimization problem. This function is
defined for get_eta_directed()
.
Usage
get_values(object, result, mydist)
Arguments
object |
An object from the optimization problem. |
result |
A list returned from |
mydist |
A list returned from |
Value
Returns the value of the object.
Converts an igraph
object to a wdnet
object
Description
Converts an igraph
object to a wdnet
object
Usage
igraph_to_wdnet(g)
Arguments
g |
An |
Value
A wdnet
object.
Examples
g <- igraph::sample_pa(50)
netwk <- igraph_to_wdnet(g)
Checks whether the input is a rpacontrol
object
Description
Checks whether the input is a rpacontrol
object
Usage
is_rpacontrol(control)
Arguments
control |
A |
Value
Logical, TRUE
if the input is a rpacontrol
object.
Checks if the input is a wdnet
object
Description
Checks if the input is a wdnet
object
Usage
is_wdnet(netwk)
Arguments
netwk |
A |
Value
Logical, TRUE
if argument netwk is a wdnet
object.
Examples
netwk <- rpanet(nstep = 1e3)
is_wdnet(netwk)
Aggregate edgeweight into nodes' strength.
Description
Aggregate edgeweight into nodes' strength.
Usage
node_strength_cpp(snode, tnode, weight, nnode, weighted = TRUE)
Arguments
snode |
Source nodes. |
tnode |
Target nodes. |
weight |
Edgeweight. |
nnode |
Number of nodes. |
weighted |
Logical, true if the edges are weighted, false if not. |
Value
Out-strength and in-strength.
Plots the input network
Description
Plots the input network via igraph::plot.igraph()
.
Usage
## S3 method for class 'wdnet'
plot(x, ...)
Arguments
x |
A |
... |
Additional parameters passed to |
Value
Returns NULL
, invisibly.
Prints rpacontrol
objects
Description
These functions print rpacontrol
objects in the terminal.
print.rpacontrol()
shows only the current controls, whereas
summary.rpacontrol()
includes both specified controls and the
unspecified controls that use default values.
Usage
## S3 method for class 'rpacontrol'
print(x, ...)
## S3 method for class 'rpacontrol'
summary(object, ...)
Arguments
x |
An object of class |
... |
Additional arguments. |
object |
An object of class |
Value
Returns the controls invisibly.
Examples
control <- rpa_control_scenario()
print(control)
Prints the input network
Description
These functions print a network to the terminal.
Usage
## S3 method for class 'wdnet'
print(x, node.attrs = TRUE, edge.attrs = TRUE, max.lines = 5, ...)
## S3 method for class 'wdnet'
summary(object, ...)
Arguments
x |
A |
node.attrs |
Logical, whether to print node attributes, if available. |
edge.attrs |
Logical, whether to print edge attributes, if available. |
max.lines |
Integer, the maximum number of lines of edgelist and node attributes to print. The rest of the output will be truncated. |
... |
Additional arguments. |
object |
The graph of which the summary will be printed. |
Details
summary.wdnet
prints the number of nodes and edges, preference
functions, and whether the network is directed, weighted. print.wdnet
prints the same information, and also lists some edges and node attributes,
if available. Edge scenarios are 0: from initial network; 1: alpha
; 2:
beta
; 3: gamma
; 4: xi
; 5; rho
; 6: reciprocal.
Prints rpacontrol
in terminal
Description
Prints rpacontrol
in terminal
Usage
print_control_details(x, control_name)
Arguments
x |
An object of class |
control_name |
A string, the name of the control component. |
Value
Returns NULL
invisibly.
Prints rpa_control_edgeweight()
in terminal
Description
Prints rpa_control_edgeweight()
in terminal
Usage
print_control_edgeweight(control)
Arguments
control |
A list of control parameters for
|
Value
Returns NULL
invisibly.
Prints rpa_control_newedge()
in terminal
Description
Prints rpa_control_newedge()
in terminal
Usage
print_control_newedge(control)
Arguments
control |
A list of control parameters for
|
Value
Returns NULL
invisibly.
Prints rpa_control_preference()
in terminal
Description
Prints rpa_control_preference()
in terminal
Usage
print_control_preference(control, directed)
Arguments
control |
A list of control parameters for
|
directed |
Logical, whether to print preference functions for directed networks only. If missing, print preference functions for both directed and undirected networks. |
Value
Returns NULL
invisibly.
Prints rpa_control_reciprocal()
in terminal
Description
Prints rpa_control_reciprocal()
in terminal
Usage
print_control_reciprocal(control)
Arguments
control |
A list of control parameters for
|
Value
Returns NULL
invisibly.
Prints rpa_control_scenario()
in terminal
Description
Prints rpa_control_scenario()
in terminal
Usage
print_control_scenario(control)
Arguments
control |
A list of control parameters for
|
Value
Returns NULL
invisibly.
Default controls for rpanet
Description
Default controls for rpanet
Usage
rpa_control_default()
Value
Returns a list of default controls.
Control weight of new edges. Defined for rpanet
.
Description
Control weight of new edges. Defined for rpanet
.
Usage
rpa_control_edgeweight(sampler = NULL)
Arguments
sampler |
A function used for sampling edge weights. If |
Value
A list of class rpacontrol
containing the sampler
function.
Examples
# Sample edge weights from Gamma(5, 0.2).
my_gamma <- function(n) rgamma(n, shape = 5, scale = 0.2)
control <- rpa_control_edgeweight(
sampler = my_gamma
)
Control new edges in each step. Defined for rpanet
.
Description
Control new edges in each step. Defined for rpanet
.
Usage
rpa_control_newedge(
sampler = NULL,
snode.replace = TRUE,
tnode.replace = TRUE,
node.replace = TRUE
)
Arguments
sampler |
A function used for sampling the number of new edges to be
added at each step. If |
snode.replace |
Logical. Determines whether the source nodes in the same step should be sampled with replacement. Defined for directed networks. |
tnode.replace |
Logical. Determines whether the target nodes in the same step should be sampled with replacement. Defined for directed networks. |
node.replace |
Logical. Determines whether the nodes in the same step should be sampled with replacement. Defined for undirected networks. If FALSE, self-loops will not be allowed under beta scenario. |
Value
A list of class rpacontrol
with components sampler
,
snode.replace
, tnode.replace
and node.replace
with
meanings as explained under 'Arguments'.
Examples
my_rpois <- function(n) rpois(n, lambda = 2) + 1
control <- rpa_control_newedge(
sampler = my_rpois,
node.replace = FALSE
)
Set preference function(s). Defined for rpanet
.
Description
Set preference function(s). Defined for rpanet
.
Usage
rpa_control_preference(
ftype = c("default", "customized"),
sparams = c(1, 1, 0, 0, 1),
tparams = c(0, 0, 1, 1, 1),
params = c(1, 1),
spref = "outs + 1",
tpref = "ins + 1",
pref = "s + 1"
)
Arguments
ftype |
Preference function type. Either "default" or "customized".
"customized" preference functions require "binary" or "linear" generation
methods. If using default preference functions, |
sparams |
A numerical vector of length 5 giving the parameters of the
default source preference function. Defined for directed networks.
Probability of choosing an existing node as the source node is proportional
to |
tparams |
A numerical vector of length 5 giving the parameters of the
default target preference function. Defined for directed networks.
Probability of choosing an existing node as the target node is proportional
to |
params |
A numerical vector of length 2 giving the parameters of the
default preference function. Defined for undirected networks. Probability
of choosing an existing node is proportional to |
spref |
Character expression or an object of class |
tpref |
Character expression or an object of class |
pref |
Character expression or an object of class |
Details
If choosing customized preference functions, spref
,
tpref
and pref
will be used and the network generation method
must be "binary" or "linear". spref
(tpref
) defines the
source (target) preference function, it can be a character expression or an
object of class XPtr
.
Character expression; it must be a one-line
C++
style expression ofouts
(node out-strength) andins
(node in-strength). For example,"pow(outs, 2) + 1"
,"pow(outs, 2) + pow(ins, 2) + 1"
, etc. The expression will be used to define anXPtr
viaRcppXPtrUtils::cppXPtr
. TheXPtr
will be passed to the network generation function. The expression must not have variables other thanouts
andins
.'XPtr' an external pointer wrapped in an object of class
XPtr
defined viaRcppXPtrUtils::cppXPtr
. An example for defining anXPtr
withC++
source code is included in Examples. For more information about passing function pointers, see https://gallery.rcpp.org/articles/passing-cpp-function-pointers-rcppxptrutils/. Please note the suppliedC++
function accepts twodouble
arguments and returns adouble
. The first and second arguments represent node out- and in-strength, respectively. Note that theXPtr
will be invalid and cannot be used to control network generation in another separate R session. Therefore, we recommend preserving the source code of your preference function for future use.
pref
is defined analogously. If using character expression, it must
be a one-line C++
style expression of s
(node strength). If
using XPtr
, the supplied C++
function accepts only one
double
argument and returns a double
.
Value
A list of class rpacontrol
with components ftype
,
sparams
, tparams
, params
or ftype
,
spref
, tpref
, pref
with function pointers
spref.pointer
, tpref.pointer
, pref.pointer
.
Examples
# Set source preference as out-strength^2 + in-strength + 1,
# target preference as out-strength + in-strength^2 + 1.
# 1. use default preference functions
ctr1 <- rpa_control_preference(
ftype = "default",
sparams = c(1, 2, 1, 1, 1), tparams = c(1, 1, 1, 2, 1)
)
# 2. use character expressions
ctr2 <- rpa_control_preference(
ftype = "customized",
spref = "pow(outs, 2) + ins + 1", tpref = "outs + pow(ins, 2) + 1"
)
# 3. define XPtr's with C++ source code
spref.pointer <- RcppXPtrUtils::cppXPtr(
code =
"double spref(double outs, double ins) {return pow(outs, 2) + ins + 1;}"
)
tpref.pointer <- RcppXPtrUtils::cppXPtr(
code =
"double tpref(double outs, double ins) {return outs + pow(ins, 2) + 1;}"
)
ctr3 <- rpa_control_preference(
ftype = "customized",
spref = spref.pointer,
tpref = tpref.pointer
)
ret <- rpanet(1e5, control = ctr3)
Control reciprocal edges. Defined for rpanet
.
Description
Control reciprocal edges. Defined for rpanet
.
Usage
rpa_control_reciprocal(
group.prob = NULL,
recip.prob = NULL,
selfloop.recip = FALSE
)
Arguments
group.prob |
A vector of probability weights for sampling the group of
new nodes. Defined for directed networks. Groups are from 1 to
|
recip.prob |
A square matrix giving the probability of adding a
reciprocal edge after a new edge is introduced. Defined for directed
networks. Its element |
selfloop.recip |
Logical, whether reciprocal edge of self-loops are allowed. |
Value
A list of class rpacontrol
with components group.prob
,
recip.prob
, and selfloop.recip
with meanings as explained
under 'Arguments'.
Examples
control <- rpa_control_reciprocal(
group.prob = c(0.4, 0.6),
recip.prob = matrix(runif(4), ncol = 2)
)
Control edge scenarios. Defined for rpanet
.
Description
Control edge scenarios. Defined for rpanet
.
Usage
rpa_control_scenario(
alpha = 1,
beta = 0,
gamma = 0,
xi = 0,
rho = 0,
beta.loop = TRUE,
source.first = TRUE
)
Arguments
alpha |
Probability of adding an edge from a new node to an existing node. |
beta |
Probability of adding an edge between existing nodes. |
gamma |
Probability of adding an edge from an existing node to a new node. |
xi |
Probability of adding an edge between two new nodes. |
rho |
Probability of adding a new node with a self-loop. |
beta.loop |
Logical. Determines whether self-loops are allowed under the
beta scenario. Default value is |
source.first |
Logical. Defined for |
Value
A list of class rpacontrol
with components alpha
,
beta
, gamma
, xi
, rho
, beta.loop
and
source.first
with meanings as explained under 'Arguments'.
Examples
control <- rpa_control_scenario(alpha = 0.5, beta = 0.5, beta.loop = FALSE)
rpacontrol: Controls the Preferential Attachment (PA) Network Generation Process
Description
The rpacontrol
object is designed to control the Preferential
Attachment (PA) network generation process within the rpanet()
function. It can have the following components:
-
scenario
: controls the edge scenarios at each step. For more information, please refer torpa_control_scenario()
. -
edgeweight
: controls the weight of the edges; seerpa_control_edgeweight()
for details. -
newedge
: controls the creation of new edges at each step; seerpa_control_newedge()
for details. -
preference
: sets preference functions; seerpa_control_preference()
for details. -
reciprocal
: controls the creation of reciprocal edges; seerpa_control_reciprocal()
for details.
Generate PA networks.
Description
Generate preferential attachment (PA) networks with linear or non-linear preference functions.
Usage
rpanet(
nstep,
initial.network = list(edgelist = matrix(c(1, 2), nrow = 1), edgeweight = 1, directed =
TRUE),
control,
method = c("binary", "linear", "bagx", "bag")
)
Arguments
nstep |
Number of steps. |
initial.network |
A |
control |
An |
method |
Which method to use: |
Value
Returns a wdnet
object that includes the following components:
-
directed
: Logical, whether the network is directed. -
weighted
: Logical, whether the network is weighted. -
edgelist
: A two-column matrix representing the edges. -
edge.attr
: A data frame including edge weights and edge scenarios (0: from initial network; 1:alpha
; 2:beta
; 3:gamma
; 4:xi
; 5;rho
; 6: reciprocal edge). -
node.attr
: A data frame including node out- and in-strength, node source and target preference scores (for directed networks), node strength and preference scores (for undirected networks), and node group (if applicable). -
newedge
: The number of new edges at each step, including reciprocal edges. -
control
: Anrpacontrol
object that is used to generate the network.
Note
The binary
method implements binary search algorithm;
linear
represents linear search algorithm; bag
method
implements the algorithm from Wan et al. (2017); bagx
puts all the
edges into a bag, then samples edges and find the source/target node of the
sampled edge.
References
Wan P, Wang T, Davis RA, Resnick SI (2017). Fitting the Linear Preferential Attachment Model. Electronic Journal of Statistics, 11(2), 3738–3780.
Examples
# Control edge scenario and edge weight through rpa_control_scenario()
# and rpa_control_edgeweight(), respectively,
# while keeping rpa_control_newedge(),
# rpa_control_preference() and rpa_control_reciprocal() as default.
set.seed(123)
control <- rpa_control_scenario(alpha = 0.5, beta = 0.5) +
rpa_control_edgeweight(
sampler = function(n) rgamma(n, shape = 5, scale = 0.2)
)
ret1 <- rpanet(nstep = 1e3, control = control)
# In addition, set node groups and probability of creating reciprocal edges.
control <- control + rpa_control_reciprocal(
group.prob = c(0.4, 0.6),
recip.prob = matrix(runif(4), ncol = 2)
)
ret2 <- rpanet(nstep = 1e3, control = control)
# Further, set the number of new edges in each step as Poisson(2) + 1 and use
# ret2 as a seed network.
control <- control + rpa_control_newedge(
sampler = function(n) rpois(n, lambda = 2) + 1
)
ret3 <- rpanet(nstep = 1e3, initial.network = ret2, control = control)
Preferential attachment algorithm for simple situations, i.e., edge weight equals 1, each step adds one new edge.
Description
Preferential attachment algorithm for simple situations, i.e., edge weight equals 1, each step adds one new edge.
Usage
rpanet_bag_cpp(
snode,
tnode,
scenario,
nnode,
nedge,
delta_out,
delta_in,
directed
)
Arguments
snode |
Source nodes. |
tnode |
Target nodes. |
scenario |
Sequence of alpha, beta, gamma, xi, rho scenarios. |
nnode |
Number of nodes in seed network. |
nedge |
Number of edges in seed network. |
delta_out |
Tuning parameter. |
delta_in |
Tuning parameter. |
directed |
Whether the network is directed. |
Value
Returns a list that includes the total number of nodes, sequences of source and target nodes.
Preferential attachment network generation.
Description
Preferential attachment network generation.
Usage
rpanet_binary_directed(
nstep,
m,
new_node_id,
new_edge_id,
source_node,
target_node,
outs,
ins,
edgeweight,
scenario,
sample_recip,
node_group,
spref_vec,
tpref_vec,
control
)
Arguments
nstep |
Number of steps. |
m |
Number of new edges in each step. |
new_node_id |
New node ID. |
new_edge_id |
New edge ID. |
source_node |
Sequence of source nodes. |
target_node |
Sequence of target nodes. |
outs |
Sequence of out-strength. |
ins |
Sequence of in-strength. |
edgeweight |
Weight of existing and new edges. |
scenario |
Scenario of existing and new edges. |
sample_recip |
Logical, whether reciprocal edges will be added. |
node_group |
Sequence of node group. |
spref_vec |
Sequence of node source preference. |
tpref_vec |
Sequence of node target preference. |
control |
List of controlling arguments. |
Value
Sampled network.
Preferential attachment network generation.
Description
Preferential attachment network generation.
Usage
rpanet_binary_undirected_cpp(
nstep,
m,
new_node_id,
new_edge_id,
node_vec1,
node_vec2,
s,
edgeweight,
scenario,
pref_vec,
control
)
Arguments
nstep |
Number of steps. |
m |
Number of new edges in each step. |
new_node_id |
New node ID. |
new_edge_id |
New edge ID. |
node_vec1 |
Sequence of nodes in the first column of edgelist. |
node_vec2 |
Sequence of nodes in the second column of edgelist. |
s |
Sequence of node strength. |
edgeweight |
Weight of existing and new edges. |
scenario |
Scenario of existing and new edges. |
pref_vec |
Sequence of node preference. |
control |
List of controlling arguments. |
Value
Sampled network.
Internal functions for generating PA networks
Description
These functions generate a PA network with linear (rpanet_simple
) or
non-linear (rpanet_general
) preference functions
Usage
rpanet_general(
nstep,
initial.network,
control,
m,
sum_m,
w,
nnode,
nedge,
method,
sample.recip
)
rpanet_simple(
nstep,
initial.network,
control,
m,
sum_m,
w,
ex_node,
ex_edge,
method
)
Arguments
nstep |
Number of steps when generating a network. |
initial.network |
A |
control |
A list of parameters that controls the PA generation process.
The default value is |
m |
Integer vector, number of new edges in each step. |
sum_m |
Integer, summation of |
w |
Vector, weight of new edges. |
nnode |
Integer, number of nodes in |
nedge |
Integer, number of edges in |
method |
Which method to use when generating PA networks: "binary" or "linear". |
sample.recip |
Whether reciprocal edges will be added. |
Value
Returns a wdnet
object that includes the following components:
-
directed
: Logical, whether the network is directed. -
weighted
: Logical, whether the network is weighted. -
edgelist
: A two-column matrix representing the edges. -
edge.attr
: A data frame including edge weights and edge scenarios (0: from initial network; 1:alpha
; 2:beta
; 3:gamma
; 4:xi
; 5;rho
; 6: reciprocal edge). -
node.attr
: A data frame including node out- and in-strength, node source and target preference scores (for directed networks), node strength and preference scores (for undirected networks), and node group (if applicable). -
newedge
: The number of new edges at each step, including reciprocal edges. -
control
: Anrpacontrol
object that is used to generate the network.
Preferential attachment network generation.
Description
Preferential attachment network generation.
Usage
rpanet_linear_directed_cpp(
nstep,
m,
new_node_id,
new_edge_id,
source_node,
target_node,
outs,
ins,
edgeweight,
scenario,
sample_recip,
node_group,
spref_vec,
tpref_vec,
control
)
Arguments
nstep |
Number of steps. |
m |
Number of new edges in each step. |
new_node_id |
New node ID. |
new_edge_id |
New edge ID. |
source_node |
Sequence of source nodes. |
target_node |
Sequence of target nodes. |
outs |
Sequence of out-strength. |
ins |
Sequence of in-strength. |
edgeweight |
Weight of existing and new edges. |
scenario |
Scenario of existing and new edges. |
sample_recip |
Logical, whether reciprocal edges will be added. |
node_group |
Sequence of node group. |
spref_vec |
Sequence of node source preference. |
tpref_vec |
Sequence of node target preference. |
control |
List of controlling arguments. |
Value
Sampled network.
Preferential attachment network generation.
Description
Preferential attachment network generation.
Usage
rpanet_linear_undirected_cpp(
nstep,
m,
new_node_id,
new_edge_id,
node_vec1,
node_vec2,
s,
edgeweight,
scenario,
pref_vec,
control
)
Arguments
nstep |
Number of steps. |
m |
Number of new edges in each step. |
new_node_id |
New node ID. |
new_edge_id |
New edge ID. |
node_vec1 |
Sequence of nodes in the first column of edgelist. |
node_vec2 |
Sequence of nodes in the second column of edgelist. |
s |
Sequence of node strength. |
edgeweight |
Weight of existing and new edges. |
scenario |
Scenario of existing and new edges. |
pref_vec |
Sequence of node preference. |
control |
List of controlling arguments. |
Value
Sampled network.
Uniformly draw a node from existing nodes for each time step.
Defined for wdnet::rpanet()
.
Description
Uniformly draw a node from existing nodes for each time step.
Defined for wdnet::rpanet()
.
Usage
sample_node_cpp(total_node)
Arguments
total_node |
Number of existing nodes at each time step. |
Value
Sampled nodes.
Converts a wdnet
object to an igraph
object
Description
Converts a wdnet
object to an igraph
object
Usage
wdnet_to_igraph(netwk)
Arguments
netwk |
A |
Value
An igraph
object.
Examples
netwk <- rpanet(nstep = 1e3)
g <- wdnet_to_igraph(netwk)
Weighted PageRank centrality
Description
Compute the weighted PageRank centrality measures of the vertices in a weighted and directed network represented through its adjacency matrix.
Usage
wpr(adj, gamma = 0.85, theta = 1, prior.info)
Arguments
adj |
is an adjacency matrix of a weighted and directed network |
gamma |
is the damping factor; it takes 0.85 (default) if not given. |
theta |
is a tuning parameter leveraging node degree and strength; theta = 0 does not consider edge weight; theta = 1 (default) fully considers edge weight. |
prior.info |
vertex-specific prior information for restarting when
arriving at a sink. When it is not given ( |
Value
a list of node names with corresponding weighted PageRank scores
Note
Function wpr
is an extension of function page_rank
in
package igraph
.
References
Zhang, P., Wang, T. and Yan, J. (2022) PageRank centrality and algorithms for weighted, directed networks with applications to World Input-Output Tables. Physica A: Statistical Mechanics and its Applications, 586, 126438.