[R-sig-eco] looping and plotting a Lefkovitch/Leslie projection
marcelino.delacruz at upm.es
marcelino.delacruz at upm.es
Thu Nov 29 20:35:23 CET 2012
Maybe you would be interested in the package Rramas
It implements some of the tools in the Ramas Ecolab (c) software
Cheers,
Marcelino
http://cran.r-project.org/web/packages/Rramas/Rramas.pdf
Con fecha 29/11/2012, "Jeffrey Stratford"
<jeffrey.stratford at wilkes.edu> escribió:
>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
More information about the R-sig-ecology
mailing list