looping and plotting a Lefkovitch/Leslie projection
Jeffrey, Check out also the popbio package. Cheers, Peter -- P?ter S?lymos, Dept Biol Sci, Univ Alberta, T6G 2E9, Canada AB solymos at ualberta.ca, Ph 780.492.8534, http://psolymos.github.com Alberta Biodiversity Monitoring Institute, http://www.abmi.ca Boreal Avian Modelling Project, http://www.borealbirds.ca On Thu, Nov 29, 2012 at 12:01 PM, Jeffrey Stratford
<jeffrey.stratford at wilkes.edu> wrote:
These are great examples. Thanks so much guys! On Thu, Nov 29, 2012 at 1:41 PM, Marc Taylor <marchtaylor at gmail.com> wrote:
Hello Jeffrey.
I have done something similar for a course on "Modelling in Conservation
Biology". Here is a simple example of an age-based Leslie model with three
classes:
L=matrix(c(0.5, 0.6666, 0, 1.0, 0, 0.3333, 0.75, 0, 0), nrow=3, ncol=3)
time=10
No=c(2,0,0)
POP=c(No)
Nt=No
for (i in 1:time){
Nt = drop(L %*% Nt)
POP=rbind(POP,Nt)
}
plot(0:time,POP[,1], type="l", ylim=range(POP), ylab="numbers",
xlab="time")
for (i in 2:length(POP[1,])){
lines(0:time,POP[,i],col=i)
}
legend(0.5*time,max(POP),
c(paste("class",(1:length(No)))),
lwd=1,
col=c(1:length(No)))
###Eigenvalues (info on pop trajectory and distribution)
sum(POP[(time),])/sum(POP[(time-1),]) # the rate of population change
between the last two iterations
x=eigen(L)
x
#dominant eigen value
abs(x$values)
#The stable population distribution is specified by the 1st vector. The
proportion of each element of the vector sum equals the corresponding class
proportions.
abs(x$vectors[,1]/sum(x$vectors[,1]))
Another nice example from a real study is that of Crouse et al. (1987).
the paper comes with all the information needed to reproduce a 7 stage
Usher matrix model (i.e. individuals have the possibility to stay in the
same class and not advance).
Crouse, Deborah T., Larry B. Crowder, and Hal Caswell. "A stage-based
population model for loggerhead sea turtles and implications for
conservation." *Ecology* 68.5 (1987): 1412-1423.
Cheers,
Marc
On Thu, Nov 29, 2012 at 5:36 PM, Alan Haynes <aghaynes at gmail.com> wrote:
Is this what you want?
Your code
#the data
A <- c(0,0,100, 0.4,0,0, 0,0.7,0)
#create a matrix from the data
L <- matrix(A, nrow=3, byrow=T)
#check out the matrix
L
#the starting population
n_0 <- c(1000, 400, 100)
#the next generation
#n_1 <- L %*% n_0
#check it out
#n_1
#run another generation
#n_2 <- L %*% n_1
#check it out
#n_2
my code:
pops <- list()
pops[[1]] <- n_0
for(i in 2: 20){ # gives 19 generations
pops[[i]] <- L %*% pops[[i-1]] # assign your matrix mult to a list slot
}
pops[[20]] # the 19th generation (because the first slot is the 0
generation)
HTH
Alan
--------------------------------------------------
Email: aghaynes at gmail.com
Mobile: +41794385586
Skype: aghaynes
On 29 November 2012 17:07, Jeffrey Stratford
<jeffrey.stratford at wilkes.edu>wrote:
Hi everyone, I have a two part population lab in my Ecology course. The first part
was
showing exponential and logistic growth. For the second section, I would like to introduce them to Leslie/Lefkovitch models. I'm able to multiply the matrix and the age classes step by step but I would like to have
them
run projections for as many generations as they choose and show the population structure by plotting the number in each age class over time. I know software programs like Populus do this but I would like to have
them
(and myself) learn the programming. Here's what I have so far: #the data A <- c(0,0,100, 0.4,0,0, 0,0.7,0) #create a matrix from the data L <- matrix(A, nrow=3, byrow=T) #check out the matrix L #the starting population n_0 <- c(1000, 400, 100) #the next generation n_1 <- L %*% n_0 #check it out n_1 #run another generation n_2 <- L %*% n_1 #check it out n_2 Many thanks, Jeff -- ******************************************************** Jeffrey A. Stratford, PhD Department of Biology and Health Sciences Wilkes University, PA 18766 USA 570-332-2942 http://web.wilkes.edu/jeffrey.stratford/ ******************************************************** [[alternative HTML version deleted]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
[[alternative HTML version deleted]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
-- ******************************************************** Jeffrey A. Stratford, PhD Department of Biology and Health Sciences Wilkes University, PA 18766 USA 570-332-2942 http://web.wilkes.edu/jeffrey.stratford/ ******************************************************** [[alternative HTML version deleted]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology