如何在R中生成一系列随机网络 [英] How to generate a series of random networks in R

查看:78
本文介绍了如何在R中生成一系列随机网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 R 初学者,所以请耐心等待.

I am an R beginner, so please bear with me.

我正在尝试创建一组大约 100 个随机网络,以与我的 60 个节点和 246 个加权链接的原始网络进行比较.

I am attempting to create a set of around 100 random networks, to compare with my original network of 60 nodes and 246 weighted links.

我希望每个网络具有 0-100 之间的随机节点数,每个节点具有随机密度(即任何一个节点与另一个节点连接的随机概率),以及 1-5 之间的随机加权边.

I would like each network to have a random number of nodes between 0-100, each with a random density (i.e. random probability that any one node will connect with another), and randomly weighted edges between 1-5.

我对 R 中的网络分析非常陌生,所以我不确定如何创建允许我输出 100 个这样的脚本(用循环猜测),也不知道如何指定随机边缘密度和权重.

I'm very new to network analysis in R, so I am not sure how to create a script that allows me to output 100 of these (guessing with a loop), nor how to specify random edge densities and weights.

任何建议都会很棒.

推荐答案

igraph 是一个好的开始:

library(igraph)
set.seed(1)
gs <- list()
for (x in seq_len(100L)) {
  gs[[x]] <- erdos.renyi.game(sample(1:100, 1), p.or.m = runif(1))
  E(gs[[x]])$weight <- sample(1:5, ecount(gs[[x]]), T)
}
plot(gs[[1]], edge.width = E(gs[[1]])$weight) # plot first graph

有关随机图生成的文档,请参阅?erdos.renyi.game.

See ?erdos.renyi.game for the documentation on the random graph generation.

这篇关于如何在R中生成一系列随机网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆