R: Compares growth and survival objects built from different...
growthModelComp
R Documentation
Compares growth and survival objects built from different covariate sets.
Description
Function compares model fits for growth and survival objects built with different linear combinations of covariates (plotting currently restricted to transforms of size; but comparison can include any chosen covariates). Growth can have multiple response forms.
Returns a list containing a summary table of covariates and scores, and another list containing all of the growth (or survival) objects used in the comparison.
dataframe with columns size, surv, and the growth response variable of choice
expVars
list of Formulas. Defaults to c(sizeNext~1, sizeNext~size, sizeNext~size + size2).
regressionType
character string identifying whether the type of regression run will have constant or changing variance (for growthModelComp. Defaults to constantVar.
testType
character string identifying the metric used to compare models. Can be any string that uses loglike from the lm or glm object. For example "AIC" or "BIC". Defaults to "AIC".
makePlot
logical whether to make plots with the comparison building. Defaults to FALSE.
mainTitle
string to place as the main attribute in plots (if makePlot = TRUE. defaults to NULL.
ncuts
for survModelComp, number of cuts in the data-set to be used in plotting
plotLegend
logical whether to plot a legend. Defaults to FALSE.
legendPos
places legend. Defaults to "topright".
...
additional arguments for plotting (ylim, col, etc)
Details
Both growthModelComp and survModelComp use a dataframe that has variables size and sizeNext to build a series of nested models. The default will build growth or survival objects with an intercept, an intercept and size, an an intercept with size and size^2 terms.
The models build use only lm or glm (and not mcmcGLMM for example) to estimate maximum likelihood estimates of functions. The testType (default "AIC" uses the loglike output from the lm or glm objects to score the model.
Plotting calls the functions plotGrowthModelComp or plotSurvModelComp to plot the objects. These functions can also be called after building the model comparison lists that are returned. If called outside of the initial building functions, they need to receive the GrowthObjects or SurvObjects list in the outputList from the build function. See plotGrowthModelComp and plotSurvModelComp for more details.
Value
a list with a summary table of class dataframe with models and scores and list of containing the objects of class grObj and survObj for each model.
Author(s)
C. Jessica E. Metcalf, Sean M. McMahon, Roberto Salguero-Gomez, Eelke Jongejans & Cory Merow.
# Data with size and sizeNext
dff <- generateData()
growthModelComp(dff, makePlot = TRUE)
survModelComp(dff, makePlot = TRUE)
growthModelComp(dff, makePlot = TRUE, regressionType = "changingVar")
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/growthModelComp.Rd_%03d_medium.png", width=480, height=480)
> ### Name: growthModelComp
> ### Title: Compares growth and survival objects built from different
> ### covariate sets.
> ### Aliases: growthModelComp survModelComp
>
> ### ** Examples
>
> # Data with size and sizeNext
> dff <- generateData()
>
> growthModelComp(dff, makePlot = TRUE)
$summaryTable
Exp. Vars Reg. Type AIC
1 sizeNext ~ 1 constantVar 1736.07099268502
2 sizeNext ~ size constantVar 1305.57055956641
3 sizeNext ~ size + size2 constantVar 1307.02981641614
$growthObjects
$growthObjects[[1]]
An object of class "growthObj"
Slot "fit":
Call:
lm(formula = Formula, data = dataf)
Coefficients:
(Intercept)
4.571
Slot "sd":
[1] 1.806852
$growthObjects[[2]]
An object of class "growthObj"
Slot "fit":
Call:
lm(formula = Formula, data = dataf)
Coefficients:
(Intercept) size
0.4147 0.7736
Slot "sd":
[1] 1.095279
$growthObjects[[3]]
An object of class "growthObj"
Slot "fit":
Call:
lm(formula = Formula, data = dataf)
Coefficients:
(Intercept) size size2
0.217786 0.859680 -0.008221
Slot "sd":
[1] 1.095871
> survModelComp(dff, makePlot = TRUE)
$summaryTable
Exp. Vars AIC
1 surv ~ 1 1251.96159540888
2 surv ~ size 1230.52157474617
3 surv ~ size + size2 1230.63374083071
$survObjects
$survObjects[[1]]
An object of class "survObj"
Slot "fit":
Call: glm(formula = Formula, family = binomial, data = dataf)
Coefficients:
(Intercept)
-0.09087
Degrees of Freedom: 902 Total (i.e. Null); 902 Residual
Null Deviance: 1250
Residual Deviance: 1250 AIC: 1252
$survObjects[[2]]
An object of class "survObj"
Slot "fit":
Call: glm(formula = Formula, family = binomial, data = dataf)
Coefficients:
(Intercept) size
-0.9472 0.1692
Degrees of Freedom: 902 Total (i.e. Null); 901 Residual
Null Deviance: 1250
Residual Deviance: 1227 AIC: 1231
$survObjects[[3]]
An object of class "survObj"
Slot "fit":
Call: glm(formula = Formula, family = binomial, data = dataf)
Coefficients:
(Intercept) size size2
-1.37001 0.36090 -0.01875
Degrees of Freedom: 902 Total (i.e. Null); 900 Residual
Null Deviance: 1250
Residual Deviance: 1225 AIC: 1231
>
> growthModelComp(dff, makePlot = TRUE, regressionType = "changingVar")
$summaryTable
Exp. Vars Reg. Type AIC
1 sizeNext ~ 1 changingVar 1741.11721358293
2 sizeNext ~ size changingVar 1315.7559642297
3 sizeNext ~ size + size2 changingVar 1324.03945205101
$growthObjects
$growthObjects[[1]]
An object of class "growthObjDeclineVar"
Slot "fit":
$coefficients
(Intercept)
4.571373
$sigmax2
[1] 3.264714
$var.exp.coef
[1] 0
$fit
Generalized least squares fit by REML
Model: Formula
Data: dataf
Log-restricted-likelihood: -867.5586
Coefficients:
(Intercept)
4.571373
Variance function:
Structure: Exponential of variance covariate
Formula: ~fitted(.)
Parameter estimates:
expon
0
Degrees of freedom: 431 total; 430 residual
Residual standard error: 1.806852
$growthObjects[[2]]
An object of class "growthObjDeclineVar"
Slot "fit":
$coefficients
(Intercept) size
0.4273720 0.7712547
$sigmax2
[1] 1.509199
$var.exp.coef
[1] -0.02539906
$fit
Generalized least squares fit by REML
Model: Formula
Data: dataf
Log-restricted-likelihood: -653.878
Coefficients:
(Intercept) size
0.4273720 0.7712547
Variance function:
Structure: Exponential of variance covariate
Formula: ~fitted(.)
Parameter estimates:
expon
-0.02539906
Degrees of freedom: 431 total; 429 residual
Residual standard error: 1.228494
$growthObjects[[3]]
An object of class "growthObjDeclineVar"
Slot "fit":
$coefficients
(Intercept) size size2
0.16113954 0.88370793 -0.01046486
$sigmax2
[1] 1.563399
$var.exp.coef
[1] -0.02922123
$fit
Generalized least squares fit by REML
Model: Formula
Data: dataf
Log-restricted-likelihood: -657.0197
Coefficients:
(Intercept) size size2
0.16113954 0.88370793 -0.01046486
Variance function:
Structure: Exponential of variance covariate
Formula: ~fitted(.)
Parameter estimates:
expon
-0.02922123
Degrees of freedom: 431 total; 428 residual
Residual standard error: 1.25036
>
>
>
>
>
>
> dev.off()
null device
1
>