microeco icon indicating copy to clipboard operation
microeco copied to clipboard

Construct and compare with random network

Open Shawane-Wang opened this issue 1 year ago • 8 comments

Hi. Is there any method to construct classic random network or generalized random graph in this package? And could we further compare our network with the constructed random network to characterize our network as presenting non-random interactions of microbiome? Looking forward to your reply.

Shawane-Wang avatar Apr 05 '23 13:04 Shawane-Wang

Do you mean the random network like this (https://rpubs.com/lgadar/generate-graphs) or constructed based on the community with a null model or from a paper? I have not created a functin to directly generate it, but it is relatively easy to do. I will show an example once I am sure the random network you want to do. Comparing networks can be performed with meconetcomp package (https://github.com/ChiLiubio/meconetcomp).

ChiLiubio avatar Apr 06 '23 01:04 ChiLiubio

I mean constructing a random network using parameters from our empirical network (like count of nodes, edges and so on). Here is an example that might be vivid (https://mp.weixin.qq.com/s?__biz=MzIxNzc1Mzk3NQ==&mid=2247484753&idx=1&sn=8b00273dfee2478478d43fbbc8da7bf3&chksm=97f5b549a0823c5f673d77006ace7641cbb93539537483e6fb15243b37187498573482f3b787&token=1817505529&lang=zh_CN&scene=21#wechat_redirect).

Shawane-Wang avatar Apr 06 '23 04:04 Shawane-Wang

Thanks. I updated the package in github and add a function random_network. Please reinstall it from github and have a try. Here is my test.

library(microeco)
data(dataset)
t1 <- trans_network$new(dataset = dataset, cor_method = "bray", filter_thres = 0.003)
t1$cal_network(COR_p_thres = 0, COR_cut = 0.3)
test <- t1$random_network(runs = 100)
test

ChiLiubio avatar Apr 06 '23 13:04 ChiLiubio

Thanks! Could we further get results like clustering coefficient, average path length rand and other network parameters according to every run of the random network, which may help us to generate the histograms of these parameters comparing with those from our empirical network? Maybe pictures as following? image

Shawane-Wang avatar Apr 06 '23 15:04 Shawane-Wang

Yes. I forgot to tell you the parameter output_sim can control whether output each result of simulation. When output_sim = TRUE, the columns from five to the last are the simulations.

library(microeco)
data(dataset)
t1 <- trans_network$new(dataset = dataset, cor_method = "bray", filter_thres = 0.003)
t1$cal_network(COR_p_thres = 0, COR_cut = 0.3)
test <- t1$random_network(runs = 100, output_sim = TRUE)
test

Then you can extract this part of results for the customized visualization.

ChiLiubio avatar Apr 07 '23 01:04 ChiLiubio

In my own dataset, I called t1 as tmp, but it returns as follows. Is it possible to be more flexible when defining our object?

image

I guess the error may comes from here. image

Shawane-Wang avatar Apr 07 '23 03:04 Shawane-Wang

Sorry. It is a bug. I have fixed it. Please reinstall the package from github and try again. Thanks.

ChiLiubio avatar Apr 07 '23 04:04 ChiLiubio

It works! Thank you for your kind help!

Shawane-Wang avatar Apr 07 '23 08:04 Shawane-Wang