@@ -396,35 +396,19 @@ adjmat_to_edgelist.list <- function(graph, undirected, keep.isolates) {
396
396
return (cbind(edgelist , times = times ))
397
397
}
398
398
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
-
418
399
# ' Time of adoption matrix
419
400
# '
420
401
# ' Creates two matrices recording times of adoption of the innovation. One matrix
421
402
# ' records the time period of adoption for each node with zeros elsewhere. The
422
403
# ' 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.
428
412
# ' @param t0 Integer scalar. Sets the lower bound of the time window (e.g. 1955).
429
413
# ' @param t1 Integer scalar. Sets the upper bound of the time window (e.g. 2000).
430
414
# ' @details
@@ -446,6 +430,12 @@ adjmat_to_edgelist.list <- function(graph, undirected, keep.isolates) {
446
430
# ' 2005 - 2000 + 1 = 6 columns instead of 2005 - 2001 + 1 = 5 columns, with the
447
431
# ' first column of the two matrices containing only zeros (as the first adoption
448
432
# ' 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
+ # '
449
439
# ' @examples
450
440
# ' # Random set of times of adoptions
451
441
# ' times <- sample(c(NA, 2001:2005), 10, TRUE)
@@ -454,6 +444,22 @@ adjmat_to_edgelist.list <- function(graph, undirected, keep.isolates) {
454
444
# '
455
445
# ' # Now, suppose that we observe the graph from 2000 to 2006
456
446
# ' 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
+
457
463
# '
458
464
# ' @export
459
465
# ' @return A list of two \eqn{n \times T}{n x T}
0 commit comments