Skip to content

Instantly share code, notes, and snippets.

@aaronberdanier
Created December 10, 2012 17:55
Show Gist options
  • Save aaronberdanier/4252132 to your computer and use it in GitHub Desktop.
Save aaronberdanier/4252132 to your computer and use it in GitHub Desktop.
Simulation
time <- 100
N <- Nhat <- dN <- K <- rep(NA,time)
P <- rlnorm(100,7,0.7)
r <- 0.05
Kmax <- 500
alpha <- mean(P)
N[1] <- 100
Nhat[1] <- rpois(1,N[1])
K[1] <- NA
for(t in 2:100){
K[t] <- Kmax*P[t]/(alpha+P[t])
dN[t] <- N[t-1]*r*(1-(N[t-1]/K[t]))
N[t] <- N[t-1]+dN[t]
Nhat[t] <- rpois(1,N[t])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment