1
votes

Is there an R function for generate 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 introduce '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

Liu, Lafferty and Wasserman (2009).

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
1

1 Answers

0
votes

You can use runif along with prob to generate your random network, e.g.,

adjmat <- prob
adjmat[] <- runif(length(prob))
g <- graph_from_adjacency_matrix(
  +(as.matrix(adjmat) <= as.matrix(prob)) - diag(d),
  mode = "undirected"
)

and the network with probabilistic edges are shown as, for example

enter image description here