Skip to content

Commit 28435c4

Browse files
committed
spelling, styling
1 parent 14a06b2 commit 28435c4

File tree

5 files changed

+50
-39
lines changed

5 files changed

+50
-39
lines changed

R/estimate_grouplevel.R

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,30 @@
66
#' which can be useful to add the random effects to the original data.
77
#'
88
#' @param model A mixed model with random effects.
9-
#' @param type `"random"` or `"total"`.
10-
#' - If `"random"` (default), the
11-
#' coefficients correspond to the conditional estimates of the random effects
12-
#' (as they are returned by `lme4::ranef()`). They typically correspond to the
13-
#' deviation of each individual group from their fixed effect (assuming the
14-
#' random effect is also included as a fixed effect). As such, a coefficient
15-
#' close to 0 means that the participants' effect is the same as the
16-
#' population-level effect (in other words, it is "in the norm").
9+
#' @param type String, describing the type of estimates that should be returned.
10+
#' Can be `"random"`, `"total"`, or `"marginal"` (experimental).
11+
#' - If `"random"` (default), the coefficients correspond to the conditional
12+
#' estimates of the random effects (as they are returned by `lme4::ranef()`).
13+
#' They typically correspond to the deviation of each individual group from
14+
#' their fixed effect (assuming the random effect is also included as a fixed
15+
#' effect). As such, a coefficient close to 0 means that the participants'
16+
#' effect is the same as the population-level effect (in other words, it is
17+
#' "in the norm").
1718
#' - If `"total"`, it will return the sum of the random effect and its
1819
#' corresponding fixed effects, which internally relies on the `coef()` method
1920
#' (see `?coef.merMod`). Note that `type = "total"` yet does not return
2021
#' uncertainty indices (such as SE and CI) for models from *lme4* or
2122
#' *glmmTMB*, as the necessary information to compute them is not yet
2223
#' available. However, for Bayesian models, it is possible to compute them.
23-
#' - If `"marginal"` (experimental), it returns marginal group-levels estimates.
24-
#' The random intercepts are computed using marginal means (see [estimate_means()]),
25-
#' and the random slopes using marginal effects (see [estimate_slopes()]).
26-
#' This method does not directly extract the parameters estimated by the model,
27-
#' but recomputes them using model predictions. While this is more computationally
28-
#' intensive, one of the benefits include interpretability: the random intercepts
29-
#' correspond to the "mean" value of the outcome for each group, and the random slopes
30-
#' correspond to the direct "effect" of the predictor for each group.
24+
#' - If `"marginal"` (experimental), it returns marginal group-levels
25+
#' estimates. The random intercepts are computed using marginal means (see
26+
#' [estimate_means()]), and the random slopes using marginal effects (see
27+
#' [estimate_slopes()]). This method does not directly extract the parameters
28+
#' estimated by the model, but recomputes them using model predictions. While
29+
#' this is more computationally intensive, one of the benefits include
30+
#' interpretability: the random intercepts correspond to the "mean" value of
31+
#' the outcome for each group, and the random slopes correspond to the direct
32+
#' "effect" of the predictor for each group.
3133
#' @param dispersion,test,diagnostic Arguments passed to
3234
#' [parameters::model_parameters()] for Bayesian models. By default, it won't
3335
#' return significance or diagnostic indices (as it is not typically very
@@ -335,6 +337,8 @@ estimate_grouplevel.stanreg <- function(model,
335337
# cor.test(m1$Coefficient, m3$Coefficient) # r = 1
336338
# cor.test(m2$Coefficient, m3$Coefficient) # r = 1
337339
.grouplevel_marginal <- function(model) {
340+
insight::check_if_installed("lme4")
341+
338342
out <- list()
339343

340344
# Analyze random effect structure
@@ -352,7 +356,9 @@ estimate_grouplevel.stanreg <- function(model,
352356
pred <- insight::find_predictors(model, effects = "all", flatten = TRUE)
353357
s <- s[s %in% pred]
354358

355-
if (length(s) > 0) randomslopes[[g]] <- s
359+
if (length(s) > 0) {
360+
randomslopes[[g]] <- s
361+
}
356362
}
357363

358364
# TODO: check if it fixes are needed for cases where random intercept is suppressed (e.g., (0 + x | g) )

R/estimate_means.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,10 @@
306306
#'
307307
#' The output from `equivalence_test()` returns a column `SGPV`, the "second
308308
#' generation p-value", which is equivalent to the `p (Equivalence)` column when
309-
#' using the `equivalence` argument. It is basically representiv the ROPE coverage
310-
#' from the confidence interval of the estimate (i.e. the proportion of the
311-
#' confidence intervals that lies within the region of practical equivalence).
309+
#' using the `equivalence` argument. It is basically representative the ROPE
310+
#' coverage from the confidence interval of the estimate (i.e. the proportion of
311+
#' the confidence intervals that lies within the region of practical
312+
#' equivalence).
312313
#'
313314
#' @section Global Options to Customize Estimation of Marginal Means:
314315
#'

inst/WORDLIST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ individuals'
139139
interpretable
140140
intersectional
141141
intersectionality
142+
interpretability
142143
intra
143144
io
144145
jmr

man/estimate_grouplevel.Rd

Lines changed: 18 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/estimate_means.Rd

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)