# Monte Carlo or Bootstrapping for network in R

I have a large network for which I'm using iGraph in R to handle. However, I would like to take some small random samples of that network, and calculate for example the standard deviation of parallel edges weights, to see how much do they actually vary.

When looking at the data on a table format, it looks like this:

Origin  Destination  Weight
A         B          30
A         B          19
A         C           1
B         D          15
B         D          40


Surely this is just a small example, but I wonder how could I do it using either iGraph or any other packages in R. I've been searching already for a while but I'm not sure how to. I assume that I would need either Bootstrapping or Monte Carlo methods for this, but code wise there isn't much info floating around.

EDIT:

The idea behind what I want to do is well explained here:

observed data are resampled to create new datasets that match the size of the original data, while allowing the same observations to be drawn multiple times. This creates slightly different datasets each time, but always based on the same original observations. Repeating this process hundreds of times and re-calculating a given statistic for each new dataset generates a distribution of possible values. Lusseau et al. [9] suggested that this approach could be incorporated into social network analysis. In the case of networks, the observation data from which the observed network was generated is bootstrapped (observations are resampled, rather than resampling nodes) and a new network is generated for each dataset by re-calculating all the edge weights in exactly the same way. The statistic of interest in the observed network is re-calculated each time and recorded. The 95% confidence interval can then be inferred by extracting the 2.5% and 97.5% quantiles of the recorded values.

(Estimating uncertainty and reliability of social network data using Bayesian inference - R. Farine et al.)

• Similar question on SO: stackoverflow.com/questions/16289353/… cbind( get.edgelist(g) , round( E(g)\$weight, 3 )) Feb 26, 2018 at 16:44
• Unfortunately not similar. I know how to get an edge list as I've shown above. What I wanted to understand is how to run some sort of bootstrapping or Monte Carlo simulation on that sort of data. Probably I wasn't clear enough with my post. Feb 26, 2018 at 17:23
• What you describe isn't bootstrapping nor is it Monte Carlo simulation. It's hard to determine what you really want, except that you want to do it in R. If you want to see how properties of your network vary, then you need to study the network itself rather than sample from it or simulate something.
– whuber
Feb 26, 2018 at 18:50
• @whuber, it's not about how the network varies. What I want is to take small random samples of the network, and see which edges are constant. If I take for example 1000, 10% samples of a network, which edges will be preserved. Same with the table above. If I take a random 10% sample 1000 times, what will change? If it's not bootstrapping, or MC, then what might it be? Feb 26, 2018 at 18:54
• What do you mean, then, by your request "to see how much do they actually vary"? I cannot tell from your description. It's unclear how you want to sample a network, what would constitute a sample, or even what you mean by "edges are constant," because I can think of many different interpretations of all of these. Perhaps you could explain what you're trying to get at by offering a small example in the question.
– whuber
Feb 26, 2018 at 18:56

I'm working on a similar problem and hoping for a similar approach. So far I have little progress but it seems 'bootnet' is an option.

library(igraph)
library(bootnet)

g1 <- sample_pa_age(...., pa.exp=..., aging.exp=...., aging.bin=1000)
g2 <- as_data_frame(g1, what="edges")
results <- bootnet(g2, nBoots=1000, statistics = "betweenness", default = "EBICglasso", sampleSize=500, type = "nonparametric")


BUT I still need to contact 'bootnet' as I am having different problems with this approach. BUT at least, "a bootstrap" was implemented.

Pls update me if you have a better solution or what happened with your bootnet results. 'Would want to know if we have similar issues with bootnet.

• I suggest you to take a look at this package github.com/cran/snowboot. At least it has more information on what it does and how. Unfortunately the bootnet package barely includes any documentation. Mar 5, 2018 at 14:51
• Just got back to this project. I successfully "bootstraped" an igraph by juggling igraph functions 'as_data_frame' and 'graph_from_data_frame'. It is easy to use 'sample' function when we have a data.frame. But we can only compute graph characteristics when data is an igraph. Mar 22, 2018 at 8:12
• The problem is that whenever you transform it into a data.frame, I'm not 100% sure of how does that take into account the fact we're working with a network. Meaning that making sure that the edge distribution will be taken into account. But again, I've never looked into that package's code, so I'm not sure how do they do it. Mar 26, 2018 at 8:15

I have a similar problem. As far as I know, the idea of the Monte Carlo method applied to networks is to allow simulating networks with certain parameters (for example, number of vertices and edges) and then calculate certain statistics of interest to compare their distribution against the observed measures. This is very different to Bootstrap. Some graph generators are available in Igraph: sample_gnp, sample_gnm, sample_pa, sample_smallworld. But I don't know how to calculate and get the metrics in each network in a unified way to get the percentiles of the estimates (as confidence intervals).