Skip to content

Commit

Permalink
Add -behavior- to be splitted in split_behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
aoliveram committed Dec 2, 2024
1 parent eeb477d commit f8f3f9a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions R/rdiffnet.r
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,9 @@ rdiffnet_validate_args <- function(seed.p.adopt, seed.nodes, behavior) {
)
}

#' Splittig behaviors
#' Splitting behaviors
#'
#' Split each behavior in an multi-diffusion diffnet object.
#' Split each behavior within multi-diffusion diffnet object.
#'
#' @param diffnet_obj A multi-diffusion diffnet object.
#' @return A list of diffnet objects. Each element represent a unique behavior.
Expand All @@ -675,6 +675,8 @@ split_behaviors <- function(diffnet_obj) {
# creates a list, keeping the structure of each element
diffnets <- replicate(ncol(diffnet_obj$toa), diffnet_obj, simplify = FALSE)

behaviors_names <- strsplit(diffnet_obj$meta$behavior, ", ")[[1]]

# loop over the behaviors
for (q in 1:ncol(diffnet_obj$toa)) {
diffnets[[q]]$toa <- as.integer(diffnet_obj$toa[, q, drop = FALSE])
Expand All @@ -683,6 +685,8 @@ split_behaviors <- function(diffnet_obj) {
diffnets[[q]]$adopt <- diffnet_obj$adopt[[q]]

diffnets[[q]]$cumadopt <- diffnet_obj$cumadopt[[q]]

diffnets[[q]]$meta$behavior <- behaviors_names[q]
}

return(diffnets)
Expand Down
6 changes: 3 additions & 3 deletions R/stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ dgr.array <- function(graph, cmode, undirected, self, valued) {
#' @templateVar self TRUE
#' @template graph_template
#' @param cumadopt \eqn{n\times T}{n * T} matrix for single diffusion.
#' \eqn{n\times T \times q}{n * T * Q} array for \eqn{Q}{Q} diffusion processes.
#' \eqn{n\times T \times Q}{n * T * Q} array for \eqn{Q}{Q} diffusion processes.
#' Cumulative adoption matrix obtained from \code{\link{toa_mat}}
#' @param attrs Either a character scalar (if \code{graph} is diffnet),
#' a numeric matrix of size \eqn{n\times T}{n * T}, or an array of size
#' \eqn{n\times T \time Q}{n * T * Q} (only for multi diffusion).
#' \eqn{n\times T \times Q}{n * T * Q} (only for multi diffusion).
#' Weighting for each time period (see details).
#' @param alt.graph Either a graph that should be used instead of \code{graph},
#' or \code{"se"} (see details).
Expand Down Expand Up @@ -479,7 +479,7 @@ dgr.array <- function(graph, cmode, undirected, self, valued) {
#'
#' diffnet_1 <- split_behaviors(diffnet)[[1]]
#' se <- struct_equiv(diffnet)
#' se <- lapply(se_1, function(x) {
#' se <- lapply(se, function(x) {
#' ans <- methods::as(x$SE, "dgCMatrix")
#' ans@x <- 1/(ans@x + 1e-20)
#' ans
Expand Down
4 changes: 2 additions & 2 deletions man/exposure.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f8f3f9a

Please sign in to comment.