SkillAgentSearch skills...

NetdiffuseR

netdiffuseR: Analysis of Diffusion and Contagion Processes on Networks

Install / Use

/learn @USCCANA/NetdiffuseR
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

R-CMD-check codecov.io CRAN_Status_Badge DOI Dependencies USC's Department of Preventive Medicine

<h1>

netdiffuseR: Analysis of Diffusion and Contagion Processes on Networks<img src="man/figures/netdiffuser-logo.svg" style="max-width:200px;width:50%;" align="right">

</h1>

This package contains functions useful for analyzing network data for diffusion of innovations applications.

The package was developed as part of the paper Thomas W. Valente, Stephanie R. Dyal, Kar-Hai Chu, Heather Wipfli, Kayo Fujimoto, Diffusion of innovations theory applied to global tobacco control treaty ratification, Social Science & Medicine, Volume 145, November 2015, Pages 89-97, ISSN 0277-9536 (available here).

From the description:

Empirical statistical analysis, visualization and simulation of diffusion and contagion processes on networks. The package implements algorithms for calculating network diffusion statistics such as transmission rate, hazard rates, exposure models, network threshold levels, infectiousness (contagion), and susceptibility. The package is inspired by work published in Valente, et al., (2015); Valente (1995), Myers (2000), Iyengar and others (2011), Burt (1987); among others.

Acknowledgements: netdiffuseR was created with the support of grant R01 CA157577 from the National Cancer Institute/National Institutes of Health.

citation(package="netdiffuseR")
To cite netdiffuseR in publications use the following paper:

  Valente TW, Vega Yon GG. Diffusion/Contagion Processes on Social
  Networks. Health Education & Behavior. 2020;47(2):235-248.
  doi:10.1177/1090198120901497

And the actual R package:

  Vega Yon G, Olivera Morales A, Valente T (2025). _netdiffuseR:
  Analysis of Diffusion and Contagion Processes on Networks_.
  doi:10.5281/zenodo.1039317 <https://doi.org/10.5281/zenodo.1039317>,
  R package version 1.24.1, <https://github.com/USCCANA/netdiffuseR>.

To see these entries in BibTeX format, use 'print(<citation>,
bibtex=TRUE)', 'toBibtex(.)', or set
'options(citation.bibtex.max=999)'.

News

Changelog can be view here.

Installation

CRAN version

To get the CRAN (stable) version of the package, simple type

install.packages("netdiffuseR")

Bleeding edge version

If you want the latest (unstable) version of netdiffuseR, using the remotes package, you can install netdiffuseR dev version as follows

remotes::install_github('USCCANA/netdiffuseR', build_vignettes = TRUE)

You can skip building vignettes by setting build_vignettes = FALSE (so it is not required). You can also get the package (pre-built binaries) from our R-Universe repository (recommended):

install.packages(
  'epiworldR',
  repos = c(
    'https://uofuepibio.r-universe.dev',
    'https://cloud.r-project.org'
  )
)

Tutorials

Since starting netdiffuseR, we have done a couple of workshops at Sunbelt and NASN. Past and current workshops can be found at https://github.com/USCCANA/netdiffuser-workshop

Presentations

  • ic2s2 2016 Evanston, IL: https://github.com/USCCANA/netdiffuser-ic2s22016 (poster)
  • useR! 2016 Stanford, CA: https://github.com/USCCANA/netdiffuser-user2016 (slides)
  • useR! 2016: https://github.com/USCCANA/netdiffuser-user2016

Examples

This example has been taken from the package’s vignettes:

library(netdiffuseR)
#> Thank you for using netdiffuseR! Please consider citing it in your work.
#> You can find the citation information by running
#>   citation("netdiffuseR")
#> 
#> Attaching package: 'netdiffuseR'
#> The following object is masked from 'package:base':
#> 
#>     %*%

Infectiousness and Susceptibility

# Generating a random graph
set.seed(1234)
n <- 100
nper <- 20
graph <- rgraph_er(n, nper, .5)
toa <- sample(c(1:(1+nper-1), NA), n, TRUE)
head(toa)
#> [1] 16  3 14  3 13  5

# Creating a diffnet object
diffnet <- as_diffnet(graph, toa)
diffnet
#> Dynamic network of class -diffnet-
#>  Name               : Diffusion Network
#>  Behavior           : Unknown
#>  # of nodes         : 100 (1, 2, 3, 4, 5, 6, 7, 8, ...)
#>  # of time periods  : 20 (1 - 20)
#>  Type               : directed
#>  Num of behaviors   : 1
#>  Final prevalence   : 0.95
#>  Static attributes  : -
#>  Dynamic attributes : -
summary(diffnet)
#> Diffusion network summary statistics
#>  Name     :  Diffusion Network 
#>  Behavior : Unknown
#> -----------------------------------------------------------------------------
#>  Period   Adopters   Cum Adopt. (%)   Hazard Rate   Density   Moran's I (sd)  
#> -------- ---------- ---------------- ------------- --------- ---------------- 
#>        1          8         8 (0.08)             -      0.50 -0.01 (0.00)     
#>        2          3        11 (0.11)          0.03      0.50 -0.01 (0.00)     
#>        3          6        17 (0.17)          0.07      0.51 -0.01 (0.00)     
#>        4          3        20 (0.20)          0.04      0.49 -0.01 (0.00)     
#>        5          9        29 (0.29)          0.11      0.50 -0.01 (0.00)     
#>        6          5        34 (0.34)          0.07      0.50 -0.01 (0.00)     
#>        7          2        36 (0.36)          0.03      0.51 -0.01 (0.00)     
#>        8          3        39 (0.39)          0.05      0.50 -0.01 (0.00)     
#>        9          5        44 (0.44)          0.08      0.50 -0.01 (0.00)     
#>       10          1        45 (0.45)          0.02      0.49 -0.01 (0.00)     
#>       11          3        48 (0.48)          0.05      0.50 -0.01 (0.00)     
#>       12          6        54 (0.54)          0.12      0.50 -0.01 (0.00)     
#>       13          8        62 (0.62)          0.17      0.50 -0.01 (0.00)     
#>       14          9        71 (0.71)          0.24      0.50 -0.01 (0.00)     
#>       15          5        76 (0.76)          0.17      0.50 -0.00 (0.00) **  
#>       16          7        83 (0.83)          0.29      0.50 -0.01 (0.00)     
#>       17          5        88 (0.88)          0.29      0.49 -0.00 (0.00) *** 
#>       18          4        92 (0.92)          0.33      0.50 -0.01 (0.00)     
#>       19          1        93 (0.93)          0.12      0.50 -0.01 (0.00)     
#>       20          2        95 (0.95)          0.29      0.50 -0.01 (0.00)     
#> ----------------------------------------------------------------------------- 
#>  Left censoring  : 0.08 (8) 
#>  Right centoring : 0.05 (5) 
#>  # of nodes      : 100
#> 
#>  Moran's I was computed on contemporaneous autocorrelation using 1/geodesic
#>  values. Significane levels  *** <= .01, ** <= .05, * <= .1.

# Visualizing distribution of suscep/infect
out <- plot_infectsuscep(diffnet, bins = 20,K=5, logscale = FALSE, h=.01)

<img src="man/figures/README-plot_infectsuscept-1.png" style="width:100.0%" />

out <- plot_infectsuscep(diffnet, bins = 20,K=5, logscale = TRUE,
                         exclude.zeros = TRUE, h=1)
#> Warning in plot_infectsuscep.list(graph$graph, graph$toa, t0, normalize, : When
#> applying logscale some observations are missing.

<img src="man/figures/README-plot_infectsuscept-2.png" style="width:100.0%" />

Threshold

# Generating a random graph
set.seed(123)
diffnet <- rdiffnet(500, 20,
                    seed.nodes = "random",
                    rgraph.args = list(m=3),
                    threshold.dist = function(x) runif(1, .3, .7))
diffnet
#> Dynamic network of class -diffnet-
#>  Name               : A diffusion network
#>  Behavior           : Random contagion
#>  # of nodes         : 500 (1, 2, 3, 4, 5, 6, 7, 8, ...)
#>  # of time periods  : 20 (1 - 20)
#>  Type               : directed
#>  Num of behaviors   : 1
#>  Final prevalence   : 1.00
#>  Static attributes  : real_threshold (1)
#>  Dynamic attributes : -

# Threshold with fixed vertex size
plot_threshold(diffnet)

<img src="man/figures/README-BoringThreshold-1.png" style="width:100.0%" />

Using more features

data("medInnovationsDiffNet")
set.seed(131)
plot_threshold(
  medInnovationsDiffNet,
  vertex.color     = viridisLite::inferno(4)[medInnovationsDiffNet[["city"]]],
  vertex.sides     = medInnovationsDiffNet[["city"]] + 2,
  sub = "Note: Vertices' sizes and shapes given by degree and city respectively",
  jitter.factor = c(1,1), jitter.amount = c(.25,.025)
)
#> Warning in (function (graph, expo, toa, include_censored = FALSE, t0 = min(toa,
#> : -vertex.sides- will be coerced to integer.

<img src="man/figures/README-NiceThreshold-1.png" style="width:100.0%" />

Adoption rate

plot_adopters(diffnet)
<img src="man/figures/README-Adopters-1.png" style="width:100.0%" />

Hazard rate

hazard_rate(diffnet)
<img src="man/figures/README-Hazard-1.png" style="width:100.0%" />

Diffusion process

plot_diffnet(medInnovationsDiffNet, slices=c(1,9,8))
<img src="man/figures/README-plot_diffnet-1.png" style="width:100.0%" />
diffnet.toa(brfarmersDiffNet)[brfarmersDiffNet$toa >= 1965] <- 

Related Skills

View on GitHub
GitHub Stars91
CategoryDevelopment
Updated7d ago
Forks22

Languages

R

Security Score

85/100

Audited on Mar 27, 2026

No findings