I need a vector (or list) of several results of a function on several simulated graphs (eg assortativity). This is to emulate a Monte Carlo procedure, to perform a segregation analysis with stochastic block models instead of Erdos-Renyi models. This allows to differentiate the probability of links between two types of actors due to the design of the data collection, with a method similar to conditional uniform graphs. I have tried unsuccessfully with the following loop:
library(igraph)
k <- cbind(c(.2,.2),c(.2,0)) # one block without data of its links
attrib <- c(1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,5,5,5,5,5,5,5,5,5,1,1,2,2,2,2,2,2,2,3,3,4,4,4,4,4,4,5,5,5,5,5,5,5,5) # observed data attributes for each block
for(i in 1:1000) {
sbm[i] <- sample_sbm(49, pref.matrix=k,block.sizes=c(24,25))
sbm[i] <- set_vertex_attr(sbm[i], "att",value=attrib)
sbm_ass[i] <- assortativity_nominal(sbm[i],V(sbm[i])$att,directed=F)
}
I've also tried with [i] only on the last line: "sbm_ass[i]...". I suppose that a function is needed, but I have not been able to realize it.
I think replicate is the thing you may need
sbm_ass <- replicate(
1000,
sample_sbm(49, pref.matrix = k, block.sizes = c(24, 25)) %>%
set_vertex_attr(name = "att", value = attrib) %>%
assortativity_nominal(V(.)$att, directed = F)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With