Introduction to the package

Author

George G. Vega Yon

Published

December 5, 2024

Modified

December 5, 2024

\[ a_i = \left\{\begin{array}{ll} 1 &\mbox{if } \tau_i\leq E_i \\ 0 & \mbox{Otherwise} \end{array}\right. \qquad E_i \equiv \frac{\sum_{j\neq i}\mathbf{X}_{ij}a_j}{\sum_{j\neq i}\mathbf{X}_{ij}} \]

Where \(E_i\) is i’s exposure to the innovation and \(\mathbf{X}\) is the adjacency matrix (the network).

netdiffuseR

Overview

netdiffuseR is an R package that:

  • Is designed for Visualizing, Analyzing and Simulating network diffusion data (in general).

  • Depends on some pretty popular packages:

  • RcppArmadillo: So it’s fast,

  • Matrix: So it’s big,

  • statnet and igraph: So it’s not from scratch

  • Can handle big graphs, e.g., an adjacency matrix with more than 4 billion elements (PR for RcppArmadillo)

  • Already on CRAN with ~6,000 downloads since its first version, Feb 2016,

  • A lot of features to make it easy to read network (dynamic) data, making it a nice companion of other net packages.

Datasets

  • netdiffuseR has the three classic Diffusion Network Datasets:

    • medInnovationsDiffNet Doctors and the innovation of Tetracycline (1955).
    • brfarmersDiffNet Brazilian farmers and the innovation of Hybrid Corn Seed (1966).
    • kfamilyDiffNet Korean women and Family Planning methods (1973).
    brfarmersDiffNet
    # Dynamic network of class -diffnet-
    #  Name               : Brazilian Farmers
    #  Behavior           : Adoption of Hybrid Corn Seeds
    #  # of nodes         : 692 (1001, 1002, 1004, 1005, 1007, 1009, 1010, 1020, ...)
    #  # of time periods  : 21 (1946 - 1966)
    #  Type               : directed
    #  Num of behaviors   : 1
    #  Final prevalence   : 1.00
    #  Static attributes  : village, idold, age, liveout, visits, contact, coo... (146)
    #  Dynamic attributes : -
    medInnovationsDiffNet
    # Dynamic network of class -diffnet-
    #  Name               : Medical Innovation
    #  Behavior           : Adoption of Tetracycline
    #  # of nodes         : 125 (1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, ...)
    #  # of time periods  : 18 (1 - 18)
    #  Type               : directed
    #  Num of behaviors   : 1
    #  Final prevalence   : 1.00
    #  Static attributes  : city, detail, meet, coll, attend, proage, length, ... (58)
    #  Dynamic attributes : -
    kfamilyDiffNet
    # Dynamic network of class -diffnet-
    #  Name               : Korean Family Planning
    #  Behavior           : Family Planning Methods
    #  # of nodes         : 1047 (10002, 10003, 10005, 10007, 10010, 10011, 10012, 10014, ...)
    #  # of time periods  : 11 (1 - 11)
    #  Type               : directed
    #  Num of behaviors   : 1
    #  Final prevalence   : 1.00
    #  Static attributes  : village, recno1, studno1, area1, id1, nmage1, nmag... (430)
    #  Dynamic attributes : -

Visualization methods

set.seed(12315)
x <- rdiffnet(
  n = 400, t = 6,
  rgraph.args    = list(k=6, p=.3),
  seed.graph     = "small-world",
  seed.nodes     = "central",
  rewire         = FALSE,
  threshold.dist = 1/4
  )
x
# Dynamic network of class -diffnet-
#  Name               : A diffusion network
#  Behavior           : Random contagion
#  # of nodes         : 400 (1, 2, 3, 4, 5, 6, 7, 8, ...)
#  # of time periods  : 6 (1 - 6)
#  Type               : directed
#  Num of behaviors   : 1
#  Final prevalence   : 0.95
#  Static attributes  : real_threshold (1)
#  Dynamic attributes : -

Diffusion networks can visualized using many methods included in the package. Here are some of them:

plot(x)

plot_diffnet(x)

plot_diffnet2(x)

plot_adopters(x)

plot_threshold(x)

plot_infectsuscep(x, K=2)
# Warning in plot_infectsuscep.list(graph$graph, graph$toa, t0, normalize, : When
# applying logscale some observations are missing.

plot_hazard(x)

Problems

  1. Using the diffnet object in intro.rda, use the function plot_threshold specifying shapes and colors according to the variables ItrustMyFriends and Age. Do you see any pattern? (solution script and solution plot)