A function that fits regressions that define growth (following next size,
size increment, or log size increment) and from these build growth objects for which methods to build an IPM object are defined; alternatively, the function creates growth objects following a specified formula with specified coefficients and sd.
Usage
makeGrowthObj(dataf=NULL, Formula = sizeNext ~ size,
regType = "constantVar", Family = "gaussian", link = NULL, coeff=NULL,sd=NULL)
Arguments
dataf
a dataframe with columns ‘size’ and
‘sizeNext’(‘size’ is size at t, ‘sizeNext’ is size at t+1);
facultatively, dataf may include ‘covariate’
and ‘covariatel’ for a single discrete covariate, indicating values at t,
and at t+1, respectively; these must take values of sequential integers, starting at
‘1’. For models fitting growth increment, 'incr' or 'logincr' may be directly provided as
a column in the dataframe, otherwise they are calculated as
dataf$sizeNext - dataf$size or log(dataf$sizeNext - dataf$size),
respectively.
Formula
a formula describing the desired
explanatory variables (interactions, etc) according to the R notation for formula.
style, i.e. separated by ‘+’, ‘*’, ‘:’ and response variable. Possible covariates include ‘size’, 'size2' (size^2), ‘size3’
(size^3),‘logsize’ (log(size)), ‘logsize2’ (log(size)^2), and
‘covariate’ (if this name is used, the assumption is made that this is a discrete covariate from which compound matrices may be constructed); or any other covariate available in dataf.
regType
possible values include ‘constantVar’ or ‘changingVar’
Family
possible values include ‘gaussian’, ‘poisson’, ‘negbin’
link
defaults to NULL, currently only relevant with Family="negbin", and only "log" and "identity" are permitted
coeff
numeric vector of required coefficients to be imposed if dataf is NULL; must be compatible with Formula
sd
numeric of required sd to be imposed if dataf is NULL
Value
An object of class growthObj, or growthObjPois, growthObjIncr, or growthObjLogIncr;
or growthObjDeclineVar, or growthObjIncrDeclineVar, or growthObjLogIncrDeclineVar.
These are S4 objects which contain the slots:
fit
an object of class lm or glm or gls that can be used with predict in the growth methods
Slots can be listed by using slotNames(growthObj)
Note
See manual for details on building case-specific growth objects. Note that DeclineVar objects cannot currently be constructed without a data-frame.
Author(s)
C. Jessica E. Metcalf, Sean M. McMahon, Roberto Salguero-Gomez & Eelke Jongejans
See Also
makeSurvObj, makeFecObj
Examples
#generate data
dff <- generateData()
#make simple linear regression growth object relating size to size at t+1
(gr1 <- makeGrowthObj(dataf = dff, Formula = sizeNext~size))
#same but relating size to incr
(gr1 <- makeGrowthObj(dataf = dff, Formula = incr ~ size))
#assess fit
picGrow(dff,gr1)
#same but relating size to incr and discrete covariate
(gr1 <- makeGrowthObj(dataf = dff, Formula = incr ~ size + covariate,
regType = "changingVar"))
#with declining increment
(gr1 <- makeGrowthObj(dataf = dff, Formula = incr ~ size + covariate,
regType = "changingVar"))
#now specifying parameters and supplying no data
gr1 <- makeGrowthObj(Formula = incr ~ size + covariate,coeff=c(1,1,1),sd=1)
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/makeGrowthObj.Rd_%03d_medium.png", width=480, height=480)
> ### Name: makeGrowthObj
> ### Title: Function to build growth objects
> ### Aliases: makeGrowthObj
>
> ### ** Examples
>
> #generate data
> dff <- generateData()
> #make simple linear regression growth object relating size to size at t+1
> (gr1 <- makeGrowthObj(dataf = dff, Formula = sizeNext~size))
An object of class "growthObj"
Slot "fit":
Call:
lm(formula = Formula, data = dataf)
Coefficients:
(Intercept) size
0.2987 0.7868
Slot "sd":
[1] 1.059566
> #same but relating size to incr
> (gr1 <- makeGrowthObj(dataf = dff, Formula = incr ~ size))
[1] "building incr as sizeNext - size"
An object of class "growthObjIncr"
Slot "fit":
Call:
lm(formula = Formula, data = dataf)
Coefficients:
(Intercept) size
0.2987 -0.2132
Slot "sd":
[1] 1.059566
>
> #assess fit
> picGrow(dff,gr1)
>
> #same but relating size to incr and discrete covariate
> (gr1 <- makeGrowthObj(dataf = dff, Formula = incr ~ size + covariate,
+ regType = "changingVar"))
[1] "building incr as sizeNext - size"
An object of class "growthObjIncrDeclineVar"
Slot "fit":
$coefficients
(Intercept) size covariate2
0.8180437 -0.2103019 -0.6496811
$sigmax2
[1] 0.921458
$var.exp.coef
[1] -0.08690733
$fit
Generalized least squares fit by REML
Model: Formula
Data: dataf
Log-restricted-likelihood: -634.7458
Coefficients:
(Intercept) size covariate2
0.8180437 -0.2103019 -0.6496811
Variance function:
Structure: Exponential of variance covariate
Formula: ~fitted(.)
Parameter estimates:
expon
-0.08690733
Degrees of freedom: 435 total; 432 residual
Residual standard error: 0.959926
> #with declining increment
> (gr1 <- makeGrowthObj(dataf = dff, Formula = incr ~ size + covariate,
+ regType = "changingVar"))
[1] "building incr as sizeNext - size"
An object of class "growthObjIncrDeclineVar"
Slot "fit":
$coefficients
(Intercept) size covariate2
0.8180437 -0.2103019 -0.6496811
$sigmax2
[1] 0.921458
$var.exp.coef
[1] -0.08690733
$fit
Generalized least squares fit by REML
Model: Formula
Data: dataf
Log-restricted-likelihood: -634.7458
Coefficients:
(Intercept) size covariate2
0.8180437 -0.2103019 -0.6496811
Variance function:
Structure: Exponential of variance covariate
Formula: ~fitted(.)
Parameter estimates:
expon
-0.08690733
Degrees of freedom: 435 total; 432 residual
Residual standard error: 0.959926
>
> #now specifying parameters and supplying no data
> gr1 <- makeGrowthObj(Formula = incr ~ size + covariate,coeff=c(1,1,1),sd=1)
>
>
>
>
>
>
>
>
> dev.off()
null device
1
>