Generate variance for random effects that produce desired intra-class coefficients (ICCs) for clustered data.

iccRE(ICC, dist, varTotal = NULL, varWithin = NULL, lambda = NULL, disp = NULL)

Arguments

ICC

Vector of values between 0 and 1 that represent the target ICC levels

dist

The distribution that describes the outcome data at the individual level. Possible distributions include "normal", "binary", "poisson", or "gamma"

varTotal

Numeric value that represents the total variation for a normally distributed model. If "normal" distribution is specified, either varTotal or varWithin must be specified, but not both.

varWithin

Numeric value that represents the variation within a cluster for a normally distributed model. If "normal" distribution is specified, either varTotal or varWithin must be specified, but not both.

lambda

Numeric value that represents the grand mean. Must be specified when distribution is "poisson" or "negative binomial".

disp

Numeric value that represents the dispersion parameter that is used to define a gamma or negative binomial distribution with a log link. Must be specified when distribution is "gamma".

Value

A vector of values that represents the variances of random effects at the cluster level that correspond to the ICC vector.

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, no. 2 (2013): 133-142.

Examples

targetICC <- seq(0.05, 0.20, by = .01)

iccRE(targetICC, "poisson", lambda = 30)
#>  [1] 0.001725780 0.002092967 0.002468051 0.002851289 0.003242950 0.003643314
#>  [7] 0.004052675 0.004471339 0.004899629 0.005337878 0.005786439 0.006245681
#> [13] 0.006715988 0.007197766 0.007691440 0.008197456

iccRE(targetICC, "binary")
#>  [1] 0.1731510 0.2099916 0.2476245 0.2860755 0.3253716 0.3655409 0.4066129
#>  [8] 0.4486184 0.4915895 0.5355599 0.5805650 0.6266415 0.6738284 0.7221662
#> [15] 0.7716975 0.8224670

iccRE(targetICC, "normal", varTotal = 100)
#>  [1]  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
iccRE(targetICC, "normal", varWithin = 100)
#>  [1]  5.263158  6.382979  7.526882  8.695652  9.890110 11.111111 12.359551
#>  [8] 13.636364 14.942529 16.279070 17.647059 19.047619 20.481928 21.951220
#> [15] 23.456790 25.000000

iccRE(targetICC, "gamma", disp = .5)
#>  [1] 0.03394390 0.04116600 0.04854342 0.05608122 0.06378469 0.07165934
#>  [7] 0.07971095 0.08794555 0.09636946 0.10498927 0.11381189 0.12284458
#> [13] 0.13209493 0.14157089 0.15128083 0.16123352

iccRE(targetICC, "negBinomial", lambda = 40, disp = .5)
#>  [1] 0.03609454 0.04377423 0.05161908 0.05963446 0.06782601 0.07619959
#>  [7] 0.08476134 0.09351768 0.10247531 0.11164126 0.12102288 0.13062787
#> [13] 0.14046431 0.15054066 0.16086581 0.17144908