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.










share|improve this question
























  • 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










  • 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















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.










share|improve this question
























  • 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










  • 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













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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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










  • 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










  • 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












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





share|improve this answer























  • 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 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













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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





share|improve this answer























  • 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 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

















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





share|improve this answer























  • 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 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















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





share|improve this answer














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






share|improve this answer














share|improve this answer



share|improve this answer








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




















  • 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 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


















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




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff