Apologies in advance if this question has already been asked, but I can't seem to find anything online to help!
I'm trying to add stochasticity to a function I've generated, that contains a logistic growth model.
This is my function:
ricker <- function(K, R, B0, t, E, Q)
{
# create empty matrix with only biomass of first year; this is where all other values will be added
B <- matrix(nrow = t, ncol = length(Q))
B[1,1:length(Q)] <- B0
for (i in 1:t) {
for (j in 1:length(Q)) {
B[i + 1,j] <-
{
B[i,j] + R * B[i,j] * (1 - B[i,j]/K) - Q[j] * E * B[i,j]
}
}
}
return(B)
}
The matrix created above has 34 rows and 34 columns. The following is the code I'm using to attempt to add stochasticity to my data.
# create variables/parameters
k <- 420000
b0 <- as.matrix(3363)
T <- 34 # number of years in data
e <- fp
r=1.2
pb <- txtProgressBar(style=3)
for (loop in 1:10) {
B <- ricker(K=k, R=r, B0=b0, t=T, E=0.5, Q=fp)
B[loop] <- B[loop] - rnorm(1,0,0.25)
if (B[loop] <0) {
B [loop] <- 0
}
setTxtProgressBar(pb,value=l/T)
}
#'
matplot(B,type="l", col=1)
I want to end up with graph like this:
However, the output isn't any different to the initial output and I can't figure out what I'm missing. Any help on the matter would be greatly appreciated!!
Thanks!!