random_interaction_matrix_bio: Generate a random parameter matrix

Usage Arguments Examples

Usage

1
random_interaction_matrix_bio(species, number_of_interactions, times = 1:100, plot = FALSE)

Arguments

species
number_of_interactions
times
plot

Examples

 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
##---- 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 (species, number_of_interactions, times = 1:100, 
    plot = FALSE) 
{
    "Generate random parameters for simulation studies on multispecies gLV"
    "For lotka volterra function without substrate, so diagonal entries less negative??"
    n = number_of_interactions
    if (n > (species^2 - species)) {
        print(paste0("Error. For ", species, " species, the number of interactions can<b4>t be greater than ", 
            species^2 - species))
        return()
    }
    interaction <- diag(sample(x = runif(n = species, min = -2, 
        max = -1)), nrow = species)
    if (abs(n) > 0) {
        coordinates <- which(interaction == 0, arr.ind = T)
        rows = sample(x = nrow(coordinates), size = n, replace = FALSE)
        for (i in 1:length(rows)) {
            interaction[coordinates[rows[i], 1], coordinates[rows[i], 
                2]] <- rnorm(1, 0, 4)
        }
    }
    colnames(interaction) = NULL
    return((interaction))
  }

lkshrsch/gLVInterNetworks documentation built on May 21, 2019, 7:33 a.m.