From f0573cfab16bc0a5c5d524d7f4ba9d2bb3cd0f71 Mon Sep 17 00:00:00 2001 From: Yelie-Yuan Date: Thu, 18 May 2023 02:32:30 -0400 Subject: [PATCH] revise argument `isolates` in clustcoef() --- NEWS.md | 4 +++- R/centrality.R | 4 ++-- R/clustercoef.R | 16 ++++++++++------ R/joint_dist.R | 4 ++-- R/rewire.R | 10 +++++----- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/NEWS.md b/NEWS.md index b716559..b319ea3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,8 +5,10 @@ Printing + Fixed a typo when printing the parameters of the default preference function. Interface -+ Moved the logical argument `directed` in `rpanet` into `initial.network`; ++ Moved the logical argument `directed` in `rpanet()` into `initial.network`; `rpanet(nstep = 1e4, initial.network = list(directed = TRUE))`. ++ Revised argument `isolates` in `clustcoef()` to binary. + # wdnet 1.1.0 diff --git a/R/centrality.R b/R/centrality.R index 05344ce..0e1248b 100644 --- a/R/centrality.R +++ b/R/centrality.R @@ -61,7 +61,7 @@ degree_c <- function(adj, alpha = 1, mode = "out") { if (isSymmetric(adj) == TRUE) { warning("The analyzed network is undirected!") } - deg_c_output <- matrix(NA, nrow = dim(adj)[1], ncol = 2) + deg_c_output <- matrix(NA_real_, nrow = dim(adj)[1], ncol = 2) adj_name <- colnames(adj) if (is.null(adj_name) == FALSE) { deg_c_output <- adj_name @@ -126,7 +126,7 @@ closeness_c <- function(adj, alpha = 1, mode = "out", if (dim(adj)[1] != dim(adj)[2]) { stop("The adjacency matrix must be a square matrix!") } else { - closeness_c_output <- matrix(NA, nrow = dim(adj)[1], ncol = 2) + closeness_c_output <- matrix(NA_real_, nrow = dim(adj)[1], ncol = 2) adj_name <- colnames(adj) if (is.null(adj_name) == FALSE) { closeness_c_output[, 1] <- adj_name diff --git a/R/clustercoef.R b/R/clustercoef.R index a6007ac..a5ce48a 100644 --- a/R/clustercoef.R +++ b/R/clustercoef.R @@ -26,18 +26,18 @@ NULL #' @param netwk A \code{wdnet} object that represents the network. If #' \code{NULL}, the function will compute the coefficient using either #' \code{edgelist}, \code{edgeweight}, or \code{adj}. -#' @param edgelist A two column matrix, each row represents a directed edge of +#' @param edgelist A two-column matrix, each row represents a directed edge of #' the network. #' @param edgeweight A vector representing the weight of edges. #' @param adj An adjacency matrix of a weighted and directed network. #' @param directed Logical. Indicates whether the edges in \code{edgelist} or #' \code{adj} are directed. -#' @param method which method used to compute clustering coefficients: Clemente +#' @param method Which method used to compute clustering coefficients: Clemente #' and Grassi (2018) or Fagiolo (2007). -#' @param isolates character, defines how to treat vertices with degree zero and -#' one. If "zero", then their clustering coefficient is returned as 0 and are +#' @param isolates Binary, defines how to treat vertices with degree zero and +#' one. If 0, then their clustering coefficient is returned as 0 and are #' included in the averaging. Otherwise, their clustering coefficient is \code{NaN} -#' and are excluded in the averaging. Default value is "zero". +#' and are excluded in the averaging. Default value is 0. #' #' @return Lists of local clustering coefficients (in terms of a vector), global #' clustering coefficient (in terms of a scalar) and number of weighted @@ -82,7 +82,7 @@ clustcoef <- function( adj, directed = TRUE, method = c("Clemente", "Fagiolo"), - isolates = "zero") { + isolates = 0) { if (missing(adj)) { netwk <- create_wdnet( netwk = netwk, @@ -173,6 +173,10 @@ clustcoef <- function( "cycle" = numTriangles$"cycle" / denomMiddle ) if (isolates == "zero") { + cat('Argument "isolates" has been revised; use "isolates = 0" instead.\n"') + isolates <- 0 + } + if (isolates == 0) { localcc <- rapply(localcc, function(i) ifelse(is.na(i), 0, i), how = "replace" ) diff --git a/R/joint_dist.R b/R/joint_dist.R index f7bd7c6..8f76a8b 100644 --- a/R/joint_dist.R +++ b/R/joint_dist.R @@ -352,10 +352,10 @@ get_eta_directed <- function( #' @param edgelist A two column matrix representing the undirected edges of a #' network. #' @param target.assortcoef Numeric, represents the predetermined assortativity -#' coefficient. If \code{NA}, the range of assortativity coefficient and +#' coefficient. If \code{NULL}, the range of assortativity coefficient and #' corresponding joint distribution are returned. #' @param eta.obj A convex function of \code{eta} to be minimized when -#' \code{target.assortcoef} is not \code{NA}. Defaults to 0. +#' \code{target.assortcoef} is not \code{NULL}. Defaults to 0. #' @param control A list of parameters passed to \code{CVXR::solve()} when #' solving for \code{eta} or computing the range of assortativity coefficient. #' diff --git a/R/rewire.R b/R/rewire.R index dc6e3c0..e4b6694 100644 --- a/R/rewire.R +++ b/R/rewire.R @@ -92,10 +92,10 @@ dprewire_directed <- function( ) rho <- data.frame( "Iteration" = c(0:iteration), - "outout" = NA, - "outin" = NA, - "inout" = NA, - "inin" = NA + "outout" = NA_real_, + "outin" = NA_real_, + "inout" = NA_real_, + "inin" = NA_real_ ) rho[1, 2:5] <- c( "outout" = stats::cor(sout, tout), @@ -169,7 +169,7 @@ dprewire_undirected <- function( eta, rewire.history ) rm(node1, node2, degree1, degree2, index1, index2) - rho <- data.frame("Iteration" = c(0:iteration), "Value" = NA) + rho <- data.frame("Iteration" = c(0:iteration), "Value" = NA_real_) rho[1, 2] <- assortcoef(edgelist = edgelist, directed = FALSE) rho[2:(iteration + 1), 2] <- ret$rho colnames(rho) <- c("Iteration", "Value")