0

如果已经问过这个问题,请提前道歉,但我似乎无法在网上找到任何帮助!

我正在尝试将随机性添加到我生成的包含逻辑增长模型的函数中。

这是我的功能:

    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)
}

上面创建的矩阵有 34 行和 34 列。以下是我用来尝试向我的数据添加随机性的代码。

# 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)

函数输出图

我想得到这样的图表:

在此处输入图像描述

但是,输出与初始输出没有任何不同,我无法弄清楚我缺少什么。任何有关此事的帮助将不胜感激!

谢谢!!

4

0 回答 0