graph - valued bipartite projection using R igraph -
i trying create valued bipartite projection data looks following:
name rid emile 17560 lou 11800 luther 11800 tot 11800 phineas 11800 phineas 13580 calvin 13580 calvin 11800 les 11800 jeff 11800 sonny 13580 leon 13580 red 13580
i imported above data , call data1
then following:
##create graph object data1 graph1 <- graph.data.frame(data1) #check if bipartite is.bipartite(graph1) false ##convert bipartite graph v(graph1)$type <- v(graph1)$name %in% data1[,1] ##check again if bipartite is.bipartite(graph1) true ##create biparite projection ##the multiplicity argument suppose count number of ##edges proj<-bipartite.projection(graph1, v(graph1)$type,multiplicity = true) ##get adjacency matrix second projection get.adjacency(proj$proj2)
i following ouput
11 x 11 sparse matrix of class "dgcmatrix" [[ suppressing 11 column names ‘emile ’, ‘lou ’, ‘luther ’ ... ]] emile . . . . . . . . . . . lou . . 1 1 1 . 1 1 1 . . luther . 1 . 1 1 . 1 1 1 . . tot . 1 1 . 1 . 1 1 1 . . phineas . 1 1 1 . . 1 1 1 . . phineas . . . . . . 1 . . 1 1 calvin . 1 1 1 1 1 . 1 1 1 1 les . 1 1 1 1 . 1 . 1 . . jeff . 1 1 1 1 . 1 1 . . . sonny . . . . . 1 1 . . . 1 leon . . . . . 1 1 . . 1 .
and
3 x 3 sparse matrix of class "dgcmatrix" 17560 11800 13580 17560 . . . 11800 . . 1 13580 . 1 .
instead of phineas , calvin having 2 edges through ***rid***s 13580 , 11800, phineas appears twice. , plot of "rid" projection shows 1 edge between 13580 , 11800. plot "name" shows phineas twice.
i appreciate suggestions modify code valued projection , adjacency matrix. thank you!
edit #1: phineas appearing twice because of type of formatting issue 2 "phinease-s" being recognized separate names. but, fixing still not solve main problem. output still gives 1 edge between phineas , calvin , between 13580 , 11800.
edit #2: session info results
r version 3.1.0 (2014-04-10) platform: i386-w64-mingw32/i386 (32-bit) locale: [1] lc_collate=english_united states.1252 lc_ctype=english_united states.1252 lc_monetary=english_united states.1252 [4] lc_numeric=c lc_time=english_united states.1252 attached base packages: [1] stats graphics grdevices utils datasets methods base other attached packages: [1] igraph_1.0.1 loaded via namespace (and not attached): [1] grid_3.1.0 lattice_0.20-29 magrittr_1.5 matrix_1.1-3 tools_3.1.0
\
edit #3
desired output 3 x 3 sparse matrix of class "dgcmatrix" 17560 11800 13580 17560 . . . 11800 . . 2 13580 . 2 . 11 x 11 sparse matrix of class "dgcmatrix" [[ suppressing 11 column names ‘emile ’, ‘lou ’, ‘luther ’ ... ]] emile . . . . . . . . . . . lou . . 1 1 1 . 1 1 1 . . luther . 1 . 1 1 . 1 1 1 . . tot . 1 1 . 1 . 1 1 1 . . phineas . 1 1 1 . 2 1 1 1 1 calvin . 1 1 1 2 1 . 1 1 1 1 les . 1 1 1 1 . 1 . 1 . . jeff . 1 1 1 1 . 1 1 . . . sonny . . . . . 1 1 . . . 1 leon . . . . . 1 1 . . 1 .
i not know have done. more information necessary: sessioninfo() check system using , version of packages.
this i've found in pc (see below result of sessioninfo()
the data
data1 <- read.table(text="name rid emile 17560 lou 11800 luther 11800 tot 11800 phineas 11800 phineas 13580 calvin 13580 calvin 11800 les 11800 jeff 11800 sonny 13580 leon 13580 red 13580", header=true)
check data
head(data1) dim(data1) str(data1) plot(data1)
call library
library(igraph)
create graph object data1
graph1 <- graph.data.frame(data1)
check if bipartite
is.bipartite(graph1) ### false
convert bipartite graph
v(graph1)$type <- v(graph1)$name %in% data1[,1]
check again if bipartite
is.bipartite(graph1) ### true
create biparite projection multiplicity argument suppose count number of edges
proj<-bipartite.projection(graph1, v(graph1)$type,multiplicity = true)
get adjacency matrix first projection
t1 <- get.adjacency(proj$proj1) t1
loading required package: matrix
11 x 11 sparse matrix of class "dgcmatrix"
[[ suppressing 11 column names ‘emile’, ‘lou’, ‘luther’ ... ]]
emile . . . . . . . . . . .
lou . . 1 1 1 1 1 1 . . .
luther . 1 . 1 1 1 1 1 . . .
tot . 1 1 . 1 1 1 1 . . .
phineas . 1 1 1 . 1 1 1 1 1 1
calvin . 1 1 1 1 . 1 1 1 1 1
les . 1 1 1 1 1 . 1 . . .
jeff . 1 1 1 1 1 1 . . . .
sonny . . . . 1 1 . . . 1 1
leon . . . . 1 1 . . 1 . 1
red . . . . 1 1 . . 1 1 .
get adjacency matrix second projection
t2 <- get.adjacency(proj$proj2) t2
3 x 3 sparse matrix of class "dgcmatrix"
17560 11800 13580
17560 . . .
11800 . . 1
13580 . 1 .
plot matrix
g1 <- graph.adjacency(t1) plot(g1)
result of sessioninfo() r version 3.0.2 (2013-09-25) platform: x86_64-w64-mingw32/x64 (64-bit)
locale: [1] lc_collate=italian_italy.1252 lc_ctype=italian_italy.1252 [3] lc_monetary=italian_italy.1252 lc_numeric=c [5] lc_time=italian_italy.1252 attached base packages:[1] stats graphics grdevices utils datasets methods base other attached packages: [1] matrix_1.1-0 igraph_0.6.6 loaded via namespace (and not attached): [1] grid_3.0.2 lattice_0.20-24
Comments
Post a Comment