expectedRank calculates the expected rank and the percentile expected
rank of any random term in a merMod object. A simple ranking of the estimated
random effects (as produced by
ranef) is not satisfactory
because it ignores any amount of uncertainty.
An object of class merMod
An optional character vector specifying the name(s) the grouping factor(s)
over which the random coefficient of interest varies. This is the
variable to the right of the pipe,
An optional character vector specifying the name(s) of the random coefficient of interest. This is the
variable to the left of the pipe,
Inspired by Lingsma et al. (2010, see also Laird and Louis 1989), expectedRank sums the probability that each level of the grouping factor is greater than every other level of the grouping factor, similar to a two-sample t-test.
The formula for the expected rank is:
ExpectedRank_i = 1 + ∑ φ((θ_i - θ_k) / √(var(θ_i)+var(θ_k))
where φ is the standard normal distribution function, θ is the estimated random effect and var(θ) is the posterior variance of the estimated random effect. We add one to the sum so that the minimum rank is one instead of zero so that in the case where there is no overlap between the variances of the random effects (or if the variances are zero), the expected rank equals the actual rank. The ranks are ordered such that the winners have ranks that are greater than the losers.
The formula for the percentile expected rank is:
100 * (ExpectedRank_i - 0.5) / N_grps
where N_grps is the number of grouping factor levels. The percentile expected rank can be interpreted as the fraction of levels that score at or below the given level.
expectedRank will only work under conditions that
will work. One current example of when this is not the case is for
models when there are multiple terms specified per factor (e.g. uncorrelated random
coefficients for the same term, e.g.
lmer(Reaction ~ Days + (1 | Subject) + (0 + Days | Subject), data = sleepstudy))
A data.frame with the following five columns:
a character representing name of the grouping factor
a character representing the level of the grouping factor
a character representing the formula term for the group
effect estimate from
the posterior variance of the estimate random effect
lme4::ranef(, condVar=TRUE)); named "
The expected rank.
The percentile expected rank.
Laird NM and Louis TA. Empirical Bayes Ranking Methods. Journal of Education Statistics. 1989;14(1)29-46. Available at http://www.jstor.org/stable/1164724.
Lingsma HF, Steyerberg EW, Eijkemans MJC, et al. Comparing and ranking hospitals based on outcome: results from The Netherlands Stroke Survey. QJM: An International Journal of Medicine. 2010;103(2):99-108. doi:10.1093/qjmed/hcp169
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#For a one-level random intercept model require(lme4) m1 <- lmer(Reaction ~ Days + (1 | Subject), sleepstudy) (m1.er <- expectedRank(m1)) #For a one-level random intercept model with multiple random terms require(lme4) m2 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy) #ranked by the random slope on Days (m2.er1 <- expectedRank(m2, term="Days")) #ranked by the random intercept (m2.er2 <- expectedRank(m2, term="int")) ## Not run: #For a two-level model with random intercepts require(lme4) m3 <- lmer(y ~ service * dept + (1|s) + (1|d), InstEval) #Ranked by the random intercept on 's' (m3.er1 <- expectedRank(m3, groupFctr="s", term="Intercept")) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.