GitHub - mastoffel/partR2: R package to partition R2 among predictors in Generalized linear mixed models (original) (raw)

CRAN total downloads Monthly downloads badge Lifecycle: maturing Codecov test coverage

partR2

The goal of partR2 is to estimate R2 in GLMMs (sensu Nakagawa & Schielzeth 2013) and to partition the R2 into the variance explained by the predictors.

The package takes a fitted lme4 model as input and gives you:

All estimates can be combined with parametric bootstrapping to get confidence intervals.

Installation

You can install the stable version of partR2 from CRAN with:

install.packages("partR2")

Or the development version from GitHub with:

install.packages("remotes")

remotes::install_github("mastoffel/partR2", build_vignettes = TRUE, dependencies = TRUE)

Access the vignette with:

check vignette

browseVignettes("partR2")

partR2 is still in an early phase of development and might contain bugs. If you find one, please report a minimal reproducible example in the issues.

Citation

When using partR2, please cite ourpaper:

Stoffel MA, Nakagawa S, Schielzeth H. 2021. partR2: partitioning R2 in generalized linear mixed models. PeerJ 9:e11414https://doi.org/10.7717/peerj.11414

Example

library(partR2) library(lme4)

?partR2-package

load data

data(biomass)

fit lme4 model

mod <- lmer(Biomass ~ Year + Temperature + SpeciesDiversity + (1|Population), data = biomass)

R2s and partial R2s

(R2 <- partR2(mod, partvars = c("SpeciesDiversity", "Temperature", "Year"), R2_type = "marginal", nboot = 100, CI = 0.95)) #> #> #> R2 (marginal) and 95% CI for the full model: #> R2 CI_lower CI_upper nboot ndf #> 0.5133 0.4383 0.5848 100 4
#> #> ---------- #> #> Part (semi-partial) R2: #> Predictor(s) R2 CI_lower CI_upper nboot ndf #> Model 0.5133 0.4383 0.5848 100 4
#> SpeciesDiversity 0.1729 0.0682 0.2721 100 3
#> Temperature 0.3058 0.2128 0.3917 100 3
#> Year 0.0140 0.0000 0.1354 100 3
#> SpeciesDiversity+Temperature 0.4916 0.4147 0.5638 100 2
#> SpeciesDiversity+Year 0.1862 0.0827 0.2835 100 2
#> Temperature+Year 0.3276 0.2364 0.4117 100 2
#> SpeciesDiversity+Temperature+Year 0.5133 0.4383 0.5848 100 1

And to plot the results:

forestplot(R2, type = "R2", line_size = 0.7, text_size = 14, point_size = 3)