# 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 )) – JasonRDalton Feb 26 '18 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. – FilipeTeixeira Feb 26 '18 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 '18 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? – FilipeTeixeira Feb 26 '18 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 '18 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. – FilipeTeixeira Mar 5 '18 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. – Erwin Mar 22 '18 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. – FilipeTeixeira Mar 26 '18 at 8:15
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.619240939617157, "perplexity": 624.2162323385219}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-35/segments/1566027331485.43/warc/CC-MAIN-20190826085356-20190826111356-00204.warc.gz"}