Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directed metrics #22

Open
wants to merge 5 commits into
base: development
Choose a base branch
from

Conversation

aj2duncan
Copy link
Contributor

What my pull improves (if applicable)

#21

This is just something I would like to be able to do directly, rather than having to use the metric calculations with sizeVector(). I completely understand if it isn't a functionality that you interested in.

Confirmation that you have tested your code

The code below demonstrates that the updated function produces the same results as direct calculation.

# testing directed networks
library(sigmaNet)
library(igraph)
library(magrittr)

set.seed(42)
g <- sample_gnm(25, 50, directed = TRUE)
V(g)$label = LETTERS[1:25] # adding labels
layout <- layout_with_kk(g)
sig <- sigmaFromIgraph(g, layout = layout)

# test the defaults match the expected results
sig_graph1a <- sig %>%
  addNodeSize(minSize = 1, maxSize = 8)
sig_graph1b <- sig %>%
  addNodeSize(sizeMetric = "closeness", minSize = 1, maxSize = 8)
# same but using igraph to calculate values directly
sig_graph2a <- sig %>%
  addNodeSize(sizeVector = degree(g), minSize = 1, maxSize = 8)
sig_graph2b <- sig %>%
  addNodeSize(sizeVector = closeness(g), minSize = 1, maxSize = 8)
# test identical
identical(jsonlite::fromJSON(sig_graph1a$x$data)$nodes$size, 
          jsonlite::fromJSON(sig_graph2a$x$data)$nodes$size)
identical(jsonlite::fromJSON(sig_graph1b$x$data)$nodes$size, 
          jsonlite::fromJSON(sig_graph2b$x$data)$nodes$size)

# repeat for different types
# test the defaults match the expected results
sig_graph1a <- sig %>%
  addNodeSize(sizeMetric = "degree", mode = "in", minSize = 1, maxSize = 8)
sig_graph1b <- sig %>%
  addNodeSize(sizeMetric = "closeness", mode = "in", minSize = 1, maxSize = 8)
# same but using igraph to calculate values directly
sig_graph2a <- sig %>%
  addNodeSize(sizeVector = degree(g, mode = "in"), minSize = 1, maxSize = 8)
sig_graph2b <- sig %>%
  addNodeSize(sizeVector = closeness(g, mode = "in"), minSize = 1, maxSize = 8)
# test identical
identical(jsonlite::fromJSON(sig_graph1a$x$data)$nodes$size, 
          jsonlite::fromJSON(sig_graph2a$x$data)$nodes$size)
identical(jsonlite::fromJSON(sig_graph1b$x$data)$nodes$size, 
          jsonlite::fromJSON(sig_graph2b$x$data)$nodes$size)

# final possible types
# test the defaults match the expected results
sig_graph1a <- sig %>%
  addNodeSize(sizeMetric = "degree", mode = "out", minSize = 1, maxSize = 8)
sig_graph1b <- sig %>%
  addNodeSize(sizeMetric = "closeness", mode = "all", minSize = 1, maxSize = 8)
# same but using igraph to calculate values directly
sig_graph2a <- sig %>%
  addNodeSize(sizeVector = degree(g, mode = "out"), minSize = 1, maxSize = 8)
sig_graph2b <- sig %>%
  addNodeSize(sizeVector = closeness(g, mode = "all"), minSize = 1, maxSize = 8)
# test identical
identical(jsonlite::fromJSON(sig_graph1a$x$data)$nodes$size, 
          jsonlite::fromJSON(sig_graph2a$x$data)$nodes$size)
identical(jsonlite::fromJSON(sig_graph1b$x$data)$nodes$size, 
          jsonlite::fromJSON(sig_graph2b$x$data)$nodes$size)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants