Provided a P matrix, which defines survival transitions across stages, this function outputs a vector defining life expectancy in units of the time step used (see convertIncrement()), for each of the size bins.
Usage
meanLifeExpect(IPMmatrix)
Arguments
IPMmatrix
an IPMmatrix object defining survival transitions.
Details
Note that more complex approaches for discretely varying environments (e.g., as in Tuljapurkar & Horvitz 2006.) have yet to be implemented.
Value
A vector of life expectancies each corresponding to a value of the size bins defined by Pmatrix@meshpoints.
Author(s)
C. Jessica E. Metcalf, Sean M. McMahon, Roberto Salguero-Gomez, Eelke Jongejans & Cory Merow.
References
Caswell, 2001. Matrix population models: analysis, construction and
interpretation. 2nd ed. Sinauer. p118-120.
Cochran & Ellner. 1992. Simple methods for calculating age-based life history parameters for stage-structured populations. Ecological Monographs 62, p345-364.
Tuljapurkar & Horvitz. 2006. From stage to age in variable
environments. Life expectancy and survivorship. Ecology 87, p1497-1509.
See Also
makeIPMPmatrix
Examples
# With a single continuous state variable (e.g. size):
dff <- generateData()
Pmatrix <- makeIPMPmatrix(minSize = min(dff$size, na.rm = TRUE),
maxSize = max(dff$size, na.rm = TRUE), growObj=makeGrowthObj(dff),
survObj = makeSurvObj(dff))
meanLifeExpect(Pmatrix)
Pmatrix <- makeIPMPmatrix(minSize = min(dff$size, na.rm = TRUE),
maxSize = max(dff$size, na.rm = TRUE), growObj = makeGrowthObj(dff),
survObj = makeSurvObj(dff))
plot(meanLifeExpect(Pmatrix), ylab = "Mean life expectancy",
xlab = "Continuous (e.g. size) stage", type = "l", col="dark gray",
ylim = c(0,max(meanLifeExpect(Pmatrix))))
# With continuous (e.g. size) and discrete (e.g. seedbank) stages:
dff <- generateData(type="discrete")
dff$covariate <- sample(1:3, size = nrow(dff), replace = TRUE)
dff$covariateNext <- sample(1:3, size = nrow(dff), replace = TRUE)
discM <- makeDiscreteTrans(dff)
Pmatrix <- makeCompoundPmatrix(minSize = min(dff$size, na.rm = TRUE),
maxSize = max(dff$size, na.rm = TRUE), envMatrix = makeEnvObj(dff),
growObj = makeGrowthObj(dff, Formula = sizeNext~size+size2+covariate),
survObj = makeSurvObj(dff, Formula = surv~size+size2+covariate),
discreteTrans = discM)
mLE <- meanLifeExpect(Pmatrix)
# showing three environments on different panels,
# life expectancy of discrete stages
# shown at level of the first size class
par(mfrow=c(max(Pmatrix@env.index),1))
xvals <- c(rep(Pmatrix@meshpoints[1],ncol(discM@discreteTrans)-1),
Pmatrix@meshpoints)
for (k in 1:max(Pmatrix@env.index)) {
indx <- ((k-1)*(ncol(discM@discreteTrans)-1+length(Pmatrix@meshpoints))+1):
(k*(ncol(discM@discreteTrans)-1+length(Pmatrix@meshpoints)))
plot(xvals,mLE[indx],
ylab = "Mean life expectancy",
xlab = "Continuous (e.g. size) and discrete (e.g. seedbank) stages",
type = "l", col = "dark gray", ylim = c(0,max(mLE)),
main=paste("habitat ",k,sep=""))
}
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(IPMpack)
Loading required package: Matrix
Loading required package: MASS
Loading required package: nlme
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/IPMpack/meanLifeExpect.Rd_%03d_medium.png", width=480, height=480)
> ### Name: meanLifeExpect
> ### Title: Calculates the mean life expectancy.
> ### Aliases: meanLifeExpect
> ### Keywords: ~kwd1
>
> ### ** Examples
>
> # With a single continuous state variable (e.g. size):
> dff <- generateData()
> Pmatrix <- makeIPMPmatrix(minSize = min(dff$size, na.rm = TRUE),
+ maxSize = max(dff$size, na.rm = TRUE), growObj=makeGrowthObj(dff),
+ survObj = makeSurvObj(dff))
> meanLifeExpect(Pmatrix)
[1] 1.203116 1.235418 1.267384 1.298367 1.327964 1.356029 1.382649 1.408084
[9] 1.432699 1.456901 1.481086 1.505610 1.530772 1.556815 1.583930 1.612271
[17] 1.641961 1.673104 1.705789 1.740096 1.776099 1.813862 1.853448 1.894913
[25] 1.938305 1.983670 2.031044 2.080457 2.131933 2.185487 2.241126 2.298846
[33] 2.358637 2.420478 2.484338 2.550177 2.617944 2.687576 2.758994 2.832103
[41] 2.906774 2.982825 3.059988 3.137844 3.215727 3.292596 3.366850 3.436144
[49] 3.497193 3.545671
>
> Pmatrix <- makeIPMPmatrix(minSize = min(dff$size, na.rm = TRUE),
+ maxSize = max(dff$size, na.rm = TRUE), growObj = makeGrowthObj(dff),
+ survObj = makeSurvObj(dff))
>
> plot(meanLifeExpect(Pmatrix), ylab = "Mean life expectancy",
+ xlab = "Continuous (e.g. size) stage", type = "l", col="dark gray",
+ ylim = c(0,max(meanLifeExpect(Pmatrix))))
>
> # With continuous (e.g. size) and discrete (e.g. seedbank) stages:
> dff <- generateData(type="discrete")
> dff$covariate <- sample(1:3, size = nrow(dff), replace = TRUE)
> dff$covariateNext <- sample(1:3, size = nrow(dff), replace = TRUE)
> discM <- makeDiscreteTrans(dff)
> Pmatrix <- makeCompoundPmatrix(minSize = min(dff$size, na.rm = TRUE),
+ maxSize = max(dff$size, na.rm = TRUE), envMatrix = makeEnvObj(dff),
+ growObj = makeGrowthObj(dff, Formula = sizeNext~size+size2+covariate),
+ survObj = makeSurvObj(dff, Formula = surv~size+size2+covariate),
+ discreteTrans = discM)
[1] "Dim of envMatrix not equal to nEnvClass. Adjusted to 3"
> mLE <- meanLifeExpect(Pmatrix)
>
> # showing three environments on different panels,
> # life expectancy of discrete stages
> # shown at level of the first size class
> par(mfrow=c(max(Pmatrix@env.index),1))
>
> xvals <- c(rep(Pmatrix@meshpoints[1],ncol(discM@discreteTrans)-1),
+ Pmatrix@meshpoints)
>
> for (k in 1:max(Pmatrix@env.index)) {
+ indx <- ((k-1)*(ncol(discM@discreteTrans)-1+length(Pmatrix@meshpoints))+1):
+ (k*(ncol(discM@discreteTrans)-1+length(Pmatrix@meshpoints)))
+
+ plot(xvals,mLE[indx],
+ ylab = "Mean life expectancy",
+ xlab = "Continuous (e.g. size) and discrete (e.g. seedbank) stages",
+ type = "l", col = "dark gray", ylim = c(0,max(mLE)),
+ main=paste("habitat ",k,sep=""))
+ }
>
>
>
>
>
> dev.off()
null device
1
>