Skip to content

Instantly share code, notes, and snippets.

@aurielfournier
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save aurielfournier/a8114c48d757cd75df10 to your computer and use it in GitHub Desktop.

Select an option

Save aurielfournier/a8114c48d757cd75df10 to your computer and use it in GitHub Desktop.
Population Biology Week 3
#####################################################
#lambda varies over time
#####################################################
low <- as.data.frame(matrix(ncol=100, nrow=100))
high <- as.data.frame(matrix(ncol=100, nrow=100))
t <- seq(2,101, by=1)
N0 <- 50
high[1,] <- N0
low[1,] <- N0
lamda<-matrix(data=rnorm(n=10000, mean=1.05,sd=.3),nrow=100,ncol=100)
for(i in 1:99){
high[(i+1),]<-high[i,]*lamda[i,]
}
lamda<-matrix(data=rnorm(n=10000, mean=1.05,sd=.3),nrow=100,ncol=100)
for(i in 1:99){
low[(i+1),]<-low[i,]*lamda[i,]
}
low$mean <- rowMeans(low)
high$mean <- rowMeans(high)
#generate the arith mean
lambda <- rep(1.05,100)
t <- seq(1,100,by=1)
arith <- N0*(lambda^t)
par(mfcol=c(3,1))
#plot low
plot(low[,1] , type="l")
for(i in 2:10){
lines(low[,i], type="l")
}
#plot high
plot(high[,1],type="l")
for(i in 2:10){
lines(high[,i], type="l")
}
# plot means
plot(arith, col="red", type="l", lwd=3)
lines(high$mean, col="orange",lwd=3)
lines(low$mean, col="green", lwd=3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment