2017-06-21 11 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

私の勘違いは、同じアフィリエーションの2つのノード間にネクタイがあることです。検索のビットと確かにこれは事実です。あなたがdata_new両方の列の「その他」の文字列を持っている

お知らせ:

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

igraphは、ネットワーク内の1つのノードとして文字列を読み込みます。 V(g)$type[V(g)$name %in% data_new[, 1]] <- TRUEは、そのtypeに対して、TRUEの値を与えます。我々は、そのtype == 'TRUE' 2つの頂点接続するタイ確認でき

> 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 
+0

グレート。あなたの答えはまさに私が探していたものでした(そして、データセットの残りの部分で他の「コーディングの類似点」を指摘しました)。どうもありがとうございます! –

関連する問題