library(shiny) library(shinyapps) library(png) library(rmarkdown) #devtools::install_github("EcoEvoEducation/EcoEvoApps")
In most populations, individuals differ from one another in size or age. Usually these differences affect rates of survival, growth, and reproduction. For example in many plant species, small plants have a lower probability of survival than large plants. When small individuals are more abundant than large individuals, a simple average of survival probability is overly simplistic. In situations like these, we need to account for differences in transition rates due to age or stage.
In a system in which individuals are either adults, $A$, or juveniles, $J$. For simplictiy, we assume that individuals may only persist as adults or juveniles for one timestep.
In each timestep, the number of juveniles, $J$, is a function of the number of adults in the prior timestep, $A$, and their reproductive rate, $f$.
$J_{t+1}=A_t*f$
Similarly, the number of adults in each timestep, $A$, is a function of the number of juveniles in the last timestep, $J$, that became adults at the per capita growth rate, $g$.
$A_{t+1}=J_t*g$
If you remember from your algebra classes, this problem can be represented by a system of equations, because information from one equation can be used to solve the other, and vice-versa. Alternatively, we can use matrix models to summarize the dynamics of this population.
To use a matrix model, we combine the information into rows and columns that represent transitions.
$\left( \begin{array}{c} J \ A \end{array} \right) = \left( \begin{array}{cc} 0 & f \ g & 0 \end{array} \right)$
In this transition matrix, each transition is accounted for: the upper left quadrant of the matrix represents reproduction (Adults to Juveniles), the lower right represents growth (Juveniles to Adults), and the other two are set to zero, because adults may not stay adults, and juveniles may not stay juveniles.
Demographic matricies are always read from the top and to the left in this way (see figure 2), but can be expanded to include more than two stages. They are also always square, and the elements are always positive. There are two common forms of demographic matricies; leslie matricies for populations that are age-structured (individuals must progress due to age), and leftkovitch matricies where individuals may both progress and retrogress between stages. A markov matrix is different, because death rates are explictly accounted for, and we will not address those kinds of matricies here.
Once a demographic matrix is constructed we can simulate the dynamics of the population in discrete time, or we can use the matrix to calculate asymptotic (the long-term) behavior. In a deterministic framework, both approaches should ultimately result in the same answer.
Let's simulate the dynamics in discrete time with two seperate equations (solid lines) and with a matrix (dashed lines):
inputPanel( sliderInput("J01", label = "Initial number of juveniles:", min = 0, max = 150, value = 50, step = 10), sliderInput("A01", label = "Initial number of Adults:", min = 0, max = 150, value = 50, step = 10), sliderInput("f", label = "Birth rate, f:", min = 0, max = 3, value = 1.0, step = 0.2), sliderInput("g", label = "Growth rate, g:", min = 0, max = 1, value = .5, step = .1) ) renderPlot({ nSteps<-50 time<-seq(from=1, to=nSteps, by=1) J<-c(input$J01, rep(NA, times=nSteps-1)) A<-c(input$A01, rep(NA, times=nSteps-1)) for (i in 2:nSteps){ J[i]<-A[i-1]*input$f A[i]<-J[i-1]*input$g} par(mfrow=c(2,1)) plot(J~time, xlab="time (t)", ylab="Number of individuals", type="l", lwd=2) lines(A~time, col="orange", type="l", lwd=2) popvec<-matrix(c(input$J01,input$A01), nrow=2, ncol=1) #initial population vector tmat<-matrix(c(0,input$f,input$g,0), nrow=2, ncol=2, byrow=T) # for (i in 2:nSteps){ vec<-matrix(popvec[,i-1], ncol=1, nrow=2, byrow=T) popvec<-cbind(popvec,tmat%*%vec) } plot(popvec[1,]~time, type="l", lwd=2, lty=2, xlab="time (t)", ylab="Number of individuals") lines(popvec[2,]~time, col="orange", type="l", lwd=2, lty=2) })
You can program these dynamics yourself:
# Model with two seperate equations J01<- 5 #initial number of juveniles A01<- 15 #initial number of adults g<- .5 # growth rate from juveniles to adults f<- 1.1 #per capita fecuntiy from adults to juveniles nSteps<-50 #number of timesteps time<-seq(from=1, to=nSteps, by=1) J<-c(J01, rep(NA, times=nSteps-1)) A<-c(A01, rep(NA, times=nSteps-1)) for (i in 2:nSteps){ J[i]<-A[i-1]*f A[i]<-J[i-1]*g} plot(J~time, xlab="time (t)", ylab="Number of individuals", type="l", lwd=2) lines(A~time, col="orange", type="l", lwd=2) #model with a transition matrix popvec<-matrix(c(J01,A01), nrow=2, ncol=1) #initial population vector tmat<-matrix(c(0,f,g,0), nrow=2, ncol=2, byrow=T) #transition matrix for (i in 2:nSteps){ vec<-matrix(popvec[,i-1], ncol=1, nrow=2, byrow=T) popvec<-cbind(popvec,tmat%*%vec) } plot(popvec[1,]~time, xlab="time (t)", ylab="Number of individuals", type="l", lwd=2) lines(popvec[2,]~time, col="orange", type="l", lwd=2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.