diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..bd213fda --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# +# See https://github.com/r-lib/actions/tree/master/examples#readme for +# additional example workflows available for the R community. + +name: R CI + +on: [push, pull_request] + +env: + cntr: uscbiostats/fmcmc:latest + +jobs: + build: + runs-on: Ubuntu-latest + strategy: + matrix: + include: + - name: release + cmd: R + - name: dev + cmd: RD + + steps: + - uses: actions/checkout@v2 + + - name: Container + run: docker pull ${{ cntr }} + + - name: SessionInfo + run: docker run --rm -i -v ${PWD}:/mnt -w /mnt ${{ cntr }} ${{ matrix.cmd }} -q -e 'sessionInfo()' + + - name: Build + run: docker run --rm -i -v ${PWD}:/mnt -w /mnt ${{ cntr }} ${{ matrix.cmd }} CMD build --no-build-vignettes --no-manual . + + - name: Check + run: docker run --rm -i -v ${PWD}:/mnt -w /mnt -e CI=true ${{ cntr }} ${{ matrix.cmd }} CMD check --no-vignettes --no-manual fmcmc_*.tar.gz + diff --git a/DESCRIPTION b/DESCRIPTION index 0cd7d971..93481d1c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: netdiffuseR Title: Analysis of Diffusion and Contagion Processes on Networks -Version: 1.22.2 +Version: 1.22.3 Authors@R: c( person("George", "Vega Yon", email="g.vegayon@gmail.com", role=c("aut", "cre"), comment=c(ORCID = "0000-0002-3171-0844", what="Rewrite functions with Rcpp, plus new features") diff --git a/NEWS.md b/NEWS.md index 37d85eea..737c6ca9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# Changes in netdiffuseR version 1.22.1 (2021-05-04) +# Changes in netdiffuseR version 1.22.1 (2021-05-27) * netdiffuseR has now a logo! diff --git a/R/bass.r b/R/bass.r index 7315c953..a1268ea5 100644 --- a/R/bass.r +++ b/R/bass.r @@ -2,7 +2,7 @@ #' #' Fits the Bass Diffusion model. In particular, fits an observed curve of #' proportions of adopters to \eqn{F(t)}, the proportion of adopters at time -#' \eqn{t}, finding the corresponding coeficients \eqn{p}, Innovation rate, +#' \eqn{t}, finding the corresponding coefficients \eqn{p}, Innovation rate, #' and \eqn{q}, imitation rate. #' #' @param Time Integer vector with values greater than 0. The \eqn{t} parameter. diff --git a/R/data.r b/R/data.r index e0c6329b..e69ba8c9 100644 --- a/R/data.r +++ b/R/data.r @@ -846,6 +846,7 @@ NULL # "medInnovationsDiffNet" #' @family diffusion datasets #' @name diffusion-data #' @author Thomas W. Valente +#' @return No return value (this manual entry only provides information). NULL diff --git a/R/diffnet-methods.r b/R/diffnet-methods.r index 91e7059d..c813d0b9 100644 --- a/R/diffnet-methods.r +++ b/R/diffnet-methods.r @@ -20,12 +20,14 @@ #' #' plot.diffnet <- function( - x,y=NULL, t=1, - vertex.color = c(adopt="steelblue", noadopt="white"), - vertex.size = "degree", - main = "Diffusion network in time %d", + x,y = NULL, + t = 1, + vertex.color = c(adopt="steelblue", noadopt="white"), + vertex.size = "degree", + main = "Diffusion network in time %d", minmax.relative.size = getOption("diffnet.minmax.relative.size", c(0.01, 0.04)), - ...) { + ... + ) { # Listing arguments igraph.args <- list(...) @@ -651,6 +653,8 @@ plot_diffnet.default <- function( #' plot_threshold(graph, expos, toa, vertex.size = "indegree") #' #' @export +#' @return Invisible. A data frame with the calculated coordinates, including: +#' `toa`, `threshold`, and `jit` (a jittered version of `toa`). #' @author George G. Vega Yon plot_threshold <- function(graph, expo, ...) UseMethod("plot_threshold") @@ -826,8 +830,16 @@ plot_threshold.default <- function( # Plotting the edges mapply(function(x0, y0, x1, y1, col, edge.curved, arrow.color) { - y <- edges_arrow(x0, y0, x1, y1, width=arrow.width, height=arrow.length, - beta=pi*(2/3), dev=par("pin"), ran=ran, curved = edge.curved) + + y <- edges_arrow( + x0, y0, x1, y1, + width = arrow.width, + height = arrow.length, + beta = pi*(2/3), + dev = par("pin"), + ran = ran, + curved = edge.curved + ) # Drawing arrow if (edge.curved) { @@ -836,7 +848,7 @@ plot_threshold.default <- function( graphics::xspline( y$edge[,1],y$edge[,2], shape = c(0, 1, 0), - open=TRUE, border = col, lwd=edge.width) + open = TRUE, border = col, lwd=edge.width) # Arrow graphics::polygon(y$arrow[,1], y$arrow[,2], col = arrow.color, border = arrow.color) diff --git a/R/graph_data.r b/R/graph_data.r index f8af83c7..d8d4a94a 100644 --- a/R/graph_data.r +++ b/R/graph_data.r @@ -36,6 +36,7 @@ #' and \code{\link{names}} (in the case of dynamic graphs as lists). Otherwise, #' when no names are provided, these will be created from scratch. #' @include imports.r +#' @return No return value (this manual entry only provides information). #' @author George G. Vega Yon #' @family graph formats NULL diff --git a/R/misc.r b/R/misc.r index b4da6701..55431c2e 100644 --- a/R/misc.r +++ b/R/misc.r @@ -82,7 +82,7 @@ recode.matrix <- function(data, ...) { #' pretty(x) #' pretty_within(x) #' range(x) -#' +#' @return A vector sequence of `n + 1` round values in the specified range. #' @export #' @keywords misc pretty_within <- function(x, min.n=5, xrange=range(x, na.rm = TRUE), ...) { diff --git a/R/rewire.r b/R/rewire.r index 9217983c..46176913 100644 --- a/R/rewire.r +++ b/R/rewire.r @@ -157,6 +157,7 @@ #' @family simulation functions #' @export #' @author George G. Vega Yon +#' @return A rewired version of the graph. #' @examples #' # Checking the consistency of the "swap" ------------------------------------ #' @@ -209,12 +210,18 @@ # ' # Marking the original structure # ' baseline <- paste0(as.vector(x), collapse="") # ' points(x=7,y=table(as.factor(w))[baseline]/nsim*100, pch=3, col="red") -rewire_graph <- function(graph, p, - algorithm="endpoints", - both.ends=FALSE, self=FALSE, multiple=FALSE, - undirected=getOption("diffnet.undirected"), - pr.change= ifelse(self, 0.5, 1), - copy.first=TRUE, althexagons=FALSE) { +rewire_graph <- function( + graph, + p, + algorithm="endpoints", + both.ends = FALSE, + self = FALSE, + multiple = FALSE, + undirected = getOption("diffnet.undirected"), + pr.change = ifelse(self, 0.5, 1), + copy.first = TRUE, + althexagons = FALSE + ) { # Checking undirected (if exists) checkingUndirected(graph) @@ -225,6 +232,16 @@ rewire_graph <- function(graph, p, warning("The option -althexagons- is still on development. So it has been set to FALSE.") } + if (copy.first) { + + warning( + "The option -copy.first- is set to TRUE. In this case, the first graph will be ", + "treated as a baseline, and thus, networks after T=1 will be replaced with T-1.", + immediate. = TRUE + ) + + } + # Checking copy.first # if (missing(copy.first)) copy.first <- FALSE @@ -246,19 +263,33 @@ rewire_graph <- function(graph, p, # If diffnet, then it must return the same object but rewired, and change # the attribute of directed or not if (inherits(graph, "diffnet")) { + graph$meta$undirected <- undirected graph$graph <- out return(graph) + } attr(out, "undirected") <- FALSE return(out) + } # @rdname rewire_graph -rewire_graph.list <- function(graph, p, algorithm, both.ends, self, multiple, undirected, - pr.change, copy.first, althexagons) { +rewire_graph.list <- function( + graph, + p, + algorithm, + both.ends, + self, + multiple, + undirected, + pr.change, + copy.first, + althexagons +) { + t <- length(graph) out <- graph @@ -291,10 +322,22 @@ rewire_graph.list <- function(graph, p, algorithm, both.ends, self, multiple, un } out + } # @rdname rewire_graph -rewire_graph.dgCMatrix <- function(graph, p, algorithm, both.ends, self, multiple, undirected, pr.change, althexagons) { +rewire_graph.dgCMatrix <- function( + graph, + p, + algorithm, + both.ends, + self, + multiple, + undirected, + pr.change, + althexagons + ) { + out <- if (algorithm == "endpoints") rewire_endpoints(graph, p, both.ends, self, multiple, undirected) else if (algorithm == "swap") @@ -307,10 +350,12 @@ rewire_graph.dgCMatrix <- function(graph, p, algorithm, both.ends, self, multipl if (!length(rn)) rn <- 1:nrow(out) dimnames(out) <- list(rn, rn) out + } # @rdname rewire_graph -rewire_graph.array <-function(graph, p, algorithm, both.ends, self, multiple, undirected, +rewire_graph.array <-function( + graph, p, algorithm, both.ends, self, multiple, undirected, pr.change, copy.first, althexagons) { n <- dim(graph)[1] t <- dim(graph)[3] @@ -321,8 +366,12 @@ rewire_graph.array <-function(graph, p, algorithm, both.ends, self, multiple, un if (!length(tn)) tn <- 1:t names(out) <- tn - return(rewire_graph.list(out, p, algorithm, both.ends, self, multiple, undirected, - pr.change, copy.first, althexagons)) + return( + rewire_graph.list( + out, p, algorithm, both.ends, self, multiple, undirected, + pr.change, copy.first, althexagons + ) + ) } #' Permute the values of a matrix @@ -364,7 +413,11 @@ rewire_graph.array <-function(graph, p, algorithm, both.ends, self, multiple, un #' @family simulation functions #' @export #' @aliases CUG QAP -permute_graph <- function(graph, self=FALSE, multiple=FALSE) { +permute_graph <- function( + graph, + self = FALSE, + multiple = FALSE + ) { # Changing class cls <- class(graph) @@ -444,10 +497,10 @@ rewire_qap <- function(graph) { } - } else { + } else ans <- rewirefun(x) - } return(ans) + } diff --git a/R/struct_equiv.R b/R/struct_equiv.R index 5ec5f2e9..1eac472b 100644 --- a/R/struct_equiv.R +++ b/R/struct_equiv.R @@ -271,7 +271,8 @@ struct_equiv_by <- function(graph, v, inf.replace, groupvar, ...) { #' @details The transformation function \code{fun} must return a square matrix #' of size \eqn{m\times m}{m*m}, where \eqn{m} is the size of the subgroup #' given by \code{INDICES}. See examples below -#' +#' @return A transformed version of the network, with the desired function applied +#' by blocks. #' @examples #' # Rewiring a graph by community -------------------------------------------- #' diff --git a/docker/DESCRIPTION b/docker/DESCRIPTION new file mode 100644 index 00000000..93481d1c --- /dev/null +++ b/docker/DESCRIPTION @@ -0,0 +1,92 @@ +Package: netdiffuseR +Title: Analysis of Diffusion and Contagion Processes on Networks +Version: 1.22.3 +Authors@R: c( + person("George", "Vega Yon", email="g.vegayon@gmail.com", role=c("aut", "cre"), + comment=c(ORCID = "0000-0002-3171-0844", what="Rewrite functions with Rcpp, plus new features") + ), + person("Thomas", "Valente", email="tvalente@usc.edu", role=c("aut", "cph"), + comment=c(ORCID="0000-0002-8824-5816", what="R original code")), + person("Stephanie", "Dyal", email="stepharp@usc.edu", role=c("ctb"), comment="Package's first version"), + person("Timothy", "Hayes", email="timothybhayes@gmail.com", role=c("ctb"), comment="Package's first version") + ) +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. +Depends: + R (>= 3.1.1) +License: MIT + file LICENSE +LazyData: true +Date: 2021-05-21 +Imports: + Rcpp (>= 0.12.1), + sna, + network, + networkDynamic, + Matrix, + MASS, + MatchIt, + SparseM, + methods, + grDevices, + graphics, + stats, + utils, + boot, + igraph, + viridisLite +Suggests: + covr, + testthat, + knitr, + rmarkdown, + ape, + RSiena, + survival +VignetteBuilder: knitr +LinkingTo: Rcpp, RcppArmadillo +RoxygenNote: 7.1.1 +Encoding: UTF-8 +URL: https://github.com/USCCANA/netdiffuseR, + https://USCCANA.github.io/netdiffuseR/ +BugReports: https://github.com/USCCANA/netdiffuseR/issues +Classification/MSC: 90C35, 90B18, 91D30 +Collate: + 'RcppExports.R' + 'imports.r' + 'graph_data.r' + 'adjmat.r' + 'bass.r' + 'bootnet.r' + 'data.r' + 'diffnet-c.R' + 'diffnet-class.r' + 'diffnet-indexing.r' + 'diffnet-methods.r' + 'egonets.R' + 'formula.r' + 'igraph.r' + 'infect_suscept.r' + 'mentor.r' + 'misc.r' + 'moran.r' + 'netmatch.r' + 'network.r' + 'options.R' + 'package-doc.r' + 'plot_diffnet2.r' + 'rewire.r' + 'random_graph.R' + 'rdiffnet.r' + 'read_write_foreign.r' + 'select_egoalter.R' + 'spatial.R' + 'stats.R' + 'struct_equiv.R' + 'struct_test.R' + 'survey_to_diffnet.R' diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..aa99e034 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,12 @@ +FROM rocker/drd + +RUN apt-get update && apt-get install \ + -y --no-install-recommends \ + libssl-dev +COPY pkgs.R . +COPY DESCRIPTION . +RUN Rscript pkgs.R && \ + Rscript -e 'utils::install.packages(readLines("pkgs.txt"))' + +CMD ["bash"] + diff --git a/docker/Dockerfile.r-ver b/docker/Dockerfile.r-ver new file mode 100644 index 00000000..7d9f8f1c --- /dev/null +++ b/docker/Dockerfile.r-ver @@ -0,0 +1,8 @@ +ARG Rversion + +FROM rocker/r-ver:${Rversion} + +RUN Rscript -e 'utils::install.packages(c("rmarkdown", "knitr", "coda", "mvtnorm", "tinytest", "mcmc", "covr"))' + +CMD ["bash"] + diff --git a/docker/Makefile b/docker/Makefile new file mode 100644 index 00000000..5c48d047 --- /dev/null +++ b/docker/Makefile @@ -0,0 +1,5 @@ +build: + cp ../DESCRIPTION . && \ + docker build -t uscbiostats/netdiffuser:latest -f Dockerfile . +push: build + docker push uscbiostats/netdiffuser:latest diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..77cecc38 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,11 @@ +To run the check in the main package folder: + +```bash +docker run -v$(pwd):/fmcmc-pkg/ -w/fmcmc-pkg --rm -i uscbiostats/fmcmc-dev:latest make check +``` + +To update the version just type + +```bash +make push +``` diff --git a/docker/pkgs.R b/docker/pkgs.R new file mode 100644 index 00000000..60188570 --- /dev/null +++ b/docker/pkgs.R @@ -0,0 +1,14 @@ +x <- readLines("DESCRIPTION") +ids <- which(grepl("^(Imports:|Suggests:|VignetteBuilder:)", x)) +x <- x[setdiff((ids[1] + 1):(ids[3] - 1), ids[2])] + +x <- gsub("^\\s+|(?<=[[:alnum:]])(\\s|,).*", "", x, perl = TRUE) +x <- setdiff(x, c("MASS", "methods", "grDevices", "graphics", "stats", "utils")) + +xfin <- x +for (i in x) { + if (require(i)) + xfin <- setdiff(xfin, i) +} + +writeLines(xfin, con = "pkgs.txt") diff --git a/inst/NEWS b/inst/NEWS index aacd4f3b..52f5e342 100644 --- a/inst/NEWS +++ b/inst/NEWS @@ -1,16 +1,10 @@ - - -CHANGES IN NETDIFFUSER VERSION 1.22.1 (2021-05-04) - +Changes in netdiffuseR version 1.22.1 (2021-05-27) - netdiffuseR has now a logo! - Making updates after changes in knitr and Matrix. - - -CHANGES IN NETDIFFUSER VERSION 1.22.0 (2020-05-17) - +Changes in netdiffuseR version 1.22.0 (2020-05-17) - Fixing a new issue regarding structural equivalence calculation. In the new version, the function has been fully ported to R, which @@ -19,30 +13,20 @@ CHANGES IN NETDIFFUSER VERSION 1.22.0 (2020-05-17) - As documented, struct_equiv now returns he euclidean distance matrix (it was not doing that). - - -CHANGES IN NETDIFFUSER VERSION 1.21.0 (2020-02-10) - +Changes in netdiffuseR version 1.21.0 (2020-02-10) - Getting netdiffuseR back to CRAN. We have fixed issues that arise from the next big CRAN release, in particular, matrices are now arrays. That was creating issues throughout the package (now fixed). - - -CHANGES IN NETDIFFUSER VERSION 1.20.2 (2019-03-25) - +Changes in netdiffuseR version 1.20.2 (2019-03-25) - Repaired broken link in bootnet. - - -CHANGES IN NETDIFFUSER VERSION 1.20.1 (2019-03-22) - +Changes in netdiffuseR version 1.20.1 (2019-03-22) - This version has no user level visible changes. - Other changes - Changing PI macros in C++ code as requested by RcppCore. @@ -50,10 +34,7 @@ Other changes - Setting 3.5 seed version for tests so that test won’t break following message from CRAN. - - -CHANGES IN NETDIFFUSER VERSION 1.20.0 (2018-06-06) - +Changes in netdiffuseR version 1.20.0 (2018-06-06) New functions and features @@ -63,14 +44,12 @@ New functions and features now selected from the viridis R package, which provides perceptually uniform and colorblind proof colors. - Bug fixes - plot_diffnet2 now has the correct scaling in nodes positions. - rdiffnet_multiple calls library(netdiffuseR) when using multicore. - Other changes - arrow.width in plot_threshold.default now set to be equal to @@ -81,10 +60,7 @@ Other changes - The c++ function edges_arrow now returns two different elements (the edge, and the arrow). - - -CHANGES IN NETDIFFUSER VERSION 1.19.0 (2017-10-16) - +Changes in netdiffuseR version 1.19.0 (2017-10-16) New functions and features @@ -108,7 +84,6 @@ New functions and features - exposure has a new parameter: lags. By default lags = 0, returns a lagged exposure matrix. - Bug fixes - igraph_to_diffnet was failing with the graph had no weights. @@ -126,7 +101,6 @@ Bug fixes corrected in diffnet_to_igraph, and other plot methods using igraph for plotting. - Other changes - Replacing some C++ functions by R functions in cases in which there @@ -139,10 +113,7 @@ Other changes Innovations”, and “Simulating diffusion networks: Using the rdiffnet function”. - - -CHANGES IN NETDIFFUSER VERSION 1.18.1 (2017-07-22) - +Changes in netdiffuseR version 1.18.1 (2017-07-22) New functions @@ -152,12 +123,10 @@ New functions - networkDynamic_to_diffnet, diffnet_to_networkDynamc coercion between diffnet and networkDynamic objects. - New features - new_diffnet and as_diffnet now receive static networks as well. - Bug fixes - diffnet_to_igraph was copying over a single adjacency matrix, which @@ -167,10 +136,7 @@ Bug fixes - In unexpected situations egonet_attrs was crashing. - - -CHANGES IN NETDIFFUSER VERSION 1.18.0 (2017-07-16) - +Changes in netdiffuseR version 1.18.0 (2017-07-16) New functions @@ -196,7 +162,6 @@ New functions - netmatch and netmatch_prepare (on development) implement matching estimators with network data. - Bugs Fixes - dgr returned with error when self == TRUE @@ -210,7 +175,6 @@ Bugs Fixes - transformGraphBy was returning with error when the time periods ranged other than 1, 2, … - New Features - rgraph_er is now significantly faster (orders of magnitude compare @@ -223,15 +187,12 @@ New Features - rewire_graph now also uses QAP. This affects directly to structu_test. - - -CHANGES IN NETDIFFUSER VERSION 1.17.0 (2016-11-10) - +Changes in netdiffuseR version 1.17.0 (2016-11-10) New features and changes -- The title of the package is now _Analysis of Diffusion and Contagion - Processes on Networks_. +- The title of the package is now Analysis of Diffusion and Contagion + Processes on Networks. - The function struct_test now allows other types of graphs. Before it only supported diffnet objects. @@ -261,7 +222,6 @@ New features and changes - classify_adopters now always includes Non-Adopters. - New functions - vertex_covariate_dist computes distances between vertices using both @@ -296,7 +256,6 @@ New functions - rewire_qap generates isomorphic graphs by “changing the labels”. - Bug fixes - ^.diffnet method was rasing to +1 power, e.g. diffnet^2 was actually @@ -322,10 +281,7 @@ Bug fixes - The method [[<-.diffnet failed when replacing a dynamic attribute with a NULL value (e.g. dn[["my_dyn_att"]] <- NULL). - - -CHANGES IN NETDIFFUSER VERSION 1.16.7 (2016-07-07) - +Changes in netdiffuseR version 1.16.7 (2016-07-07) Bug fixes @@ -343,7 +299,6 @@ Bug fixes - Fixed bug on egonet_attrs: The matrix method was returning with error. - New features and changes - plot_infectsuscept includes 2D kernel smoother via MASS::kde2d. @@ -361,7 +316,6 @@ New features and changes as exposure lags time periods prior to the time of adoption. By default is 0 so its exposure at the time of adoption. - New functions - New method c.diffnet_struct_test: A wrapper of boot:::c.boot. @@ -389,10 +343,7 @@ New functions when calling plot.igraph so that the size is proportional to the x-axis. - - -CHANGES IN NETDIFFUSER VERSION 1.16.5 (2016-05-02) - +Changes in netdiffuseR version 1.16.5 (2016-05-02) Bug fixes @@ -415,7 +366,6 @@ Bug fixes slices names different from the time periods, the slices names were kept. Now these are replaced by meta$pers. - New features and changes - Support for int64_t in RcppArmadillo now allows for creating/reading @@ -492,7 +442,6 @@ New features and changes rewire_ws which has been implemented as it was presented in Watts and Strogatz (1998). - New functions - New function: survey_to_diffnet. This function allows importing @@ -531,9 +480,6 @@ New functions - New rewiring algorithm, rewire_swap implements the edge-switch algorithm in an efficient way. This preserves degree sequences. - - -CHANGES IN NETDIFFUSER VERSION 1.16.2 (2016-02-18) - +Changes in netdiffuseR version 1.16.2 (2016-02-18) - First CRAN version. diff --git a/man/diffusion-data.Rd b/man/diffusion-data.Rd index 1080a26c..4bfbb95e 100644 --- a/man/diffusion-data.Rd +++ b/man/diffusion-data.Rd @@ -3,6 +3,9 @@ \name{diffusion-data} \alias{diffusion-data} \title{Diffusion Network Datasets} +\value{ +No return value (this manual entry only provides information). +} \description{ Diffusion Network Datasets } diff --git a/man/netdiffuseR-graphs.Rd b/man/netdiffuseR-graphs.Rd index 5b251dcc..8f4895eb 100644 --- a/man/netdiffuseR-graphs.Rd +++ b/man/netdiffuseR-graphs.Rd @@ -3,6 +3,9 @@ \name{netdiffuseR-graphs} \alias{netdiffuseR-graphs} \title{Network data formats} +\value{ +No return value (this manual entry only provides information). +} \description{ List of accepted graph formats } diff --git a/man/plot_threshold.Rd b/man/plot_threshold.Rd index 29c08f74..54a2d0f0 100644 --- a/man/plot_threshold.Rd +++ b/man/plot_threshold.Rd @@ -125,6 +125,10 @@ rotation in radians of each vertex (see details).} \item{background}{TBD} } +\value{ +Invisible. A data frame with the calculated coordinates, including: +`toa`, `threshold`, and `jit` (a jittered version of `toa`). +} \description{ Draws a graph where the coordinates are given by time of adoption, x-axis, and threshold level, y-axis. diff --git a/man/pretty_within.Rd b/man/pretty_within.Rd index 181cbf3f..62f00f76 100644 --- a/man/pretty_within.Rd +++ b/man/pretty_within.Rd @@ -21,6 +21,9 @@ resulting vector as \code{tick[(tick >= xrange[1]) & (tick <= xrange[2])]}} } +\value{ +A vector sequence of `n + 1` round values in the specified range. +} \description{ A wrapper for \code{\link[base:pretty]{pretty}}. } @@ -31,6 +34,5 @@ x <- runif(10) pretty(x) pretty_within(x) range(x) - } \keyword{misc} diff --git a/man/rewire_graph.Rd b/man/rewire_graph.Rd index 2ec81632..979bb133 100644 --- a/man/rewire_graph.Rd +++ b/man/rewire_graph.Rd @@ -42,6 +42,9 @@ the first slice as a baseline for the rest of slices (see details).} \item{althexagons}{Logical scalar. When \code{TRUE} uses the compact alternating hexagons algorithm (currently ignored [on development]).} } +\value{ +A rewired version of the graph. +} \description{ Changes the structure of a graph by altering ties. } diff --git a/man/transformGraphBy.Rd b/man/transformGraphBy.Rd index ad26c8b7..759b89fc 100644 --- a/man/transformGraphBy.Rd +++ b/man/transformGraphBy.Rd @@ -23,6 +23,10 @@ transformGraphBy(graph, INDICES, fun = function(g, ...) g, ...) \item{...}{Further arguments passed to \code{fun}} } +\value{ +A transformed version of the network, with the desired function applied +by blocks. +} \description{ When there are structural zeros given by groups, this function applies a particular transformation function of a graph by groups returning a diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index b0ac3d6e..f4c19452 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -6,6 +6,11 @@ using namespace Rcpp; +#ifdef RCPP_USE_GLOBAL_ROSTREAM +Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); +Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); +#endif + // edgelist_to_adjmat_cpp arma::sp_mat edgelist_to_adjmat_cpp(const arma::mat& edgelist, NumericVector weights, int n, bool undirected, bool self, bool multiple); RcppExport SEXP _netdiffuseR_edgelist_to_adjmat_cpp(SEXP edgelistSEXP, SEXP weightsSEXP, SEXP nSEXP, SEXP undirectedSEXP, SEXP selfSEXP, SEXP multipleSEXP) { diff --git a/vignettes/large-simulation.Rmd b/vignettes/large-simulation.Rmd new file mode 100644 index 00000000..7b811c4c --- /dev/null +++ b/vignettes/large-simulation.Rmd @@ -0,0 +1,44 @@ +--- +title: "Vignette Title" +author: "Vignette Author" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Vignette Title} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r setup, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +# Preliminaries + +We are interested in running a large scale simulation featuring hundreds of thousands (if not millions) of vertices. Before we proceed, you need to consider the following: + +1. Networks in netdiffuseR are sparse-matrices, thus, as long as the network is sparsely connected, it will fit in a regular computer. +2. At the same time, converting a sparse-matrix into a dense matrix at this scale **is not a good idea**, as you computer may crash. This would be the case, for example, if you want to calculate the geodesic matrix. +3. Following the previous point, using `summary(..., skip.moran = FALSE)`--the default behavior--is not a good idea. When dealing with large graphs, set `skip.moran = TRUE` to avoid memory overflow. + +# Case 1: Single simulation + +Suppose we want to simulate a diffusion process with the following parameters: + +- Network type: Small world with parameters $n=200k, k = 10, p = .1$ + +```{r setp-1, eval=FALSE} +library(netdiffuseR) +``` + +We no proceed with the simulation + +```{r sim-1, eval=FALSE} +ans_sw <- rdiffnet(n = 200, t = 10) +``` + + + diff --git a/vignettes/rdiffnets.Rmd b/vignettes/rdiffnets.Rmd new file mode 100644 index 00000000..cda9dc1c --- /dev/null +++ b/vignettes/rdiffnets.Rmd @@ -0,0 +1,93 @@ +--- +title: "A simple simulation example" +author: "George G Vega Yon" +date: "February 25, 2019" +output: rmarkdown::html_vignette +header-includes: \usepackage{graphicx} +vignette: > + %\VignetteIndexEntry{A simple rdiffnet example} + %\VignetteEngine{knitr::rmarkdown} + %\usepackage[utf8]{inputenc} +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = TRUE) +``` + +## R Markdown + +## Step 1: Loading the packages + +```{r loading, message=FALSE, warning=FALSE} +library(netdiffuseR) +library(sna) +``` + +## Step 2: Random network (for input) + +```{r random-net} +set.seed(8826) + +# Simulating a small world (10, 3) with pr = .3 +net <- rgraph_ws(50, 3, .3) + +# A bit more of rewiring +net <- rewire_graph(net, p=3, both.ends = TRUE) +``` + +Taking a look at it using sna + +```{r viz} + +# Visualizing with +gplot(as.matrix(net)) +``` + +```{r diffnet} +# Random diffusion with a fixed threshold of 1, simulating 5 time points +mydiffnet <- rdiffnet( + seed.graph = net, # The network we just created + threshold.dist = 1, # Fixed threshold of 1 + t = 5, # 5 time points + rewire = FALSE, # No rewire (defaults TRUE) + exposure.args = list(normalized=FALSE), # Exposure to be computed unnormalized + # so we use counts instead + seed.nodes = "random" # Random set of initial adopters + ) + +# Looking at the diffusion process +plot_diffnet(mydiffnet) + +# Some summary stats +summary(mydiffnet) +``` + +We can actually go further and run multiple simulations instead so that we can +get a confidence interval in the proportion of adopters + +```{r diffnet-multiple, warning=FALSE} +set.seed(871) +mydiffnet <- rdiffnet_multiple( + statistic = function(n) cumulative_adopt_count(n)["prop",], + R = 1000, + stop.no.diff = FALSE, # This option allows us to continue + # The simulation process, even if there + # is no adoption. + seed.graph = net, # The network we just created + threshold.dist = 1, # Fixed threshold of 1 + t = 5, # 5 time points + rewire = FALSE, # No rewire (defaults TRUE) + exposure.args = list(normalized=FALSE), # Exposure to be computed unnormalized + # so we use counts instead + seed.nodes = "random" # Random set of initial adopters + ) + +# Looking at the diffusion process +boxplot( + t(mydiffnet), + xlab = "Time", + ylab = "Proportion of Adopters", + main = "Simulation of 1,000 diffusion processes" + ) +``` +