我使用erdos-renyi算法在R中创建了一组随机网络。但是,我找不到计算图的R平方(Pearson相关系数)值的函数。例如,如果我使用igraph包中的功能erdos renyi游戏来制作我的网络
erdos.renyi.game(281, 447, type = "gnm",m = 465, directed = FALSE)
我怎样才能计算出这个R平方值?
答案 0 :(得分:0)
library(igraph)
library(intergraph)
library(sna)
# create the graphs
gs <- replicate(2,
sample_gnm(281, 447,m = 465, directed = FALSE),
simplify = F)
# sample_gnm is preferred to erdos.renyi.game now
# turn them into network objects
nets <- lapply(gs, asNetwork)
现在使用gcor
获取相关性,并使用qaptest
来测试重要性。
gcor(nets, g1 = 1, g2 =2)
[1] 0.003537025
qaptest(nets, gcor, g1 = 1, g2 = 2)
QAP Test Results
Estimated p-values:
p(f(perm) >= f(d)): 0.17
p(f(perm) <= f(d)): 0.834