inSilico_bio: Generate in silico data

Usage Arguments Examples

Usage

1
inSilico_bio(species, number_of_interactions, events, mode = 1, times = 1:100)

Arguments

species
number_of_interactions
events
mode
times

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
##---- 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, events, 
    mode = 1, times = 1:100) 
{
    "requires: random_interaction_matrix_bio, solveLV"
    "mode:0 = linear ODE, 1 = normal, 2 = mixed feeding, 3 = events"
    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()
    }
    res <- matrix(0, nrow = 2)
    while (class(res)[1] != "deSolve") {
        interactions <- random_interaction_matrix_bio(species, 
            number_of_interactions)
        growth <- rep(0, nrow(interactions))
        var_means <- runif(n = species, 0.1, 0.8)
        for (i in 1:nrow(interactions)) {
            growth[i] <- -1 * (interactions[i, ] %*% var_means)
        }
        Parms <- cbind(growth, interactions)
        options(warn = 2)
        x0 <- var_means + rnorm(n = species, mean = var_means, 
            sd = 0.01)
        if (mode == 3) {
            print("Events")
            names(x0) <- as.character(1:length(x0))
            res <- tryCatch(solveLV_event(events = events, times = times, 
                Parms, States = x0, c = 2 * c, lambda = lambda, 
                cycle = cycle), error = function(e) return("error"))
            s <- S(t = times, c = 2 * c, lambda = lambda, cycle)
        }
        if (mode == 1) {
            res <- tryCatch(solveLV_bio(times = times, Parms, 
                States = x0), warning = function(w) return("error"), 
                error = function(e) return("error"))
        }
        if (mode == 0) {
            print("linear ODE")
            res <- tryCatch(solveLV_bio_linear(Parms, States = x0, 
                times = times))
        }
    }
    options(warn = 1)
    return(list(res, Parms))
  }

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