Calculating the share of isolates in R with igraph
up vote
1
down vote
favorite
I am currently working on an analysis of networks in R. I have run into something that does not seem right to me. First some context:
I have created a network with the igraph package with 7231 observations of 4 variables, using the following code:
MyNetwork <- data.frame(Katalog_G_2000_2018_VOLLEDIG$Zuwendungsempfänger, Katalog_G_2000_2018_VOLLEDIG$Ausführende.Stelle, Katalog_G_2000_2018_VOLLEDIG$typ, Katalog_G_2000_2018_VOLLEDIG$verbund)
Network <- graph.data.frame(MyNetwork, directed=F)
After this, I visualised the network with the following code:
plot(Network,vertex.size=6, edge.arrow.size=0.4, main= "ICT-Networks in Germany 2000-2018", vertex.label.cex = 0.8,vertex.label=NA,vertex.color = "green")
Now, I would like to find out how many vertices without edges there are in my network (i.e. the share of isolates). For this I tried using this code:
V(Network)[igraph::degree(Network, mode = "out")>0 & igraph::degree(Network, mode = "in") > 0]
length(V(Network)[igraph::degree(Network, mode = 'out')>0 & igraph::degree(Network, mode = 'in') > 0])
This is where the problem arises. Running this code, tells me that 4305/4305 vertices have edges, while the visualisation of my network clearly shows that there are vertices without edges.
Could anyone please tell me how to fix this code to find out what the share of isolates in my network is? Any other solutions to this problem (using different codes for example) would we greatly appreciated as well. If you need any additional information in order to answer my question, please let me know (unfortunately I can't share my data set at this point).
Thanks in advance.
r networking igraph
add a comment |
up vote
1
down vote
favorite
I am currently working on an analysis of networks in R. I have run into something that does not seem right to me. First some context:
I have created a network with the igraph package with 7231 observations of 4 variables, using the following code:
MyNetwork <- data.frame(Katalog_G_2000_2018_VOLLEDIG$Zuwendungsempfänger, Katalog_G_2000_2018_VOLLEDIG$Ausführende.Stelle, Katalog_G_2000_2018_VOLLEDIG$typ, Katalog_G_2000_2018_VOLLEDIG$verbund)
Network <- graph.data.frame(MyNetwork, directed=F)
After this, I visualised the network with the following code:
plot(Network,vertex.size=6, edge.arrow.size=0.4, main= "ICT-Networks in Germany 2000-2018", vertex.label.cex = 0.8,vertex.label=NA,vertex.color = "green")
Now, I would like to find out how many vertices without edges there are in my network (i.e. the share of isolates). For this I tried using this code:
V(Network)[igraph::degree(Network, mode = "out")>0 & igraph::degree(Network, mode = "in") > 0]
length(V(Network)[igraph::degree(Network, mode = 'out')>0 & igraph::degree(Network, mode = 'in') > 0])
This is where the problem arises. Running this code, tells me that 4305/4305 vertices have edges, while the visualisation of my network clearly shows that there are vertices without edges.
Could anyone please tell me how to fix this code to find out what the share of isolates in my network is? Any other solutions to this problem (using different codes for example) would we greatly appreciated as well. If you need any additional information in order to answer my question, please let me know (unfortunately I can't share my data set at this point).
Thanks in advance.
r networking igraph
In your last line of code (length
) the condition will return a vector of logicals (TRUE and FALSE). So the length is the same as the number of points. You want to count the TRUEs. You can do this by replacing yourlength
withsum
– G5W
Nov 8 at 15:14
Thanks for your reply. I tried replacing 'length' with 'sum' and got 9268665 back from R.This doesn't seem plausible to me, given the fact that there are 4305 vertices in the network. Do you think I maybe misunderstood your reply?
– Freek
Nov 9 at 11:56
Could it be that the isolated vertices have self edges (self-loops)?
– adm
Nov 9 at 16:55
If I got it right, I removed all the loops with this code <Network <- simplify(Network, remove.multiple = F, remove.loops = T), so I don't think that's the problem. Thanks for the suggestion though!
– Freek
Nov 10 at 13:04
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am currently working on an analysis of networks in R. I have run into something that does not seem right to me. First some context:
I have created a network with the igraph package with 7231 observations of 4 variables, using the following code:
MyNetwork <- data.frame(Katalog_G_2000_2018_VOLLEDIG$Zuwendungsempfänger, Katalog_G_2000_2018_VOLLEDIG$Ausführende.Stelle, Katalog_G_2000_2018_VOLLEDIG$typ, Katalog_G_2000_2018_VOLLEDIG$verbund)
Network <- graph.data.frame(MyNetwork, directed=F)
After this, I visualised the network with the following code:
plot(Network,vertex.size=6, edge.arrow.size=0.4, main= "ICT-Networks in Germany 2000-2018", vertex.label.cex = 0.8,vertex.label=NA,vertex.color = "green")
Now, I would like to find out how many vertices without edges there are in my network (i.e. the share of isolates). For this I tried using this code:
V(Network)[igraph::degree(Network, mode = "out")>0 & igraph::degree(Network, mode = "in") > 0]
length(V(Network)[igraph::degree(Network, mode = 'out')>0 & igraph::degree(Network, mode = 'in') > 0])
This is where the problem arises. Running this code, tells me that 4305/4305 vertices have edges, while the visualisation of my network clearly shows that there are vertices without edges.
Could anyone please tell me how to fix this code to find out what the share of isolates in my network is? Any other solutions to this problem (using different codes for example) would we greatly appreciated as well. If you need any additional information in order to answer my question, please let me know (unfortunately I can't share my data set at this point).
Thanks in advance.
r networking igraph
I am currently working on an analysis of networks in R. I have run into something that does not seem right to me. First some context:
I have created a network with the igraph package with 7231 observations of 4 variables, using the following code:
MyNetwork <- data.frame(Katalog_G_2000_2018_VOLLEDIG$Zuwendungsempfänger, Katalog_G_2000_2018_VOLLEDIG$Ausführende.Stelle, Katalog_G_2000_2018_VOLLEDIG$typ, Katalog_G_2000_2018_VOLLEDIG$verbund)
Network <- graph.data.frame(MyNetwork, directed=F)
After this, I visualised the network with the following code:
plot(Network,vertex.size=6, edge.arrow.size=0.4, main= "ICT-Networks in Germany 2000-2018", vertex.label.cex = 0.8,vertex.label=NA,vertex.color = "green")
Now, I would like to find out how many vertices without edges there are in my network (i.e. the share of isolates). For this I tried using this code:
V(Network)[igraph::degree(Network, mode = "out")>0 & igraph::degree(Network, mode = "in") > 0]
length(V(Network)[igraph::degree(Network, mode = 'out')>0 & igraph::degree(Network, mode = 'in') > 0])
This is where the problem arises. Running this code, tells me that 4305/4305 vertices have edges, while the visualisation of my network clearly shows that there are vertices without edges.
Could anyone please tell me how to fix this code to find out what the share of isolates in my network is? Any other solutions to this problem (using different codes for example) would we greatly appreciated as well. If you need any additional information in order to answer my question, please let me know (unfortunately I can't share my data set at this point).
Thanks in advance.
r networking igraph
r networking igraph
edited Nov 9 at 11:57
asked Nov 8 at 13:29
Freek
113
113
In your last line of code (length
) the condition will return a vector of logicals (TRUE and FALSE). So the length is the same as the number of points. You want to count the TRUEs. You can do this by replacing yourlength
withsum
– G5W
Nov 8 at 15:14
Thanks for your reply. I tried replacing 'length' with 'sum' and got 9268665 back from R.This doesn't seem plausible to me, given the fact that there are 4305 vertices in the network. Do you think I maybe misunderstood your reply?
– Freek
Nov 9 at 11:56
Could it be that the isolated vertices have self edges (self-loops)?
– adm
Nov 9 at 16:55
If I got it right, I removed all the loops with this code <Network <- simplify(Network, remove.multiple = F, remove.loops = T), so I don't think that's the problem. Thanks for the suggestion though!
– Freek
Nov 10 at 13:04
add a comment |
In your last line of code (length
) the condition will return a vector of logicals (TRUE and FALSE). So the length is the same as the number of points. You want to count the TRUEs. You can do this by replacing yourlength
withsum
– G5W
Nov 8 at 15:14
Thanks for your reply. I tried replacing 'length' with 'sum' and got 9268665 back from R.This doesn't seem plausible to me, given the fact that there are 4305 vertices in the network. Do you think I maybe misunderstood your reply?
– Freek
Nov 9 at 11:56
Could it be that the isolated vertices have self edges (self-loops)?
– adm
Nov 9 at 16:55
If I got it right, I removed all the loops with this code <Network <- simplify(Network, remove.multiple = F, remove.loops = T), so I don't think that's the problem. Thanks for the suggestion though!
– Freek
Nov 10 at 13:04
In your last line of code (
length
) the condition will return a vector of logicals (TRUE and FALSE). So the length is the same as the number of points. You want to count the TRUEs. You can do this by replacing your length
with sum
– G5W
Nov 8 at 15:14
In your last line of code (
length
) the condition will return a vector of logicals (TRUE and FALSE). So the length is the same as the number of points. You want to count the TRUEs. You can do this by replacing your length
with sum
– G5W
Nov 8 at 15:14
Thanks for your reply. I tried replacing 'length' with 'sum' and got 9268665 back from R.This doesn't seem plausible to me, given the fact that there are 4305 vertices in the network. Do you think I maybe misunderstood your reply?
– Freek
Nov 9 at 11:56
Thanks for your reply. I tried replacing 'length' with 'sum' and got 9268665 back from R.This doesn't seem plausible to me, given the fact that there are 4305 vertices in the network. Do you think I maybe misunderstood your reply?
– Freek
Nov 9 at 11:56
Could it be that the isolated vertices have self edges (self-loops)?
– adm
Nov 9 at 16:55
Could it be that the isolated vertices have self edges (self-loops)?
– adm
Nov 9 at 16:55
If I got it right, I removed all the loops with this code <Network <- simplify(Network, remove.multiple = F, remove.loops = T), so I don't think that's the problem. Thanks for the suggestion though!
– Freek
Nov 10 at 13:04
If I got it right, I removed all the loops with this code <Network <- simplify(Network, remove.multiple = F, remove.loops = T), so I don't think that's the problem. Thanks for the suggestion though!
– Freek
Nov 10 at 13:04
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
If your main graph is all connected, you can count the vertices without edges this way.
library(igraph)
length(decompose.graph(Network,
mode = c("weak", "strong"),
max.comps = NA,
min.vertices = 0)
) - 1
Thank you for your reply. The code your provided me with leads to an outcome of '81'. Isn't that a rather small number for a network with 4305 vertices in total? I tried the same code for my other networks (I have a made a few subsets for different time periods) and got '0' as an outcome. Does this mean that my graph isn't connected properly?
– Freek
Nov 9 at 11:52
No, this will only work for your purpose, if your main graph is all connected. The code above is really just counting the sub-graphs. So, each vertices without an edge will be counted as a sub-graph. You could also try adjusting the arguments.
– adm
Nov 9 at 17:01
Okay, thank you. Do you maybe know about a code/method that helps me find out if my main graph is all connected?
– Freek
Nov 10 at 13:06
If you graph has a large portion connected then '81' doesn't seem like a small number. If you want to check if it is connected runis.connected()
. If not, save the decomposed graph list to variable and test an individual component.components <- decompose(g, min.vertices=2) then is.connected(components[[2]])
– adm
Nov 12 at 19:34
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
If your main graph is all connected, you can count the vertices without edges this way.
library(igraph)
length(decompose.graph(Network,
mode = c("weak", "strong"),
max.comps = NA,
min.vertices = 0)
) - 1
Thank you for your reply. The code your provided me with leads to an outcome of '81'. Isn't that a rather small number for a network with 4305 vertices in total? I tried the same code for my other networks (I have a made a few subsets for different time periods) and got '0' as an outcome. Does this mean that my graph isn't connected properly?
– Freek
Nov 9 at 11:52
No, this will only work for your purpose, if your main graph is all connected. The code above is really just counting the sub-graphs. So, each vertices without an edge will be counted as a sub-graph. You could also try adjusting the arguments.
– adm
Nov 9 at 17:01
Okay, thank you. Do you maybe know about a code/method that helps me find out if my main graph is all connected?
– Freek
Nov 10 at 13:06
If you graph has a large portion connected then '81' doesn't seem like a small number. If you want to check if it is connected runis.connected()
. If not, save the decomposed graph list to variable and test an individual component.components <- decompose(g, min.vertices=2) then is.connected(components[[2]])
– adm
Nov 12 at 19:34
add a comment |
up vote
0
down vote
If your main graph is all connected, you can count the vertices without edges this way.
library(igraph)
length(decompose.graph(Network,
mode = c("weak", "strong"),
max.comps = NA,
min.vertices = 0)
) - 1
Thank you for your reply. The code your provided me with leads to an outcome of '81'. Isn't that a rather small number for a network with 4305 vertices in total? I tried the same code for my other networks (I have a made a few subsets for different time periods) and got '0' as an outcome. Does this mean that my graph isn't connected properly?
– Freek
Nov 9 at 11:52
No, this will only work for your purpose, if your main graph is all connected. The code above is really just counting the sub-graphs. So, each vertices without an edge will be counted as a sub-graph. You could also try adjusting the arguments.
– adm
Nov 9 at 17:01
Okay, thank you. Do you maybe know about a code/method that helps me find out if my main graph is all connected?
– Freek
Nov 10 at 13:06
If you graph has a large portion connected then '81' doesn't seem like a small number. If you want to check if it is connected runis.connected()
. If not, save the decomposed graph list to variable and test an individual component.components <- decompose(g, min.vertices=2) then is.connected(components[[2]])
– adm
Nov 12 at 19:34
add a comment |
up vote
0
down vote
up vote
0
down vote
If your main graph is all connected, you can count the vertices without edges this way.
library(igraph)
length(decompose.graph(Network,
mode = c("weak", "strong"),
max.comps = NA,
min.vertices = 0)
) - 1
If your main graph is all connected, you can count the vertices without edges this way.
library(igraph)
length(decompose.graph(Network,
mode = c("weak", "strong"),
max.comps = NA,
min.vertices = 0)
) - 1
edited Nov 9 at 17:03
answered Nov 8 at 22:46
adm
71111
71111
Thank you for your reply. The code your provided me with leads to an outcome of '81'. Isn't that a rather small number for a network with 4305 vertices in total? I tried the same code for my other networks (I have a made a few subsets for different time periods) and got '0' as an outcome. Does this mean that my graph isn't connected properly?
– Freek
Nov 9 at 11:52
No, this will only work for your purpose, if your main graph is all connected. The code above is really just counting the sub-graphs. So, each vertices without an edge will be counted as a sub-graph. You could also try adjusting the arguments.
– adm
Nov 9 at 17:01
Okay, thank you. Do you maybe know about a code/method that helps me find out if my main graph is all connected?
– Freek
Nov 10 at 13:06
If you graph has a large portion connected then '81' doesn't seem like a small number. If you want to check if it is connected runis.connected()
. If not, save the decomposed graph list to variable and test an individual component.components <- decompose(g, min.vertices=2) then is.connected(components[[2]])
– adm
Nov 12 at 19:34
add a comment |
Thank you for your reply. The code your provided me with leads to an outcome of '81'. Isn't that a rather small number for a network with 4305 vertices in total? I tried the same code for my other networks (I have a made a few subsets for different time periods) and got '0' as an outcome. Does this mean that my graph isn't connected properly?
– Freek
Nov 9 at 11:52
No, this will only work for your purpose, if your main graph is all connected. The code above is really just counting the sub-graphs. So, each vertices without an edge will be counted as a sub-graph. You could also try adjusting the arguments.
– adm
Nov 9 at 17:01
Okay, thank you. Do you maybe know about a code/method that helps me find out if my main graph is all connected?
– Freek
Nov 10 at 13:06
If you graph has a large portion connected then '81' doesn't seem like a small number. If you want to check if it is connected runis.connected()
. If not, save the decomposed graph list to variable and test an individual component.components <- decompose(g, min.vertices=2) then is.connected(components[[2]])
– adm
Nov 12 at 19:34
Thank you for your reply. The code your provided me with leads to an outcome of '81'. Isn't that a rather small number for a network with 4305 vertices in total? I tried the same code for my other networks (I have a made a few subsets for different time periods) and got '0' as an outcome. Does this mean that my graph isn't connected properly?
– Freek
Nov 9 at 11:52
Thank you for your reply. The code your provided me with leads to an outcome of '81'. Isn't that a rather small number for a network with 4305 vertices in total? I tried the same code for my other networks (I have a made a few subsets for different time periods) and got '0' as an outcome. Does this mean that my graph isn't connected properly?
– Freek
Nov 9 at 11:52
No, this will only work for your purpose, if your main graph is all connected. The code above is really just counting the sub-graphs. So, each vertices without an edge will be counted as a sub-graph. You could also try adjusting the arguments.
– adm
Nov 9 at 17:01
No, this will only work for your purpose, if your main graph is all connected. The code above is really just counting the sub-graphs. So, each vertices without an edge will be counted as a sub-graph. You could also try adjusting the arguments.
– adm
Nov 9 at 17:01
Okay, thank you. Do you maybe know about a code/method that helps me find out if my main graph is all connected?
– Freek
Nov 10 at 13:06
Okay, thank you. Do you maybe know about a code/method that helps me find out if my main graph is all connected?
– Freek
Nov 10 at 13:06
If you graph has a large portion connected then '81' doesn't seem like a small number. If you want to check if it is connected run
is.connected()
. If not, save the decomposed graph list to variable and test an individual component. components <- decompose(g, min.vertices=2) then is.connected(components[[2]])
– adm
Nov 12 at 19:34
If you graph has a large portion connected then '81' doesn't seem like a small number. If you want to check if it is connected run
is.connected()
. If not, save the decomposed graph list to variable and test an individual component. components <- decompose(g, min.vertices=2) then is.connected(components[[2]])
– adm
Nov 12 at 19:34
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53208743%2fcalculating-the-share-of-isolates-in-r-with-igraph%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
In your last line of code (
length
) the condition will return a vector of logicals (TRUE and FALSE). So the length is the same as the number of points. You want to count the TRUEs. You can do this by replacing yourlength
withsum
– G5W
Nov 8 at 15:14
Thanks for your reply. I tried replacing 'length' with 'sum' and got 9268665 back from R.This doesn't seem plausible to me, given the fact that there are 4305 vertices in the network. Do you think I maybe misunderstood your reply?
– Freek
Nov 9 at 11:56
Could it be that the isolated vertices have self edges (self-loops)?
– adm
Nov 9 at 16:55
If I got it right, I removed all the loops with this code <Network <- simplify(Network, remove.multiple = F, remove.loops = T), so I don't think that's the problem. Thanks for the suggestion though!
– Freek
Nov 10 at 13:04