MyNixOS website logo
Description

Partitioning R2 in GLMMs.

Partitioning the R2 of GLMMs into variation explained by each predictor and combination of predictors using semi-partial (part) R2 and inclusive R2. Methods are based on the R2 for GLMMs described in Nakagawa & Schielzeth (2013) and Nakagawa, Johnson & Schielzeth (2017).

CRAN totaldownloads Monthly downloadsbadge Lifecycle:maturing Codecov testcoverage

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:

  • R2 (marginal or conditional)
  • Part (semi-partial) R2, the variance explained uniquely by each predictor and combinations of predictors
  • Inclusive R2, the variance explained by a predictor independent of all other predictors
  • Structure coefficients, the correlation between a predictor and the fitted response
  • Beta weights, standardised model estimates

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 our paper:

Stoffel MA, Nakagawa S, Schielzeth H. 2021. partR2: partitioning R2 in generalized linear mixed models. PeerJ9:e11414 https://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.4439   0.5908   100   4  
#> 
#> ----------
#> 
#> Part (semi-partial) R2:
#>  Predictor(s)                      R2     CI_lower CI_upper nboot ndf
#>  Model                             0.5133 0.4439   0.5908   100   4  
#>  SpeciesDiversity                  0.1729 0.0736   0.2913   100   3  
#>  Temperature                       0.3058 0.2193   0.4106   100   3  
#>  Year                              0.0140 0.0000   0.1537   100   3  
#>  SpeciesDiversity+Temperature      0.4916 0.4205   0.5714   100   2  
#>  SpeciesDiversity+Year             0.1862 0.0883   0.3029   100   2  
#>  Temperature+Year                  0.3276 0.2430   0.4293   100   2  
#>  SpeciesDiversity+Temperature+Year 0.5133 0.4439   0.5908   100   1

And to plot the results:

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

Metadata

Version

0.9.2

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows