Skip to content

Commit

Permalink
revise argument isolates in clustcoef()
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelie-Yuan committed May 18, 2023
1 parent 8d1a38e commit f0573cf
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions R/centrality.R
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions R/clustercoef.R
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions R/joint_dist.R
Expand Up @@ -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.
#'
Expand Down
10 changes: 5 additions & 5 deletions R/rewire.R
Expand Up @@ -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),
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit f0573cf

Please sign in to comment.