Last data update: 2014.03.03

R: Projects how long it takes to get from a starting...
timeToSizeR Documentation

Projects how long it takes to get from a starting distribution to a target continuous stage value.

Description

Provided with a starting vector reflecting starting individual sizes, this function projects forward via the provided IPM until a defined proportion of the population has reach the chosen endSize. Only works for single environment or compound matrices (not time-varying covariates apart from a single discrete one).

Usage

timeToSize(startingSizes, IPM, endSize, startingEnv = 1, maxT = 100, propReach = 0.01)

Arguments

startingSizes

vector of starting sizes reflecting sizes of individuals in the starting population (in any order).

IPM

the IPM Pmatrix.

endSize

the end size.

startingEnv

vector of starting env, same length as startingSizes, or length = 1 if compound matrices are not being used.

maxT

the max number of time steps tested.

propReach

the proportion of the starting pop that have to be > than the endSize for it to count.

Details

Plots and returned values of survivorship from preliminary runs will give a notion of how low this has to be.

Value

ts.dist

the time-series of size distribution

time.reach

the time for n.reach to be at sizes > endSize

survivorship

survivorship over the course of the time elapsed for that pop

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.

Examples

#note that with the "fake data" essentially either takes 
#forever or is immediate...
dff <- generateData()
startSizes <- rnorm(1000, 2.5, 1)
Pmatrix <- makeIPMPmatrix(minSize = 1.2*min(dff$size, na.rm=TRUE),
maxSize = 1.2*max(dff$size, na.rm=TRUE), 
growObj = makeGrowthObj(dff), 
survObj = makeSurvObj(dff))

rc <- timeToSize(startingSizes = startSizes, IPM = Pmatrix, endSize = 6, 
startingEnv = 1, maxT = 1000, propReach = 0.001)

names(rc)

par(mfrow=c(2,2), bty = "l")
## Make picture with lines for distribution of 
## population on different time points
matplot(Pmatrix@meshpoints, rc$ts.dist, type = "l", xlab = "size", 
ylab = "Number of individuals")

## Examine time elapsed for propReach to attain the chosen endSize
rc$time.reach

## Plot out the survivorship
plot(rc$survivorship, type = "l", #log = "y", 
xlab = "time step", ylab = "Probability original population survival", 
ylim = c(0,1), col = "gray")

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/timeToSize.Rd_%03d_medium.png", width=480, height=480)
> ### Name: timeToSize
> ### Title: Projects how long it takes to get from a starting distribution
> ###   to a target continuous stage value.
> ### Aliases: timeToSize
> ### Keywords: ~kwd1 ~kwd2
> 
> ### ** Examples
> 
> #note that with the "fake data" essentially either takes 
> #forever or is immediate...
> dff <- generateData()
> startSizes <- rnorm(1000, 2.5, 1)
> Pmatrix <- makeIPMPmatrix(minSize = 1.2*min(dff$size, na.rm=TRUE),
+ maxSize = 1.2*max(dff$size, na.rm=TRUE), 
+ growObj = makeGrowthObj(dff), 
+ survObj = makeSurvObj(dff))
> 
> rc <- timeToSize(startingSizes = startSizes, IPM = Pmatrix, endSize = 6, 
+ startingEnv = 1, maxT = 1000, propReach = 0.001)
[1] "Time to reach: 1"
> 
> names(rc)
[1] "ts.dist"      "time.reach"   "survivorship"
> 
> par(mfrow=c(2,2), bty = "l")
> ## Make picture with lines for distribution of 
> ## population on different time points
> matplot(Pmatrix@meshpoints, rc$ts.dist, type = "l", xlab = "size", 
+ ylab = "Number of individuals")
> 
> ## Examine time elapsed for propReach to attain the chosen endSize
> rc$time.reach
[1] 1
> 
> ## Plot out the survivorship
> plot(rc$survivorship, type = "l", #log = "y", 
+ xlab = "time step", ylab = "Probability original population survival", 
+ ylim = c(0,1), col = "gray")
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>