netdiffuseR
netdiffuseR: Analysis of Diffusion and Contagion Processes on Networks
Science Score: 67.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 9 DOI reference(s) in README -
✓Academic publication links
Links to: zenodo.org -
✓Committers with academic emails
2 of 7 committers (28.6%) from academic institutions -
✓Institutional organization owner
Organization usccana has institutional domain (cana.usc.edu) -
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.7%) to scientific vocabulary
Keywords
Repository
netdiffuseR: Analysis of Diffusion and Contagion Processes on Networks
Basic Info
- Host: GitHub
- Owner: USCCANA
- License: other
- Language: R
- Default Branch: master
- Homepage: https://USCCANA.github.io/netdiffuseR
- Size: 99.9 MB
Statistics
- Stars: 89
- Watchers: 14
- Forks: 22
- Open Issues: 30
- Releases: 9
Topics
Metadata Files
README.md
netdiffuseR: Analysis of Diffusion and Contagion Processes on
Networks
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.
r
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.23.0, <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
r
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
r
remotes::install_github('USCCANA/netdiffuseR', build_vignettes = TRUE)
You can skip building vignettes by setting build_vignettes = FALSE (so
it is not required).
For the case of OSX users, there seems to be a problem when installing
packages depending on Rcpp. This issue, developed
here, can be solved
by open the terminal and typing the following
sh
curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /
before installing the package through devtools.
Binary versions
For the case of windows and mac users, they can find binary versions of the package here, netdiffuseR1…zip, and netdiffuseR1…tgz respectively. They can install this directly as follows (using the 1.16.3.29 version):
Install dependencies from CRAN
r > install.packages(c("igraph", "Matrix", "SparseM", "RcppArmadillo", "sna"), dependencies=TRUE)Download the binary version and install it as follows:
``` r
install.packages("netdiffuseR_1.16.3.29.zip", repos=NULL) ```
For windows users, and for Mac users:
``` r
install.packages("netdiffuseR_1.16.3.29.tgz", repos=NULL) ```
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:
r
library(netdiffuseR)
Attaching package: 'netdiffuseR'
The following object is masked from 'package:base':
%*%
Infectiousness and Susceptibility
``` r
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
``` r
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 : -
r
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.
``` r
Visualizing distribution of suscep/infect
out <- plot_infectsuscep(diffnet, bins = 20,K=5, logscale = FALSE, h=.01) ```

r
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.

Threshold
``` r
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 : -
``` r
Threshold with fixed vertex size
plot_threshold(diffnet) ```

Using more features
r
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.

Adoption rate
r
plot_adopters(diffnet)

Hazard rate
r
hazard_rate(diffnet)

Diffusion process
r
plot_diffnet(medInnovationsDiffNet, slices=c(1,9,8))

r
diffnet.toa(brfarmersDiffNet)[brfarmersDiffNet$toa >= 1965] <- NA
plot_diffnet2(brfarmersDiffNet, vertex.size = "indegree")

``` r set.seed(1231)
Random scale-free diffusion network
x <- rdiffnet(1000, 4, seed.graph="scale-free", seed.p.adopt = .025, rewire = FALSE, seed.nodes = "central", rgraph.arg=list(self=FALSE, m=4), threshold.dist = function(id) runif(1,.2,.4))
Diffusion map (no random toa)
dm0 <- diffusionMap(x, kde2d.args=list(n=150, h=1), layout=igraph::layoutwithfr)
Random
diffnet.toa(x) <- sample(x$toa, size = nnodes(x))
Diffusion map (random toa)
dm1 <- diffusionMap(x, layout = dm0$coords, kde2d.args=list(n=150, h=.5))
oldpar <- par(no.readonly = TRUE) col <- viridisLite::plasma(100) par(mfrow=c(1,2), oma=c(1,0,0,0), cex=.8) image(dm0, col=col, main="Non-random Times of Adoption\nAdoption from the core.") image(dm1, col=col, main="Random Times of Adoption") par(mfrow=c(1,1)) mtext("Both networks have the same distribution on times of adoption", 1, outer = TRUE) ```

r
par(oldpar)
Adopters classification
r
out <- classify(kfamilyDiffNet, include_censored = TRUE)
ftable(out)
thr Non-Adopters Very Low Thresh. Low Thresh. High Thresh. Very High Thresh.
toa
Non-Adopters 0.00 0.00 0.00 0.00 0.00
Early Adopters 0.00 14.04 8.40 0.57 0.29
Early Majority 0.00 5.64 11.65 5.54 2.58
Late Majority 0.00 1.34 5.06 6.21 2.96
Laggards 0.00 1.53 0.00 0.00 34.19
``` r
Plotting
oldpar <- par(no.readonly = TRUE) par(xpd=TRUE) plot(out, color=viridisLite::inferno(5), las = 2, xlab="Time of Adoption", ylab="Threshold", main="")
Adding key
legend("bottom", legend = levels(out$thr), fill=viridisLite::inferno(5), horiz = TRUE, cex=.6, bty="n", inset=c(0,-.1)) ```

r
par(oldpar)
Session info
r
sessionInfo()
R version 4.5.0 (2025-04-11)
Platform: aarch64-apple-darwin24.2.0
Running under: macOS Sequoia 15.0.1
Matrix products: default
BLAS: /opt/homebrew/Cellar/openblas/0.3.29/lib/libopenblasp-r0.3.29.dylib
LAPACK: /opt/homebrew/Cellar/r/4.5.0/lib/R/lib/libRlapack.dylib; LAPACK version 3.12.1
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: America/Denver
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] netdiffuseR_1.23.0
loaded via a namespace (and not attached):
[1] Matrix_1.7-3 jsonlite_2.0.0 dplyr_1.1.4
[4] compiler_4.5.0 tidyselect_1.2.1 Rcpp_1.0.14
[7] networkLite_1.1.0 boot_1.3-31 yaml_2.3.10
[10] fastmap_1.2.0 lattice_0.22-6 coda_0.19-4.1
[13] R6_2.6.1 generics_0.1.4 MatchIt_4.7.2
[16] igraph_2.1.4.9046 knitr_1.50 MASS_7.3-65
[19] backports_1.5.0 tibble_3.3.0 statnet.common_4.12.0
[22] pillar_1.10.2 rlang_1.1.6 xfun_0.52
[25] viridisLite_0.4.2 cli_3.6.5 magrittr_2.0.3
[28] network_1.19.0 digest_0.6.37 grid_4.5.0
[31] lifecycle_1.0.4 vctrs_0.6.5 sna_2.8
[34] evaluate_1.0.3 SparseM_1.84-2 glue_1.8.0
[37] rmarkdown_2.29 tools_4.5.0 pkgconfig_2.0.3
[40] networkDynamic_0.11.5 htmltools_0.5.8.1
To-do list
- Import/Export functions for interfacing other package’s clases, in
particular:
statnetset (specially the packagesnetworkDynamicandndtv), ~~igraph~~ andRsiena. - Populate the tests folder.
- ~~Use spells? (
select_egoalterwould use this)~~ - ~~Classify individuals by adoption category using early adopters, adopters, and laggards, and by threshold using very low, low, high and very high threshold (Valente 95’ p. 94).~~
- ~~Double check all functions using adjacency matrix values.~~
- ~~Remove dimnames from matrices and vectors. It is more efficient to use the ones stored in meta instead.~~
- Implement the Bass model
- ~~Include function to import survey data (as shown on the vignettes)~~
- Exposure based on Mahalanobis distances and also Roger Leenders on weighting exposure (internal note).
- (2016-03-30): use
xsplinefor drawing polygons & edges. - ~~(2016-04-04): Add more options to
exposure, namely,self(so removes diagonal or not!).~~ - (2016-04-19): animal behaviorists.
- (2016-10-18): Review language throughout the manual (more than innovation).
- (2016-10-18): Evaluate and eventually use a standard graph format
(
networkfor instance?). - (2016-10-18): Standarize graph plot methods (choose either statnet/igraph/own)
Owner
- Name: USC Center for Applied Network Analysis
- Login: USCCANA
- Kind: organization
- Location: Los Angeles, CA
- Website: https://cana.usc.edu
- Repositories: 2
- Profile: https://github.com/USCCANA
GitHub Events
Total
- Create event: 7
- Issues event: 13
- Watch event: 3
- Delete event: 3
- Issue comment event: 8
- Member event: 1
- Push event: 67
- Pull request review comment event: 25
- Pull request review event: 9
- Pull request event: 10
- Fork event: 2
Last Year
- Create event: 7
- Issues event: 13
- Watch event: 3
- Delete event: 3
- Issue comment event: 8
- Member event: 1
- Push event: 67
- Pull request review comment event: 25
- Pull request review event: 9
- Pull request event: 10
- Fork event: 2
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| George G. Vega Yon | g****n@g****m | 371 |
| srdyal | s****e@g****m | 6 |
| Thomas W Valente | t****e@u****u | 3 |
| George Vega Yon | g****e@A****l | 3 |
| KristinaMiljkovic | m****i@u****u | 2 |
| srdyal | s****l | 1 |
| Aníbal Olivera M. | 1****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 45
- Total pull requests: 10
- Average time to close issues: about 1 month
- Average time to close pull requests: 25 days
- Total issue authors: 12
- Total pull request authors: 3
- Average comments per issue: 1.09
- Average comments per pull request: 0.5
- Merged pull requests: 5
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 11
- Pull requests: 8
- Average time to close issues: 15 days
- Average time to close pull requests: 29 days
- Issue authors: 3
- Pull request authors: 3
- Average comments per issue: 0.55
- Average comments per pull request: 0.38
- Merged pull requests: 4
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- gvegayon (28)
- aoliveram (6)
- Hanele (2)
- rameman (2)
- Fabrizio-Marini (1)
- map42 (1)
- twvalente (1)
- PCK1992 (1)
- karan (1)
- srpitts (1)
- OwenTheAnalyst (1)
- fobos3 (1)
Pull Request Authors
- gvegayon (7)
- KristinaMiljkovic (6)
- aoliveram (4)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 2
-
Total downloads:
- cran 688 last-month
-
Total dependent packages: 0
(may contain duplicates) -
Total dependent repositories: 4
(may contain duplicates) - Total versions: 26
- Total maintainers: 1
proxy.golang.org: github.com/USCCANA/netdiffuseR
- Documentation: https://pkg.go.dev/github.com/USCCANA/netdiffuseR#section-documentation
- License: other
-
Latest release: v1.23.0
published 8 months ago
Rankings
cran.r-project.org: netdiffuseR
Analysis of Diffusion and Contagion Processes on Networks
- Homepage: https://github.com/USCCANA/netdiffuseR
- Documentation: http://cran.r-project.org/web/packages/netdiffuseR/netdiffuseR.pdf
- License: MIT + file LICENSE
-
Latest release: 1.23.0
published 8 months ago
Rankings
Maintainers (1)
Dependencies
- R >= 3.1.1 depends
- MASS * imports
- MatchIt * imports
- Matrix * imports
- Rcpp >= 0.12.1 imports
- SparseM * imports
- boot * imports
- grDevices * imports
- graphics * imports
- igraph * imports
- methods * imports
- network * imports
- networkDynamic * imports
- sna * imports
- stats * imports
- utils * imports
- viridisLite * imports
- RSiena * suggests
- ape * suggests
- covr * suggests
- knitr * suggests
- rmarkdown * suggests
- survival * suggests
- testthat * suggests
- R >= 3.1.1 depends
- MASS * imports
- MatchIt * imports
- Matrix * imports
- Rcpp >= 0.12.1 imports
- SparseM * imports
- boot * imports
- grDevices * imports
- graphics * imports
- igraph * imports
- methods * imports
- network * imports
- networkDynamic * imports
- sna * imports
- stats * imports
- utils * imports
- viridisLite * imports
- RSiena * suggests
- ape * suggests
- covr * suggests
- knitr * suggests
- rmarkdown * suggests
- survival * suggests
- testthat * suggests
- actions/checkout v2 composite
- actions/cache v2 composite
- actions/checkout v2 composite
- actions/upload-artifact main composite
- r-lib/actions/setup-pandoc v1 composite
- r-lib/actions/setup-r v1 composite
- rocker/drd latest build