Description Usage Arguments Value Examples
The function generate random network considering the selected types of triads.
1 | simulate.RL(ideal.net, random.net, terms = "forb", k = 100, custom.terms = NULL, cr.type = "sum")
|
ideal.net |
ideal network structure of class |
random.net |
random or initial network of class |
terms |
which types of triads has to be considered (allowed |
k |
the number of iterations |
custom.terms |
additional terms to be considered (if |
cr.type |
how to calculate CR value (allways use |
new.network |
generated network |
change.ratio.vec |
vector of CR values, each value is calculated after each iteration |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (ideal.net, random.net, terms = "forb", k = 100, custom.terms = NULL,
cr.type = "sum")
{
teoreticna.porazdelitev <- summary(ideal.net ~ triadcensus)
if (terms == "forb")
allowed.terms <- names(teoreticna.porazdelitev)[teoreticna.porazdelitev ==
0]
if (terms == "allow")
allowed.terms <- names(teoreticna.porazdelitev)[teoreticna.porazdelitev !=
0]
if (terms == "all")
allowed.terms <- names(teoreticna.porazdelitev)
if (terms == "cust")
allowed.terms <- names(teoreticna.porazdelitev)[custom.terms]
change.ratio.vec <- NULL
new.network <- random.net
for (i in 1:k) {
pov <- sample(which(random.net == 0)[is.element(which(random.net ==
0), which(diag(1, nrow = n) == 1)) == F], size = 1)
npov <- sample(which(random.net == 1), size = 1)
new.network[pov] <- 1
new.network[npov] <- 0
s.rand <- summary(random.net ~ triadcensus)
s.new <- summary(new.network ~ triadcensus)
if (cr.type == "mean") {
nova.teoreticna <- mean((s.new[allowed.terms] - teoreticna.porazdelitev[allowed.terms]))
stara.teoreticna <- mean((s.rand[allowed.terms] -
teoreticna.porazdelitev[allowed.terms]))
}
if (cr.type == "sum") {
nova.teoreticna <- sum((s.new[allowed.terms] - teoreticna.porazdelitev[allowed.terms])^2)
stara.teoreticna <- sum((s.rand[allowed.terms] -
teoreticna.porazdelitev[allowed.terms])^2)
}
change.ratio.vec[i] <- change.ratio <- nova.teoreticna/stara.teoreticna
if (is.nan(change.ratio) == FALSE) {
if (change.ratio < 1)
random.net <- new.network
else new.network <- random.net
}
else new.network <- random.net
}
return(list(new.network, change.ratio.vec))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.