R: Iterates until obtaining the number of bins required so that...
convergeIPM
R Documentation
Iterates until obtaining the number of bins required so that the difference in the chosen measure (lambda, R0, life expectancy of a chosenBin) falls below a chosen tolerance level
Description
Increases bin number by a specified binIncrease until the difference in the chosen measure falls below a tolerance level
numeric, initial number of bins of size used in the matrix - will be increased for the assessment
minSize
numeric, minimum size used for meshpoints
maxSize
numeric, maximum size used for meshpoints of the P matrix.
discreteTrans
matrix of discrete transitions; or 1 if there is none
integrateType
integration type.
correction
correction (see makeIPMPmatrix)
preCensus
boolean defining whether fecundity is pre or post census; defaults to pre
tol
desired tolerance level
binIncrease
increments in increase in the number of bins (should be an integer)
chosenBin
desired bin for which life expectancy should be assessed; default is 1st.
response
what variable is convergence to be tested for; options are "lambda", "R0", "lifeExpect"; for the latter, the desired bin should be considered
Details
Different choices for responses will yield different values. The pattern of change in lambda (or other response variables) can be complex, so it is advisable to start with large binIncrease and small tolerance, and then once one knows a general idea of how big the matrix needs to be, run the function again with a smaller binIncrease but start it closer to the goal.
For the life expectancy option, if discrete stages are included via discreteTrans then if chosenBin=1, this function will use the first discrete bin.
Value
binIncrease
the number of bins used to increase matrix size in assessing tolerance
Pmatrix
the final Pmatrix if only LE is being considered
IPM
the final IPM
R0
the final R0
lambda
the final lambda
LE
the final vector of life expectancies
Note
This code was modified from original code by Melissa Eitzel.
Author(s)
C. Jessica E. Metcalf, Sean M. McMahon, Roberto Salguero-Gomez, Eelke Jongejans & Cory Merow.
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/convergeIPM.Rd_%03d_medium.png", width=480, height=480)
> ### Name: convergeIPM
> ### Title: Iterates until obtaining the number of bins required so that the
> ### difference in the chosen measure (lambda, R0, life expectancy of a
> ### chosenBin) falls below a chosen tolerance level
> ### Aliases: convergeIPM
>
> ### ** Examples
>
> dff<-generateData()
> gr1<-makeGrowthObj(dff)
> sv1<-makeSurvObj(dff)
> fv1<-makeFecObj(dff,Transform="log")
>
> res <- convergeIPM(growObj=gr1,
+ survObj=sv1, fecObj=fv1,
+ nBigMatrix=10, minSize=-2,
+ maxSize=15,discreteTrans = 1,
+ integrateType = "midpoint",
+ correction = "none",
+ preCensus = TRUE, tol=1e-3,binIncrease=10)
[1] "delta: new lambda:New number of grid points:\n "
[1] "997.416204478626 2.58379552137448 20"
[1] "0.00163247533384325 2.58542799670832 30"
[1] "2.67777497420241e-06 2.58542531893334 40"
[1] "Final lambda from iteration:" "2.58542531893334"
[1] "Number of bins:" "40"
>
> res <- convergeIPM(growObj=gr1,
+ survObj=sv1, fecObj=fv1,
+ nBigMatrix=10, minSize=-2,
+ maxSize=15,discreteTrans = 1,
+ integrateType = "midpoint",
+ correction = "none",
+ preCensus = TRUE, tol=1e-3,
+ binIncrease=10, response="R0")
[1] "delta: new R0:New number of grid points:"
[1] "996.423804511585 3.57619548841513 20"
[1] "0.0028345506834242 3.57903003909855 30"
[1] "2.86530353070802e-05 3.57900138606325 40"
[1] "Final R0 from iteration:" "3.57900138606325"
[1] "Number of bins:" "40"
>
> res <- convergeIPM(growObj=gr1, survObj=sv1, fecObj=fv1,
+ nBigMatrix=10, minSize=-2,
+ maxSize=15,discreteTrans = 1,
+ integrateType = "midpoint",
+ correction = "none",
+ preCensus = TRUE, tol=1e-3,binIncrease=10,
+ response="lifeExpect")
[1] "delta: new LE:New number of grid points:"
[1] "998.687961611648 1.31203838835194 20"
[1] "0.0179904786957996 1.29404790965614 30"
[1] "0.00886927807009985 1.28517863158604 40"
[1] "0.00528051827108622 1.27989811331495 50"
[1] "0.00350336738358981 1.27639474593136 60"
[1] "0.0024941714339044 1.27390057449746 70"
[1] "0.00186616665802042 1.27203440783944 80"
[1] "0.00144883964771414 1.27058556819172 90"
[1] "0.00115743012123737 1.26942813807048 100"
[1] "0.000945909150347868 1.26848222892014 110"
[1] "Final life expectancy of chosen bin from iteration:"
[2] "1.26848222892014"
[1] "Number of bins:" "110"
>
>
>
>
>
>
>
>
> dev.off()
null device
1
>