2017-06-21 41 views
3

我使用版本0.99.879和包版本1.0.1。我的問題與此問題密切相關:igraph package in RStudio: Bipartite graph projection error
但是,我的問題更多地涉及到數據結構。下面是我用csv.file的一個例子的鏈接:https://workupload.com/file/6qhyZqc和下面的代碼:二分圖投影錯誤(igraph,RStudio)

# 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 


一切順利,除了投影指示。所以,代碼不是問題。也許錯誤/問題可能在數據本身。由於我已經使用這些數據已經有一段時間了,我認爲,我的專業態度是盲目的。如果其他人可以查看發佈的示例數據並提出建議,可能會出現什麼情況,那將是非常好的。
任何幫助非常歡迎!

回答

2

我的預感是你在同一個聯盟的兩個節點之間有一個聯繫。有點搜索,實際情況就是這樣。

請注意,您必須在字符串中「其他」的data_new列:

data_new[which(data_new[,1] %in% data_new[,2]),1] 
[1] "other" 

igraph讀取字符串作爲網絡中的一個節點。 V(g)$type[V(g)$name %in% data_new[, 1]] <- TRUEtype的值爲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" 

第十二屆邊緣,既有頂點具有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 
+0

大。你的回答正是我所期待的(並指出我在其他數據集中的其他「編碼相似性」)。非常感謝! –