Formula (Nakagawa & Schielzeth 2013, eq. 26):
R2_marginal = sigma2_f / (sigma2_f + sigma2_l + sigma2_e),
where sigma2_f is the variance of the fixed-effect fitted
values, sigma2_l the between-cluster variance and
sigma2_e the residual variance. The conditional R-squared
adds sigma2_l to the numerator.
Usage
Niccgg(y, X, Z = NULL, cluster = NULL)
Arguments
- y
Response, length N.
- X
Fixed-effects design WITHOUT an intercept column.
- Z
Ignored; a random-intercept model has Z equal to the
cluster indicator, which cluster already supplies.
- cluster
Grouping label per observation.
Value
List with estimate, r2_marginal,
r2_conditional, sigma2_f, sigma2_l,
sigma2_e, icc, n, n_clusters.
Details
Determinism: the variance components are the one-way random-effects
ANOVA moment estimators on the OLS residuals, not an iterative REML
fit, so both language arms land on the same numbers exactly.
sigma2_e = MSW, sigma2_l = max(0, (MSB - MSW) / n0),
n0 = (N - sum n_i^2 / N) / (k - 1).
References
Nakagawa, S. & Schielzeth, H. (2013). A general and
simple method for obtaining R^2 from generalized linear
mixed-effects models. Methods in Ecology and Evolution, 4(2),
133-142. doi:10.1111/j.2041-210x.2012.00261.x
Examples
set.seed(1)
cl <- rep(1:20, each = 10)
x <- rnorm(200)
y <- 1 + 0.8 * x + rnorm(20)[cl] + rnorm(200)
Niccgg(y, X = matrix(x), cluster = cl)[c("r2_marginal", "r2_conditional", "icc")]
#> $r2_marginal
#> [1] 0.2285486
#>
#> $r2_conditional
#> [1] 0.6257546
#>
#> $icc
#> [1] 0.5148814
#>