Is there an R function for generating an undirected graph with probability on edges? I've tried to generate a nonparanormal data set by constructing the adjacency matrix (precision matrix) [see appendix]. First of all, I should generate a random graph, which the of pairwise edges (i,j) follows the normal probability density function. the igraph
package includes the sample_fitness
and sample_degseq
functions, which apply probabilities on the degree of each vertex, but not on the existence of edges between i and j vertices.
Thank you all.
.
library(MASS)
library(Matrix)
library(philentropy)
library(qgraph)
library(igraph)
library(huge)
d=10
tmp=matrix(runif(2*d,0,0.5),d,2)
tmp=2*tmp
L=distance(tmp,method="euclidean")
s=0.125
prob=(1/sqrt(2*pi))*exp(-(L^2)/2*s)
prob=mat2vec(prob)
degs<-sample(0:(length(prob)-1),d,replace=TRUE,prob=prob)
for(i in 1:d){
if (degs[i]>4){degs[i]=4}
}
degs
if(sum(degs)%%2!=0){degs[1]<-degs[1]+1}
degs
g4 <-sample_degseq(degs,method="vl")
all(degree(g4)==degs)
plot(g4)
theta=as_adjacency_matrix(g4,type="both")
for(j in 1:d){
for(i in 1:d){
if(theta[i,j]==0)
omega[i,j]=0
else
omega[i,j]=0.245
}
}
diag(omega)=1