1 | simula.neutra.hub(S = 100, j = 10, ciclo = 10000, step = 100)
|
S |
|
j |
|
ciclo |
|
step |
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 | ##---- 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 (S = 100, j = 10, ciclo = 10000, step = 100)
{
J <- S * j
ind.mat = matrix(nrow = J, ncol = 1 + ciclo/step)
n.dead <- c()
n.dead[1] <- 0
ind.mat[, 1] <- rep(1:S, each = j)
cod.sp <- ind.mat[, 1]
p.death <- 1/J
for (i in 2:(1 + ciclo/step)) {
n.mortes <- 0
for (a in 1:step) {
morte = rbinom(J, 1, prob = p.death)
D = sum(morte)
n.mortes <- n.mortes + D
if (D > 0) {
nascer = which(morte == 1)
novos <- sample(1:J, D, replace = T)
cod.sp[nascer] <- cod.sp[novos]
}
}
ind.mat[, i] <- cod.sp
n.dead[i] <- n.mortes
}
tempo <- seq(0, ciclo, by = step)
colnames(ind.mat) <- tempo
names(n.dead) <- tempo
resulta = list(tempo = tempo, sp.list = ind.mat, n.mortes = n.dead)
return(resulta)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.