二分图投影错误(igraph,RStudio)
Bipartite graph projection error (igraph, RStudio)
我正在使用 rstudio version 0.99.879 and the package igraph version 1.0.1. My question is closely related to this one on the same problem: igraph package in RStudio: Bipartite graph projection error
However, my question is more related to the data structure. Here is a link to an example of the csv.file that I use: https://workupload.com/file/6qhyZqc 和以下代码:
# Start
set.seed(7)
setwd("C:/Users/Stefan/Desktop/")
data <- read.csv("example.csv", sep=";")
summary(data)
library(igraph)
## using subset function to select 2 variables
data_new <- subset(data, select=c(justification, claimant_function))
data_new
g <- graph.data.frame(data_new, directed = FALSE)
g
col <- c("steelblue1", "white")
shape <- c("circle", "square")
# creating bipartite network
V(g)$type <- FALSE
V(g)$type[V(g)$name %in% data_new[, 1]] <- TRUE
is.bipartite(g)
# TRUE
plot(g, layout = layout.kamada.kawai,
vertex.shape = shape[as.numeric(V(g)$type) + 1],
vertex.color = col[as.numeric(V(g)$type) + 1],
edge.color = 'gray')
# bipartiate projection
one_mode_networks <- bipartite.projection(g)
# Error in .Call("R_igraph_bipartite_projection", graph, types,
# as.integer(probe1), :
# At bipartite.c:198 : Non-bipartite edge found in bipartite projection,
# Invalid value
除了投影命令外,一切正常。所以,代码不是问题。也许 mistake/problem 可能在数据本身中。由于我已经处理数据很长时间了,所以我认为我在专业上被蒙蔽了。如果其他人可以查看已发布的示例数据并可以提出可能是什么问题的建议,那就太好了。
非常欢迎任何帮助!
我的预感是您在同一从属关系的两个节点之间建立联系。有点搜索,确实是这样。
请注意,您在 data_new
的 和 列中都有字符串 'other':
data_new[which(data_new[,1] %in% data_new[,2]),1]
[1] "other"
igraph
将字符串读取为网络中的一个节点。 V(g)$type[V(g)$name %in% data_new[, 1]] <- TRUE
为其 type
赋值 TRUE
。
我们可以看到哪个领带连接了两个 type == 'TRUE'
:
的顶点
> i <- which(V(g)$type[match(ends(g,1:ecount(g))[,1],V(g)$name)] == V(g)$type[match(ends(g,1:ecount(g))[,2],V(g)$name)])
> ends(g, i)
[,1] [,2]
[1,] "financial solidity" "other"
第12条边,两个顶点都有type==TRUE
.
只需重估字符串,使它们不相等,一切顺利。
data_new <- subset(data, select=c(justification, claimant_function))
data_new[which(data_new[,1]=="other"),1] <- "other just"
data_new[which(data_new[,2]=="other"),2] <- "other claim"
g <- graph.data.frame(data_new, directed = FALSE)
# creating bipartite network
V(g)$type <- FALSE
V(g)$type[V(g)$name %in% data_new[, 1]] <- TRUE
is.bipartite(g)
one_mode_networks <- bipartite_projection(g)
检查:
> one_mode_networks
$proj1
IGRAPH UNW- 16 72 --
+ attr: name (v/c), weight (e/n)
+ edges (vertex names):
[1] business --expert/scientist business --public figure
[3] business --media/journalist business --citizen
[5] business --legislative business --ECB
[7] government --media/journalist government --expert/scientist
[9] government --other claim government --legislative
[11] government --ECB government --European Commission
[13] government --other politician/party government --European Parliament
[15] government --citizen government --European Council
+ ... omitted several edges
$proj2
IGRAPH UNW- 16 83 --
+ attr: name (v/c), weight (e/n)
+ edges (vertex names):
[1] political solidarity--monetary solidarity political solidarity--financial solidity
[3] political solidarity--no justification political solidarity--cultural solidarity
[5] political solidarity--sovereignty political solidarity--self interest
[7] political solidarity--economic solidarity political solidarity--human solidarity
[9] financial solidity --social solidarity financial solidity --misuse of solidarity
[11] financial solidity --economic solidarity financial solidity --cultural solidarity
[13] financial solidity --self interest financial solidity --legal regulations
[15] financial solidity --necessity financial solidity --conditionally
+ ... omitted several edges
我正在使用 rstudio version 0.99.879 and the package igraph version 1.0.1. My question is closely related to this one on the same problem: igraph package in RStudio: Bipartite graph projection error
However, my question is more related to the data structure. Here is a link to an example of the csv.file that I use: https://workupload.com/file/6qhyZqc 和以下代码:
# Start
set.seed(7)
setwd("C:/Users/Stefan/Desktop/")
data <- read.csv("example.csv", sep=";")
summary(data)
library(igraph)
## using subset function to select 2 variables
data_new <- subset(data, select=c(justification, claimant_function))
data_new
g <- graph.data.frame(data_new, directed = FALSE)
g
col <- c("steelblue1", "white")
shape <- c("circle", "square")
# creating bipartite network
V(g)$type <- FALSE
V(g)$type[V(g)$name %in% data_new[, 1]] <- TRUE
is.bipartite(g)
# TRUE
plot(g, layout = layout.kamada.kawai,
vertex.shape = shape[as.numeric(V(g)$type) + 1],
vertex.color = col[as.numeric(V(g)$type) + 1],
edge.color = 'gray')
# bipartiate projection
one_mode_networks <- bipartite.projection(g)
# Error in .Call("R_igraph_bipartite_projection", graph, types,
# as.integer(probe1), :
# At bipartite.c:198 : Non-bipartite edge found in bipartite projection,
# Invalid value
除了投影命令外,一切正常。所以,代码不是问题。也许 mistake/problem 可能在数据本身中。由于我已经处理数据很长时间了,所以我认为我在专业上被蒙蔽了。如果其他人可以查看已发布的示例数据并可以提出可能是什么问题的建议,那就太好了。
非常欢迎任何帮助!
我的预感是您在同一从属关系的两个节点之间建立联系。有点搜索,确实是这样。
请注意,您在 data_new
的 和 列中都有字符串 'other':
data_new[which(data_new[,1] %in% data_new[,2]),1]
[1] "other"
igraph
将字符串读取为网络中的一个节点。 V(g)$type[V(g)$name %in% data_new[, 1]] <- TRUE
为其 type
赋值 TRUE
。
我们可以看到哪个领带连接了两个 type == 'TRUE'
:
> i <- which(V(g)$type[match(ends(g,1:ecount(g))[,1],V(g)$name)] == V(g)$type[match(ends(g,1:ecount(g))[,2],V(g)$name)])
> ends(g, i)
[,1] [,2]
[1,] "financial solidity" "other"
第12条边,两个顶点都有type==TRUE
.
只需重估字符串,使它们不相等,一切顺利。
data_new <- subset(data, select=c(justification, claimant_function))
data_new[which(data_new[,1]=="other"),1] <- "other just"
data_new[which(data_new[,2]=="other"),2] <- "other claim"
g <- graph.data.frame(data_new, directed = FALSE)
# creating bipartite network
V(g)$type <- FALSE
V(g)$type[V(g)$name %in% data_new[, 1]] <- TRUE
is.bipartite(g)
one_mode_networks <- bipartite_projection(g)
检查:
> one_mode_networks
$proj1
IGRAPH UNW- 16 72 --
+ attr: name (v/c), weight (e/n)
+ edges (vertex names):
[1] business --expert/scientist business --public figure
[3] business --media/journalist business --citizen
[5] business --legislative business --ECB
[7] government --media/journalist government --expert/scientist
[9] government --other claim government --legislative
[11] government --ECB government --European Commission
[13] government --other politician/party government --European Parliament
[15] government --citizen government --European Council
+ ... omitted several edges
$proj2
IGRAPH UNW- 16 83 --
+ attr: name (v/c), weight (e/n)
+ edges (vertex names):
[1] political solidarity--monetary solidarity political solidarity--financial solidity
[3] political solidarity--no justification political solidarity--cultural solidarity
[5] political solidarity--sovereignty political solidarity--self interest
[7] political solidarity--economic solidarity political solidarity--human solidarity
[9] financial solidity --social solidarity financial solidity --misuse of solidarity
[11] financial solidity --economic solidarity financial solidity --cultural solidarity
[13] financial solidity --self interest financial solidity --legal regulations
[15] financial solidity --necessity financial solidity --conditionally
+ ... omitted several edges