network icon indicating copy to clipboard operation
network copied to clipboard

does `as.sna.edgelist = TRUE` argument to `as.edgelist` behave as intended?

Open chad-klumb opened this issue 2 years ago • 0 comments

e.g.

require(network)
nw <- network.initialize(2, directed = FALSE)
nw[1,2] <- 1
as.matrix.network.edgelist(nw, as.sna.edgelist = FALSE)
as.matrix.network.edgelist(nw, as.sna.edgelist = TRUE)
as.edgelist(nw, as.sna.edgelist = FALSE)
as.edgelist(nw, as.sna.edgelist = TRUE)

produces

> as.matrix.network.edgelist(nw, as.sna.edgelist = FALSE)
     [,1] [,2]
[1,]    1    2
attr(,"n")
[1] 2
attr(,"vnames")
[1] 1 2
> as.matrix.network.edgelist(nw, as.sna.edgelist = TRUE)
     [,1] [,2] [,3]
[1,]    1    2    1
[2,]    2    1    1
attr(,"n")
[1] 2
attr(,"vnames")
[1] 1 2
> as.edgelist(nw, as.sna.edgelist = FALSE)
     [,1] [,2]
[1,]    1    2
attr(,"n")
[1] 2
attr(,"vnames")
[1] 1 2
attr(,"directed")
[1] FALSE
attr(,"bipartite")
[1] FALSE
attr(,"loops")
[1] FALSE
attr(,"class")
[1] "matrix_edgelist" "edgelist"        "matrix"          "array"          
> as.edgelist(nw, as.sna.edgelist = TRUE)
     [,1] [,2] [,3]
[1,]    1    2    1
attr(,"n")
[1] 2
attr(,"vnames")
[1] 1 2
attr(,"directed")
[1] FALSE
attr(,"bipartite")
[1] FALSE
attr(,"loops")
[1] FALSE
attr(,"class")
[1] "matrix_edgelist" "edgelist"        "matrix"          "array"          

i.e. the screening of edges in as.edgelist.matrix (which does not receive or recognize as.sna.edgelist in the current implementation) is dropping the "reversed" edge 2 1 from the output when as.sna.edgelist = TRUE is passed to as.edgelist, which seems like not what we want for sna (based on the behavior of as.matrix.network.edgelist).

chad-klumb avatar Apr 18 '22 14:04 chad-klumb