rpanet {wdnet}R Documentation

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 wdnet object or a list representing the initial network. By default, initial.network has one directed edge from node 1 to node 2 with weight 1. It can contain the following components: a two-column matrix edgelist representing the edges; a vector edgeweight representing the weight of edges; a logical argument directed indicating whether the initial network is directed. If edgeweight is not specified, all edges from the initial network are assumed to have weight 1. In addition, an integer vector nodegroup can be added to the list for specifing node groups; nodegroup is defined for directed networks, if NULL, all nodes from the seed network are assumed to be in group 1.

control

An rpacontrol object controlling the PA network generation process. If not specified, all the control parameters will be set to default. For more details, see rpa_control_scenario(), rpa_control_newedge(), rpa_control_edgeweight(), rpa_control_preference and rpa_control_reciprocal(). Under the default setup, at each step, a new edge of weight 1 is added from a new node A to an existing node B (alpha scenario), where B is chosen with probability proportional to its in-strength + 1.

method

Which method to use: binary, linear, bagx or bag. For bag and bagx methods, beta.loop must be TRUE, default preference functions must be used, and sparams should be set to c(1, 1, 0, 0, a), tparams to c(0, 0, 1, 1, b), and param to c(1, c), where a, b, and c are non-negative constants; furthermore, reciprocal edges and sampling without replacement are not considered, i.e., option rpa_control_reciprocal() must be set as default, snode.replace, tnode.replace and node.replace must be TRUE. In addition, bag method only works for unweighted networks and does not consider multiple edges, i.e., rpa_control_edgeweight() and rpa_control_newedge() must be set as default.

Value

Returns a wdnet object that includes the following components:

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

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)


[Package wdnet version 1.2.3 Index]