Skip to content

Commit

Permalink
version 1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
paytonjjones authored and cran-robot committed May 10, 2018
1 parent 33bdde9 commit 6699c9b
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 746 deletions.
18 changes: 8 additions & 10 deletions DESCRIPTION
@@ -1,25 +1,23 @@
Package: networktools
Title: Tools for Identifying Important Nodes in Networks
Version: 1.1.1
Date: 2018-2-5
Version: 1.1.2
Date: 2018-5-7
Authors@R: person("Payton", "Jones", email = "payton_jones@g.harvard.edu", role = c("aut", "cre"))
Description: Includes assorted tools for network analysis. Useful for
calculating and plotting expected influence, bridge centrality, and impact statistics.
Description: Includes assorted tools for network analysis. Bridge centrality, impact, & goldbricker.
Depends: R (>= 3.0.0)
License: GPL-3
Encoding: UTF-8
LazyData: true
Imports:
qgraph,igraph,IsingFit,reshape2,nnet,ggplot2,gridExtra,stats,graphics,utils,NetworkComparisonTest,devtools,
cocor
qgraph,igraph,IsingFit,reshape2,nnet,ggplot2,gridExtra,stats,graphics,utils,NetworkComparisonTest,devtools,cocor,RColorBrewer
RoxygenNote: 6.0.1
Suggests: knitr, rmarkdown
VignetteBuilder: knitr
Suggests: R.rsp
VignetteBuilder: R.rsp
URL: https://CRAN.R-project.org/package=networktools
BugReports: http://github.com/paytonjjones/networktools/issues
NeedsCompilation: no
Packaged: 2018-02-05 16:01:56 UTC; payto
Packaged: 2018-05-07 20:24:48 UTC; payto
Author: Payton Jones [aut, cre]
Maintainer: Payton Jones <payton_jones@g.harvard.edu>
Repository: CRAN
Date/Publication: 2018-02-05 16:31:02 UTC
Date/Publication: 2018-05-10 15:50:36 UTC
30 changes: 14 additions & 16 deletions MD5
@@ -1,48 +1,46 @@
55f8ef4385923d2995e054d5faba939e *DESCRIPTION
1d23add17358e36a193d1436b771c6ae *NAMESPACE
3c658df3e9c1997cf70f9355fede9aa2 *NEWS.md
e3466dc4c35c864dbe2c168fba4ff04b *DESCRIPTION
883017b57ce2ae7f38a015a2235e00fe *NAMESPACE
4f49f7e233d751ddde650443197a1e67 *NEWS.md
3d99d2c6e7b65740c7ad8a6d1d7d0ef3 *R/assumptionCheck.R
ae93b1c8955d7d8d4e291abfeaff0a48 *R/bridge.R
84f152b5a0fbdccef8aafb2a622e9488 *R/bridge.R
db9fae5fe89d0a82e7a600227a65791e *R/data_documentation.R
9749b1badaa667b773d82e9af8708ec5 *R/edge_impact.R
145a2e5fd3c7c6371f91fcfa706b1435 *R/expectedInf.R
b2885be98c23ad6c55ff538baaf3fcd8 *R/global_impact.R
adb44b8453d8b1c7b49f8fa9b4456e40 *R/goldbricker.R
a0ad9eebcb8f0b37ed45f485eb8ee871 *R/goldbricker.R
a1da90e3a1653f93c3d230e59ae8b2ea *R/hidden_functions.R
1c85bff098685d22d00a14eb9888532e *R/impact.R
40fe130ee122e9688390176d3b8442e9 *R/impact_NCT.R
27ee303b044436d7f57fb0f90014ae7d *R/impact_boot.R
04fea955be37527e0e9be58480ce4a8f *R/imports.R
ac299122ddd05cbfd99918bcfca28adc *R/imports.R
219246837987178d79c9a42d53b13aea *R/net_reduce.R
f19d1aae4aca9e5cb9c6f2f960007e79 *R/networktools-package.r
0b8b93933f1459e0d9f5d95397de60ba *R/structure_impact.R
8d93e1868364c608ee8e68ee1be74795 *R/summary_print_plot.R
52d31c34e36217883af064e2fe49990c *build/vignette.rds
0b16c9dbcaf68c871633230978462c9f *R/summary_print_plot.R
e326373c6457ada83f2a0bd8d29d03bd *build/vignette.rds
b36c9ac17ed19012e016f719d89696a0 *data/depression.rda
089c6b27af88285ef845229c2e78467e *data/social.rda
3db79a48f7a5dd0c2ac19d5ff25d4210 *inst/doc/Impact.R
a8276d44a21865c39e84f213f9ba7292 *inst/doc/Impact.Rmd
a2abd130b0bc8c0ed56d4cd4fb445509 *inst/doc/Impact.pdf
6359b531d14396c373f2b3a725d1155c *inst/doc/Impact.pdf
1bee5e1beed0961552ebf69e23f7478c *inst/doc/Impact.pdf.asis
44951a88c1e44e76cac482e007d3abe4 *man/assumptionCheck.Rd
70861b8ba8877c1ae6ddadcd16bf5942 *man/bridge.Rd
0b68a2d1c80b4650dbc0068167276beb *man/bridge.Rd
6312ee98bdd8bca8e33c7c3f763b0aea *man/coerce_to_adjacency.Rd
6b369dc2cc0ed86fa1f64b081c09b78a *man/depression.Rd
973979c2b8a3aa490f81f7ad3de76a2e *man/edge.impact.Rd
c006aa48ab73bfabb3879dcc024cbe58 *man/expectedInf.Rd
dfbd199423233683e1d46374d5f401c9 *man/global.impact.Rd
5ca7a38e6e206fcfec187bc11353c67d *man/goldbricker.Rd
2347aa391d1e01ffc7760ffcc23df23d *man/goldbricker.Rd
2fc456793c379430e12378b37ee2407f *man/impact.NCT.Rd
00cb8a470e756a614b7378773339d5f5 *man/impact.Rd
e860314e7d136e76e43e6ac589b2c489 *man/impact.boot.Rd
fdeab966f3a53f237747d18de718515f *man/net_reduce.Rd
1156dead634fe0c301412661d9ecdfc6 *man/networktools.Rd
622dc6d76e9c19cedbd971963dd8a130 *man/plot.all.impact.Rd
dda646c0e050f98b4e9c802b9b6054c8 *man/plot.bridge.Rd
1de9ae805ced4579247389f35fb588ec *man/plot.bridge.Rd
16cb20ca730dcd91fdc64d7236f5e04d *man/plot.edge.impact.Rd
29c614a613fd8dc24f48db94883d489a *man/plot.expectedInf.Rd
d1425df1dc7d666b82e32ca2ce3c07fb *man/plot.global.impact.Rd
8d8c76b274704cb0f52f0dce98c260a2 *man/plot.structure.impact.Rd
1077043d1e1e5092559f7acdb02205db *man/social.Rd
e5bea2ea7a637816fa7f527e8df55249 *man/structure.impact.Rd
a8276d44a21865c39e84f213f9ba7292 *vignettes/Impact.Rmd
41d8ebd21578934b1c0fd6fa944dc9ad *vignettes/figures/pe_figure.png
1bee5e1beed0961552ebf69e23f7478c *vignettes/Impact.pdf.asis
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -32,6 +32,7 @@ export(impact.NCT)
export(impact.boot)
export(net_reduce)
export(structure.impact)
importFrom(RColorBrewer,brewer.pal)
importFrom(igraph,E)
importFrom(stats,cor)
importFrom(stats,median)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Expand Up @@ -13,3 +13,7 @@
* The goldbricker() and net_reduce() functions are now available. Useful for comparing correlations
in order to eliminate nodes in networks which ostensibly measure the same construct

# networktools 1.1.2

* Additions to bridge() function: can use list input for communities, improved error handling
* New argument "corMin" in goldbricker function
42 changes: 29 additions & 13 deletions R/bridge.R
Expand Up @@ -9,7 +9,8 @@
#' a network
#' @param communities an object of class "communities" (igraph) OR a character vector of
#' community assignments for each node (e.g., c("Comm1", "Comm1", "Comm2", "Comm2)).
#' The ordering of this vector should correspond to the vector from argument "nodes"
#' The ordering of this vector should correspond to the vector from argument "nodes".
#' Can also be in list format (e.g., list("Comm1"=c(1:10), "Comm2"=c(11:20)))
#' @param useCommunities character vector specifying which communities should be included. Default set to "all"
#' @param directed logical. Directedness is automatically detected if set to "NULL" (the default).
#' Symmetric adjacency matrices will be undirected, asymmetric matrices will be directed
Expand Down Expand Up @@ -88,16 +89,6 @@ bridge <- function(network, communities=NULL, useCommunities="all", directed=NUL
#coerce_to_adjacency includes auto-detection of directedness
if(is.null(directed)) {directed<-attr(adj,"directed")}

#useCommunities
if(useCommunities[1]!="all"){
if(is.null(communities) | class(communities)=="function"){
stop("Communities must be prespecified to utilize the useCommunities argument")
}
innodes <- communities %in% useCommunities
communities <- communities[innodes]
adj <- adjmat <- adj[innodes,innodes]
}

# get igraph of complete network
if(directed) {
g <- igraph::graph_from_adjacency_matrix(adj, mode="directed", diag=FALSE, weighted= TRUE)
Expand All @@ -107,14 +98,35 @@ bridge <- function(network, communities=NULL, useCommunities="all", directed=NUL

#if communities not supplied, use spinglass default settings to detect
if(is.null(communities) | class(communities)=="function"){
if(useCommunities != "all"){
stop("You must prespecify communities to use the useCommunities argument")
}
communities <- try(igraph::spinglass.community(g, spins=3))
if(class(communities)=="try-error") {stop("Automatic community detection failed. Please prespecify communities")}
message("Note: Communities automatically detected with spinglass. Use \'communities\' argument to prespecify community structure")
}

if(is.null(nodes)){nodes <- colnames(adj)}
if(class(communities)=="communities") {communities <- communities$membership}
if(is.list(communities)){communities <- as.character(utils::stack(communities)$ind)}

#useCommunities
if(useCommunities[1]!="all"){
innodes <- communities %in% useCommunities
communities <- communities[innodes]
adj <- adjmat <- adj[innodes,innodes]
}

#Check for common communities issues
if(length(unique(communities))==0){
stop("No viable communities")
}
if(length(unique(communities))==1){
stop("Only 1 community specified, bridge centrality cannot be computed")
}
if(length(communities)!=length(nodes)){
stop("Length of communities argument does not match number of nodes")
}

#take inverse of weight for igraph object "g" only (igraph's length functions view small edges as closer)
igraph::E(g)$weight <- 1/igraph::E(g)$weight
Expand Down Expand Up @@ -200,8 +212,12 @@ bridge <- function(network, communities=NULL, useCommunities="all", directed=NUL
names(communities) <- nodes
included_nodes <- unique(c(node_of_interest, names(communities[communities==unique(communities)[j]])))
new_net <- network[included_nodes, included_nodes]
new_net[node_of_interest, node_of_interest] <- 0 # a self loop isn't a bridge
ei1_node <- expectedInf(new_net, step=1, directed=directed)[[1]][node_of_interest]
if(is.matrix(new_net)){
new_net[node_of_interest, node_of_interest] <- 0 # a self loop isn't a bridge
ei1_node <- expectedInf(new_net, step=1, directed=directed)[[1]][node_of_interest]
} else {
ei1_node <- 0
}
return(ei1_node)
}
## This loop creates a list of j vectors
Expand Down
12 changes: 8 additions & 4 deletions R/goldbricker.R
Expand Up @@ -8,6 +8,8 @@
#' @param method method for comparing correlations. See ?cocor.dep.groups.overlap for a full list
#' @param threshold variable pairs which have less than the threshold proportion of significantly different
#' correlations will be considered "bad pairs"
#' @param corMin the minimum zero-order correlation between two items to be considered "bad pairs". Items
#' that are uncorrelated are unlikely to represent the same underlying construct
#' @param progressbar logical. prints a progress bar in the console
#'
#' @details
Expand Down Expand Up @@ -36,7 +38,7 @@
#' reduced_depression <- net_reduce(data=depression, badpairs=gb_depression)
#'
#' ## Set a new threshold quickly
#' goldbricker(gb_depression, threshold=0.6)
#' gb_depression_60 <- goldbricker(data=gb_depression, threshold=0.6)
#'
#'}
#' @return \code{\link{goldbricker}} returns a list of class "\code{goldbricker}" which contains:
Expand All @@ -49,7 +51,7 @@
#'
#'
#'@export
goldbricker <- function(data, p=0.05, method="hittner2003", threshold=0.25, progressbar=TRUE) {
goldbricker <- function(data, p=0.05, method="hittner2003", threshold=0.25, corMin=0.5, progressbar=TRUE) {
if(class(data)!="goldbricker"){
cormat <- qgraph::cor_auto(data)
n <- nrow(data)
Expand Down Expand Up @@ -82,14 +84,16 @@ goldbricker <- function(data, p=0.05, method="hittner2003", threshold=0.25, prog
diag(perc_reject) <- NA
} else{
perc_reject <- data$proportion_matrix
cormat <- perc_reject
}
combnames <- matrix(as.numeric(),dim(perc_reject)[1],dim(perc_reject)[1])
for(i in 1:dim(perc_reject)[1]){for(j in 1:dim(perc_reject)[1]){
combnames[i,j] <- paste(colnames(perc_reject)[i], colnames(perc_reject)[j], sep=" & ")
}}
lower <- perc_reject[lower.tri(perc_reject)]
names(lower) <- combnames[lower.tri(combnames)]
suggested_reductions <- lower[lower<threshold][order(lower[lower<threshold])]
lower_cor <- cormat[lower.tri(cormat)]
names(lower) <- names(lower_cor) <- combnames[lower.tri(combnames)]
suggested_reductions <- lower[lower<threshold&lower_cor>corMin][order(lower[lower<threshold&lower_cor>corMin])]
if(length(suggested_reductions)==0){suggested_reductions <- "No suggested reductions"}
res <- list(proportion_matrix=perc_reject,
suggested_reductions=suggested_reductions,
Expand Down
1 change: 1 addition & 0 deletions R/imports.R
@@ -1,4 +1,5 @@
#' @importFrom stats cor median na.omit prcomp
#' @importFrom utils setTxtProgressBar txtProgressBar
#' @importFrom igraph E
#' @importFrom RColorBrewer brewer.pal
NULL
15 changes: 11 additions & 4 deletions R/summary_print_plot.R
Expand Up @@ -497,6 +497,7 @@ plot.expectedInf <- function(x, order=c("given","alphabetical", "value"), zscore
#' @param include a vector of centrality measures to include ("Bridge Strength", "Bridge Betweenness", "Bridge Closeness",
#' "Bridge Expected Influence (1-step)", "Bridge Expected Influence (2-step)"),
#' if missing all available measures will be plotted
#' @param RColorBrewer A palette name from RColorBrewer, for coloring of axis labels
#' @param ... other plotting specifications in ggplot2 (aes)
#'
#' @details
Expand All @@ -514,9 +515,12 @@ plot.expectedInf <- function(x, order=c("given","alphabetical", "value"), zscore
#'}
#' @method plot bridge
#' @export
plot.bridge <- function(x, order=c("given","alphabetical", "value"), zscore=FALSE, include, ...){
plot.bridge <- function(x, order=c("given","alphabetical", "value"), zscore=FALSE, include, RColorBrewer="Dark2", ...){
attr(x, "class") <- NULL
nodes <- names(x[[1]])
comm <- x$communities; commcol <- vector(); pal <- brewer.pal(max(length(unique(comm)), 3), RColorBrewer)
for(i in 1:length(unique(comm))){commcol[i] <- pal[i]}
cols <- commcol[match(comm, unique(comm))]
x$communities <- NULL
if(zscore) {
scalenoatt <- function(y){
Expand All @@ -538,13 +542,15 @@ plot.bridge <- function(x, order=c("given","alphabetical", "value"), zscore=FALS
Long$node <- factor(as.character(Long$node), levels = rev(unique(as.character(Long$node))))
g <- ggplot2::ggplot(Long, ggplot2::aes_string(x = 'value', y = 'node', group = 'type', ...))
g <- g + ggplot2::geom_path() + ggplot2::xlab("") + ggplot2::ylab("") + ggplot2::geom_point()
g <- g + ggplot2::facet_grid('~measure', scales = "free")
g <- g + ggplot2::facet_grid('~measure', scales = "free") +
ggplot2::theme(axis.text.y = ggplot2::element_text(colour=rev(cols)))
} else if(order[1]=="alphabetical"){
Long <- Long[with(Long, order(Long$node)),]
Long$node <- factor(as.character(Long$node), levels = unique(as.character(Long$node)[order(Long$node)]))
g <- ggplot2::ggplot(Long, ggplot2::aes_string(x='value', y='node', group='type', ...))
g <- g + ggplot2::geom_path() + ggplot2::geom_point() + ggplot2::xlab("") + ggplot2::ylab("") +
ggplot2::facet_grid('~measure', scales="free") + ggplot2::scale_y_discrete(limits = rev(levels(Long$node)))
ggplot2::facet_grid('~measure', scales="free") + ggplot2::scale_y_discrete(limits = rev(levels(Long$node))) +
ggplot2::theme(axis.text.y = ggplot2::element_text(colour=cols[order(nodes, decreasing=T)]))
} else if(order[1]=="value") {
glist <- list()
for(i in 1:length(include)) {
Expand All @@ -553,7 +559,8 @@ plot.bridge <- function(x, order=c("given","alphabetical", "value"), zscore=FALS
temp_Long$node <- factor(as.character(temp_Long$node), levels = unique(as.character(temp_Long$node)[order(temp_Long$value)]))
glist[[i]] <- ggplot2::ggplot(temp_Long, ggplot2::aes_string(x='value', y='node', group='type',...)) +
ggplot2::geom_path() + ggplot2::geom_point() + ggplot2::xlab("") + ggplot2::ylab("") +
ggplot2::facet_grid('~measure', scales="free")
ggplot2::facet_grid('~measure', scales="free") +
ggplot2::theme(axis.text.y = ggplot2::element_text(colour=cols[order(temp_Long$value, decreasing=T)]))
}
if(length(include)==1){g <- gridExtra::grid.arrange(glist[[1]])
} else if(length(include)==2){gridExtra::grid.arrange(glist[[1]],glist[[2]], ncol=2)
Expand Down
Binary file modified build/vignette.rds
Binary file not shown.
99 changes: 0 additions & 99 deletions inst/doc/Impact.R

This file was deleted.

0 comments on commit 6699c9b

Please sign in to comment.