# Goodness-of-fit statistics for linear models

### Description

Returns (pseudo)-R^2 and AIC values for component models in structural equation model (SEM).

### Usage

1 |

### Arguments

`modelList` |
a |

`aicc` |
whether AIC corrected for small sample size (AICc) should be returned. Default is |

### Details

Returns goodness-of-fit statistics for generalized linear (mixed) models, including (marginal and condition) R^2 and Akaike Information Criterion (AIC(c)) values.

### Value

Returns a `data.frame`

with the model class, the family, the link function, the marginal R^2 (based on fixed effects only) and/or conditional R^2 (based on fixed and random effects, if present), and the AIC(c) score (based on ML).

### Note

If the models in `modelList`

are all fit the same response, the function automatically returns the delta AIC(c) as the final column.

This function sources the `rsquared.glmm`

function found here: https://github.com/jslefche/rsquared.glmm, and thus may be periodically updated independently of this package.

### Author(s)

Jon Lefcheck & Juan Casallas

### References

Nakagawa, Shinichi, and Holger Schielzeth. "A general and simple method for obtaining R2 from generalized linear mixed-effects models." Methods in Ecology and Evolution 4.2 (2013): 133-142.

Johnson, Paul C.D. "Extension of Nakagawa & Schielzeth's R2GLMM to random slopes models." Methods in Ecology and Evolution.

### Examples

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | ```
# Load example data
data(shipley2009)
# Load model packages
library(lme4)
library(nlme)
# Create list of models
shipley2009.modlist = list(
lme(DD ~ lat, random = ~1|site/tree, na.action = na.omit,
data = shipley2009),
lme(Date ~ DD, random = ~1|site/tree, na.action = na.omit,
data = shipley2009),
lme(Growth ~ Date, random = ~1|site/tree, na.action = na.omit,
data = shipley2009),
glmer(Live ~ Growth+(1|site)+(1|tree),
family=binomial(link = "logit"), data = shipley2009)
)
# Return model fit statistics
rsquared(shipley2009.modlist)
## Not run:
# Get R2 for linear model
lm.mod = lm(DD ~ lat, data = shipley2009)
rsquared(lm.mod)
# Get R2 for generalized linear model
glm.mod = glm(Live ~ Growth, family = "binomial", data = shipley2009)
rsquared(glm.mod)
# Get R2 for generalized least-squares model
library(nlme)
gls.mod = gls(DD ~ lat, na.action = na.omit, data = shipley2009)
rsquared(gls.mod)
# Can supply the models as a list
# Use lm and gls -- should produce very similar R2s, will also produce delta AIC
rsquared(list(lm.mod, gls.mod))
# Get R2 for linear mixed effects model (nlme)
lme.mod = lme(DD ~ lat, random = ~1|site/tree, na.action = na.omit, data = shipley2009)
rsquared(lme.mod)
# Get R2 for linear mixed effects model (lme4)
library(lme4)
lmer.mod = lmer(DD ~ lat + (1|site/tree), data = shipley2009)
rsquared(lmer.mod)
# Get R2 for generalized linear mixed effects model (lme4)
glmer.mod = glmer(Live ~ Growth + (1|site/tree), family = "binomial", data = shipley2009)
rsquared(glmer.mod)
## End(Not run)
``` |