-
Notifications
You must be signed in to change notification settings - Fork 8
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
as.network.data.frame does not handle two-mode adjacency matrices correctly #64
Comments
(for this and #65) I pointed out that using S3 dispatch would be a breaking change when it was requested that I use that instead of the function I originally proposed ( |
Ok, so it sounds like we have an issue to address. IIUC, using the S3 dispatch for this function is what causes the breakage. I believe this choice was originally motivated by maintainability concerns. @CarterButts do you have a preferred solution? |
I have mixed feelings about this. To me, a data frame is not a generalisation of a matrix or an array, though for bipartite networks, it's a bit less clear-cut. That having been said, if I think this would fix @CarterButts's issue. @knapply, is there any reason not to change the |
The input shouldn't be a data frame if it's supposed to be a matrix. The errors could probably be more informative ("is this supposed to be an adjacency matrix? If so, use If memory serves, the reason this is an issue is because the original I'm assuming this normalized the behavior of passing data frames as input that really should've been matrices. |
@knapply, perhaps I misremembered. Does |
Has anything been changed in the
Also an issue here: https://community.rstudio.com/t/as-network-file-ergm-error-loops-is-false-but-x-contains-loops/115793 |
@jdohmen indeed, in the recent version of network the data.frame is interpreted as an edgelist (first two columns) plus optional edge attributes (the remaining columns, if any). In your case the data frame is a "two-mode" (non-square) adjacency matrix. What you need is convert it to R matrix with e.g. d <- data.frame(
+ a = c(0,0,1,1),
+ b = c(0,0,1,0),
+ c = c(1,1,0,0)
+ )
net <- as.network(data.matrix(d), bipartite = TRUE)
as.matrix(net)
# a b c
# 1 0 0 1
# 2 0 0 1
# 3 1 1 0
# 4 1 0 0 In your case it will be something like WissOperativeAnpass1 <- read_excel("WissOperativeAnpass.xlsx")
NetWissOperativeAnpass1 <- as.network(data.matrix(WissOperativeAnpass1), bipartite = TRUE) ... assuming you have no other columns in Excel beyond the adjacency information. |
@krivit @knapply @CarterButts , is it feasible to retain the original behavior by having an argument to |
Then PLEASE also add a NODELIST (ego, alter1, alter2). Empirical survey data mostly comes as a NODELIST. I have spent so much time with getting nodelists into statnet: |
When called with a two-mode adjacency matrix,
as.network.matrix
will correctly interpret this as a graph with an enforced bipartition, with the passed matrix being the off-diagonal portion of the full adjacency matrix.as.network.data.frame
will not, and indeed returns errors if e.g. the matrix is square and has non-zero diagonal entries whenloops==FALSE
. (See also related issue ofas.network.data.frame
not respecting the same semantics asas.network.matrix
.) Settingloops=TRUE
andbipartite=TRUE
does not rectify the problem, because it throws an error when loops are set on bipartite graphs.For this issue, the needed fix is for
as.network.data.frame
to correctly detect and implement two-mode matrix processing. Here is a demonstration:We should be seeing the same behavior for
as.network.data.frame
asas.network.matrix
here, and are not.The text was updated successfully, but these errors were encountered: