gen.network.FE {nem}R Documentation

Generate the network with a given blockmodel and with a given level of errors

Usage

gen.network.FE(type = type, randomShare = 0.4, symmetric = FALSE, n = 42, size = rep(1/nrow(type), nrow(type)))

Arguments

type

a matrix containg types of blocks "null" or "com"

randomShare

a level of errors (a single value between 0 (ideal network) and 1 (random network))

symmetric

should the network be symmetric TRUE or asymmetric FALSE

n

number of unnits in a network

size

specify the size of each cluster; specify the vector of sizes (the elements of the vector have sum to 1)

Value

The function returns a binary network of class matrix.

Examples

##---- 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 (type = type, randomShare = 0.4, symmetric = F, n = 42,
    size = c(1/3, 1/3, 1/3))
{
    initialNetwork <- gen.network(type = type, errors = 0, symmetric = symmetric,
        n = n, size = size)
    newNetwork <- initialNetwork
    kriterij <- (1 - (sum(initialNetwork == 1)/length(initialNetwork))) *
        randomShare
    if (randomShare != 0) {
        while (mean(newNetwork[which(initialNetwork == 1)] ==
            0) <= kriterij) {
            newNetwork[sample(which(newNetwork == 0), size = 1)] <- 1
            newNetwork[sample(which(newNetwork == 1), size = 1)] <- 0
        }
        nloops <- sum(diag(newNetwork) == 1)
        diag(newNetwork) <- 1
        changeToOne <- sample(which(newNetwork == 0), size = nloops,
            replace = F)
        newNetwork[changeToOne] <- 1
        diag(newNetwork) <- 0
        return(newNetwork)
    }
    if (randomShare == 0)
        return(initialNetwork)
  }

[Package nem version 0.12.33 Index]