add_pa_graph {DiagrammeR} | R Documentation

## Add a preferential attachment graph

### Description

To an existing graph object, add a graph built according to the Barabasi-Albert model, which uses preferential attachment in its stochastic algorithm.

### Usage

    add_pa_graph(graph, n, m = NULL, power = 1, out_dist = NULL,
      use_total_degree = FALSE, zero_appeal = 1, algo = "psumtree")

### Arguments

`graph` | a graph object of class `dgr_graph`.
`n` | the number of nodes comprising the preferential attachment graph.
`m` | the number of edges to add in each time step.
`power` | the power of the preferential attachment. The default value of `1` indicates a linear preferential attachment.
`out_dist` | a numeric vector that provides the distribution of the number of edges to add in each time step.
`use_total_degree` | a logical value (default is `TRUE`) that governs whether the total degree should be used for calculating the citation probability. If `FALSE`, the indegree is used.
`zero_appeal` | a measure of the attractiveness of the nodes with no adjacent edges.

`algo`

the algorithm to use to generate the graph. The available options are `psumtree`, `psumtree-multiple`, and `bag`. With the `psumtree` algorithm, a partial prefix-sum tree is used to to create the graph. Any values for `power` and `zero_appeal` can be provided and this algorithm never generates multiple edges. The `psumtree-multiple` algorithm also uses a partial prefix-sum tree but the difference here is that multiple edges are allowed. The `bag` algorithm places the node IDs into a bag as many times as their in-degree (plus once more). The required number of cited nodes are drawn from the bag with replacement. Multiple edges may be produced using this method (it is not disallowed).

### Examples

    # Create an undirected PA
    # graph with 100 nodes, adding
    # 2 edges at every time step
    pa_graph <-
      create_graph(
        directed = FALSE) %>%
      add_pa_graph(
        n = 100,
        m = 1)

    # Get a count of nodes
    pa_graph %>% node_count()
    #> [1] 100

    # Get a count of edges
    pa_graph %>% edge_count()
    #> [1] 99

[Package DiagrammeR version 0.9.2 Index]