Skip to content

Commit 3121449

Browse files
committed
Updating documentation for toa_mat
1 parent 26d7798 commit 3121449

File tree

5 files changed

+63
-33
lines changed

5 files changed

+63
-33
lines changed

R/adjmat.r

+30-24
Original file line numberDiff line numberDiff line change
@@ -396,35 +396,19 @@ adjmat_to_edgelist.list <- function(graph, undirected, keep.isolates) {
396396
return(cbind(edgelist, times=times))
397397
}
398398

399-
# # Benchmark with the previous version
400-
# library(microbenchmark)
401-
# library(netdiffuseR)
402-
#
403-
# dat <- as.data.frame(cbind(edgelist, w))
404-
# colnames(dat) <- c('ego','alter','tie')
405-
# microbenchmark(
406-
# adjmatbuild(dat,n,1:n),
407-
# edgelist_to_adjmat(edgelist, w), times=100)
408-
#
409-
# old <- adjmatbuild(dat[,-3],n,1:n)
410-
# new <- (edgelist_to_adjmat(unique(edgelist), undirected = FALSE))[,,1]
411-
# arrayInd(which(old!=new), dim(old), dimnames(old))
412-
#
413-
# ## Dynamic
414-
# microbenchmark(
415-
# adjByTime(cbind(year=times,dat),n,max(times)),
416-
# edgelist_to_adjmat(edgelist, w, times), times=100)
417-
418399
#' Time of adoption matrix
419400
#'
420401
#' Creates two matrices recording times of adoption of the innovation. One matrix
421402
#' records the time period of adoption for each node with zeros elsewhere. The
422403
#' second records the cumulative time of adoption such that there are ones for
423-
#' the time of adoption and every time period thereafter.
424-
#'
425-
#' @param obj Either an integer vector of size \eqn{n} containing time of adoption of the innovation,
426-
#' or a \code{\link{diffnet}} object.
427-
#' @param labels Character vector of size \eqn{n}. Labels (ids) of the vertices.
404+
#' the time of adoption and every time period thereafter. For multiple behavior
405+
#' diffusion, creates a list where each element contains those two matrices for
406+
#' each behavior.
407+
#'
408+
#' @param obj Either an integer vector of length \eqn{n} containing time of adoption
409+
#' of the innovation, a matrix of size \eqn{n \times Q} (for multiple \eqn{Q} behaviors), or
410+
#' a \code{\link{diffnet}} object (both for single or multiple behaviors).
411+
#' @param labels Character vector of length \eqn{n}. Labels (ids) of the vertices.
428412
#' @param t0 Integer scalar. Sets the lower bound of the time window (e.g. 1955).
429413
#' @param t1 Integer scalar. Sets the upper bound of the time window (e.g. 2000).
430414
#' @details
@@ -446,6 +430,12 @@ adjmat_to_edgelist.list <- function(graph, undirected, keep.isolates) {
446430
#' 2005 - 2000 + 1 = 6 columns instead of 2005 - 2001 + 1 = 5 columns, with the
447431
#' first column of the two matrices containing only zeros (as the first adoption
448432
#' happend after the year 2000).
433+
#'
434+
#' For multiple behaviors, the input can be a matrix or a \code{diffnet} object.
435+
#' In this case, the output will be a list, with each element replicating the output
436+
#' for a single diffusion: a matrix recording the time period of adoption for
437+
#' each node, and a second matrix with ones from the moment the node adopts the behavior.
438+
#'
449439
#' @examples
450440
#' # Random set of times of adoptions
451441
#' times <- sample(c(NA, 2001:2005), 10, TRUE)
@@ -454,6 +444,22 @@ adjmat_to_edgelist.list <- function(graph, undirected, keep.isolates) {
454444
#'
455445
#' # Now, suppose that we observe the graph from 2000 to 2006
456446
#' toa_mat(times, t0=2000, t1=2006)
447+
#'
448+
#' # For multiple behaviors, the input can be a matrix..
449+
#' times_1 <- c(2001L, 2004L, 2003L, 2008L)
450+
#' times_2 <- c(2001L, 2005L, 2006L, 2008L)
451+
#' times <- matrix(c(times_1, times_2), nrow = 4, ncol = 2)
452+
#'
453+
#' toa <- toa_mat(times)
454+
#' toa[[1]]$adopt # time period of adoption for the first behavior
455+
#'
456+
#' #.. or a diffnet object
457+
#' graph <- lapply(2001:2008, function(x) rgraph_er(4))
458+
#' diffnet <- new_diffnet(graph, times)
459+
#'
460+
#' toa <- toa_mat(diffnet)
461+
#' toa[[1]]$cumadopt # cumulative adoption matrix for the first behavior
462+
457463
#'
458464
#' @export
459465
#' @return A list of two \eqn{n \times T}{n x T}

R/diffnet-class.r

+1-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ check_as_diffnet_attrs <- function(attrs, meta, is.dynamic, id.and.per.vars=NULL
508508
#' \item{toa}{An integer vector of length \eqn{n} with times of adoption. When \eqn{Q}{Q} multiple
509509
#' behavior diffusion is selected, a matrix of size \eqn{n \times Q}{n * Q}}.
510510
#' \item{adopt, cumadopt}{Numeric matrices of size \eqn{n\times T}{n*T} as those returned
511-
#' by \code{\link{toa_mat}}. For \eqn{Q}{Q} multiple behavior diffusion, \code{adopt} and \code {cumadopt}
511+
#' by \code{\link{toa_mat}}. For \eqn{Q}{Q} multiple behavior diffusion, \code{adopt} and \code{cumadopt}
512512
#' become a list of \eqn{n\times T}{n*T} elements, with \eqn{Q}{Q} elements.}
513513
#' \item{vertex.static.attrs}{If not NULL, a data frame with \eqn{n} rows with vertex static
514514
#' attributes.}

man/diffnet-class.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/toa_diff.Rd

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/toa_mat.Rd

+27-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)