Last data update: 2014.03.03

R: Calculates growth objects reflecting distribution of...
sampleVitalRateObjR Documentation

Calculates growth objects reflecting distribution of parameters from lm or glm.

Description

Generate parametric bootstrap samples for vital rate objects (e.g. class growthObj, survObj, fecObj, etc.) from estimated parameters and the variance covariance matrix that defines them using a multivariate normal distribution. It is helpful when building multiple IPMs for study of parameter uncertainty or stochastic dynamics.

Usage

sampleVitalRateObj(
				Obj, 
				nSamp=100, 
				nDiscreteGrowthTransitions=NULL,
				nDiscreteOffspringTransitions = NULL,
				nOffspring = NULL)



Arguments

Obj

a growth or survival object with a slot named "fit" containing an lm or glm, etc., or a fertility object with a slot named "fitFec" for .getListRegObjectsFec, likewise.

nSamp

desired number of samples from the multivariate normal.

nDiscreteGrowthTransitions

number of transitions used to estimate a discreteTrans object. This is used to estimate the correct variance for sampling the discreteTrans object. It is only required if a discreteTransObject is provided.

nDiscreteOffspringTransitions

number of transitions used to estimate transition probabilities between discrete offspring stages (stored in the @offspringSplitter slot of a fecObj). This is used to estimate the correct variance for the sampling. It is only required if a fecObject is provided.

nOffspring

number of transitions used to the offspring size distribution (stored in the @offspringRel and @offspringsd slots of a fecObj). This is used to estimate the correct variance for the sampling. It is only required if a fecObject is provided.

Value

The output is list of the provided vital rate object with different parameter values in each list element, e.g. a list of growth or survival objects containing an lm or glm; or fertility objects likewise.

Note

This function has replaced the functionality of getListRegObjects and getListRegObjects. Those functions are no longer supported but have been hidden (.getListRegObjects and .getListRegObjects) and can be accessed for backward compatibility.

Author(s)

Cory Merow, C. Jessica E. Metcalf, Sean M. McMahon, Roberto Salguero-Gomez, Eelke Jongejans.

See Also

sampleIPM ,sampleIPMOutput,sampleSequentialIPMs

Examples


# ===========================================================================
# Sample Vital Rate Objects
	# Parametric bootstrap sample for a growth object 
		dff <- generateData(type='discrete')
		gr1 <- makeGrowthObj(dff)
		gr1List=sampleVitalRateObj(gr1,nSamp=9)

	# Parametric bootstrap sample for a survival object 
		sv1 <- makeSurvObj(dff)
		sv1List=sampleVitalRateObj(sv1,nSamp=9)

	# Parametric bootstrap sample for a fecundity object 
		fv1 <- makeFecObj(dff)
		fv1List=sampleVitalRateObj(
			fv1,nSamp=9,
			nDiscreteOffspringTransitions =100,
			nOffspring=100)

	# Parametric bootstrap sample for a discrete transition object 
		dt1 <- makeDiscreteTrans(dff)
		dt1List=sampleVitalRateObj(
			dt1,nSamp=9,
			nDiscreteGrowthTransitions=100)
# ===========================================================================
	# Make a list of growth/survival (P) matrices (omitting fecundity)
		Pmatrixlist=sampleIPM(
			growObjList=gr1List,
			survObjList=sv1List,
			fecObjList =NULL,
			nBigMatrix = 20, minSize = -5, maxSize = 20)
		# plot results
		par(mfrow=c(3,3))
		lapply(Pmatrixlist,image)

	# Combine the list of fecundity objects with a single survival 
	# and growth object in a list of IPMs to look at just the impact 
	# of uncertainty in fecundity parameter estimates on population 
	# growth rate
		IPMlist2=sampleIPM(
			growObjList=list(gr1),
			survObjList=list(sv1),
			fecObjList =fv1List,
			discreteTransList=list(dt1), 
			nBigMatrix = 20, minSize = -5, maxSize = 20)
		# plot results
		lapply(IPMlist2,image) 

	# Combine the lists of all vital rate objects in a list of IPMs 
	# to look at the impact of uncertainty in all parameters on population 
	# growth rate
		IPMlist3=sampleIPM(
			growObjList=gr1List,
			survObjList=sv1List,
			fecObjList =fv1List,
			discreteTransList=list(dt1),
			nBigMatrix = 20, minSize = -5, maxSize = 20)
		# plot results
		lapply(IPMlist3,image) 

# ===========================================================================
# Summarize the outputs	
	# Get uncertainty in passage time from the list of growth/survival matrices
		IPMout1=sampleIPMOutput(PMatrixList=Pmatrixlist)
		qLE=apply(IPMout1[['LE']],2,quantile,probs=c(.025,.5,.975))
		plot(IPMout1$meshpoints,qLE[2,],type='l',ylim=c(0,max(qLE)))
		lines(IPMout1$meshpoints,qLE[1,],type='l',lty=3)
		lines(IPMout1$meshpoints,qLE[3,],type='l',lty=3)

	# Get uncertainty in lambda from the list of IPMs where only 
	# fecundity varied
		IPMout2=sampleIPMOutput(IPMList=IPMlist2)
		qlambda=quantile(IPMout2[['lambda']],probs=c(.025,.5,.975))
		boxplot(IPMout2[['lambda']])
	
	# Get uncertainty in lambda and passage time from size 5 
	#to a series of size from the list of IPMs where all vital rates varied
		IPMout3=sampleIPMOutput(
			IPMList=IPMlist3,
			passageTimeTargetSize=c(10),
			sizeToAgeStartSize=c(5),
			sizeToAgeTargetSize=c(6,7,8,9,10))
		qlambda=quantile(IPMout3[['lambda']],probs=c(.025,.5,.975))
		boxplot(IPMout3[['resAge']]) 

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/sampleVitalRateObj.Rd_%03d_medium.png", width=480, height=480)
> ### Name: sampleVitalRateObj
> ### Title: Calculates growth objects reflecting distribution of parameters
> ###   from lm or glm.
> ### Aliases: sampleVitalRateObj .getListRegObjects .getListRegObjectsFec
> 
> ### ** Examples
> 
> 
> # ===========================================================================
> # Sample Vital Rate Objects
> 	# Parametric bootstrap sample for a growth object 
> 		dff <- generateData(type='discrete')
> 		gr1 <- makeGrowthObj(dff)
> 		gr1List=sampleVitalRateObj(gr1,nSamp=9)
Loading required package: mvtnorm
Loading required package: MCMCpack
Loading required package: coda
##
## Markov Chain Monte Carlo Package (MCMCpack)
## Copyright (C) 2003-2016 Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park
##
## Support provided by the U.S. National Science Foundation
## (Grants SES-0350646 and SES-0350613)
##
> 
> 	# Parametric bootstrap sample for a survival object 
> 		sv1 <- makeSurvObj(dff)
> 		sv1List=sampleVitalRateObj(sv1,nSamp=9)
> 
> 	# Parametric bootstrap sample for a fecundity object 
> 		fv1 <- makeFecObj(dff)
[1] "Warning - offspring splitter indicates more than just continuous stages. No fecundity by the discrete stages supplied in fecByDiscrete; assumed that is 0"
> 		fv1List=sampleVitalRateObj(
+ 			fv1,nSamp=9,
+ 			nDiscreteOffspringTransitions =100,
+ 			nOffspring=100)
> 
> 	# Parametric bootstrap sample for a discrete transition object 
> 		dt1 <- makeDiscreteTrans(dff)
> 		dt1List=sampleVitalRateObj(
+ 			dt1,nSamp=9,
+ 			nDiscreteGrowthTransitions=100)
> # ===========================================================================
> 	# Make a list of growth/survival (P) matrices (omitting fecundity)
> 		Pmatrixlist=sampleIPM(
+ 			growObjList=gr1List,
+ 			survObjList=sv1List,
+ 			fecObjList =NULL,
+ 			nBigMatrix = 20, minSize = -5, maxSize = 20)
> 		# plot results
> 		par(mfrow=c(3,3))
> 		lapply(Pmatrixlist,image)
[[1]]
NULL

[[2]]
NULL

[[3]]
NULL

[[4]]
NULL

[[5]]
NULL

[[6]]
NULL

[[7]]
NULL

[[8]]
NULL

[[9]]
NULL

> 
> 	# Combine the list of fecundity objects with a single survival 
> 	# and growth object in a list of IPMs to look at just the impact 
> 	# of uncertainty in fecundity parameter estimates on population 
> 	# growth rate
> 		IPMlist2=sampleIPM(
+ 			growObjList=list(gr1),
+ 			survObjList=list(sv1),
+ 			fecObjList =fv1List,
+ 			discreteTransList=list(dt1), 
+ 			nBigMatrix = 20, minSize = -5, maxSize = 20)
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
Warning messages:
1: In sampleIPM(growObjList = list(gr1), survObjList = list(sv1), fecObjList = fv1List,  :
  Length of growth object list is less than the length of another vital rate object list, so some members of the growth object list have been repeated.
2: In sampleIPM(growObjList = list(gr1), survObjList = list(sv1), fecObjList = fv1List,  :
  Length of survival object list is less than the length of another vital rate object list, so some members of the survival object list have been repeated.
> 		# plot results
> 		lapply(IPMlist2,image) 
[[1]]
NULL

[[2]]
NULL

[[3]]
NULL

[[4]]
NULL

[[5]]
NULL

[[6]]
NULL

[[7]]
NULL

[[8]]
NULL

[[9]]
NULL

> 
> 	# Combine the lists of all vital rate objects in a list of IPMs 
> 	# to look at the impact of uncertainty in all parameters on population 
> 	# growth rate
> 		IPMlist3=sampleIPM(
+ 			growObjList=gr1List,
+ 			survObjList=sv1List,
+ 			fecObjList =fv1List,
+ 			discreteTransList=list(dt1),
+ 			nBigMatrix = 20, minSize = -5, maxSize = 20)
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
[1] "Warning: fertility values < 0 exist in matrix, consider transforms. Negative values set to zero"
> 		# plot results
> 		lapply(IPMlist3,image) 
[[1]]
NULL

[[2]]
NULL

[[3]]
NULL

[[4]]
NULL

[[5]]
NULL

[[6]]
NULL

[[7]]
NULL

[[8]]
NULL

[[9]]
NULL

> 
> # ===========================================================================
> # Summarize the outputs	
> 	# Get uncertainty in passage time from the list of growth/survival matrices
> 		IPMout1=sampleIPMOutput(PMatrixList=Pmatrixlist)
[1] "no target size for passage time provided; taking meshpoint median"
[1] "no starting size for size to age provided; taking minimum size"
[1] "no target size for size to age provided; taking meshpoint values"
> 		qLE=apply(IPMout1[['LE']],2,quantile,probs=c(.025,.5,.975))
> 		plot(IPMout1$meshpoints,qLE[2,],type='l',ylim=c(0,max(qLE)))
> 		lines(IPMout1$meshpoints,qLE[1,],type='l',lty=3)
> 		lines(IPMout1$meshpoints,qLE[3,],type='l',lty=3)
> 
> 	# Get uncertainty in lambda from the list of IPMs where only 
> 	# fecundity varied
> 		IPMout2=sampleIPMOutput(IPMList=IPMlist2)
[1] "no target size for passage time provided; taking meshpoint median"
[1] "no starting size for size to age provided; taking minimum size"
[1] "no target size for size to age provided; taking meshpoint values"
> 		qlambda=quantile(IPMout2[['lambda']],probs=c(.025,.5,.975))
> 		boxplot(IPMout2[['lambda']])
> 	
> 	# Get uncertainty in lambda and passage time from size 5 
> 	#to a series of size from the list of IPMs where all vital rates varied
> 		IPMout3=sampleIPMOutput(
+ 			IPMList=IPMlist3,
+ 			passageTimeTargetSize=c(10),
+ 			sizeToAgeStartSize=c(5),
+ 			sizeToAgeTargetSize=c(6,7,8,9,10))
> 		qlambda=quantile(IPMout3[['lambda']],probs=c(.025,.5,.975))
> 		boxplot(IPMout3[['resAge']]) 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>