Skip to content

Commit 8849680

Browse files
committed
air styler
1 parent c390c1f commit 8849680

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

R/estimate_grouplevel.R

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ estimate_grouplevel <- function(model, ...) {
7070

7171
#' @rdname estimate_grouplevel
7272
#' @export
73-
estimate_grouplevel.default <- function(model,
74-
type = "random",
75-
...) {
73+
estimate_grouplevel.default <- function(model, type = "random", ...) {
7674
# validate argument
7775
type <- insight::validate_argument(type, c("random", "total", "marginal"))
7876

@@ -123,12 +121,14 @@ estimate_grouplevel.default <- function(model,
123121

124122
#' @rdname estimate_grouplevel
125123
#' @export
126-
estimate_grouplevel.brmsfit <- function(model,
127-
type = "random",
128-
dispersion = TRUE,
129-
test = NULL,
130-
diagnostic = NULL,
131-
...) {
124+
estimate_grouplevel.brmsfit <- function(
125+
model,
126+
type = "random",
127+
dispersion = TRUE,
128+
test = NULL,
129+
diagnostic = NULL,
130+
...
131+
) {
132132
# validate argument
133133
type <- insight::validate_argument(type, c("random", "total"))
134134

@@ -152,7 +152,8 @@ estimate_grouplevel.brmsfit <- function(model,
152152

153153
# match parameters
154154
if (!is.null(clean_parameters)) {
155-
clean_parameters <- clean_parameters[clean_parameters$Parameter %in% params$Parameter, , drop = FALSE]
155+
# fmt: skip
156+
clean_parameters <- clean_parameters[clean_parameters$Parameter %in% params$Parameter, , drop = FALSE] # nolint
156157
}
157158

158159
# Re-add info
@@ -179,19 +180,17 @@ estimate_grouplevel.brmsfit <- function(model,
179180
# Filter out non-random effects
180181
random <- random[startsWith(random$Parameter, "r_"), ]
181182
# Remove Group from Level
182-
random$Level <- sapply(
183-
1:nrow(random),
184-
function(i) gsub(paste0("^", random$Group[i], "\\."), "", random$Level[i])
185-
)
183+
random$Level <- sapply(seq_len(nrow(random)), function(i) {
184+
gsub(paste0("^", random$Group[i], "\\."), "", random$Level[i])
185+
})
186186
# Find the group name (what follows "r_" and before the first "[" or "__")
187187
random$Group <- gsub("^r_(.*?)(\\[.*|__.*)", "\\1", random$Name)
188188
# Keep Parameter what's in between [ and ]
189189
random$Parameter <- gsub("^r_.*?\\[(.*?)\\].*", "\\1", random$Name)
190190
# Remove Level from it
191-
random$Parameter <- sapply(
192-
1:nrow(random),
193-
function(i) gsub(paste0("^", random$Level[i], "\\,"), "", random$Parameter[i])
194-
)
191+
random$Parameter <- sapply(seq_len(nrow(random)), function(i) {
192+
gsub(paste0("^", random$Level[i], "\\,"), "", random$Parameter[i])
193+
})
195194
# remove temporary name column
196195
random$Name <- NULL
197196
}
@@ -205,12 +204,14 @@ estimate_grouplevel.brmsfit <- function(model,
205204

206205

207206
#' @export
208-
estimate_grouplevel.stanreg <- function(model,
209-
type = "random",
210-
dispersion = TRUE,
211-
test = NULL,
212-
diagnostic = NULL,
213-
...) {
207+
estimate_grouplevel.stanreg <- function(
208+
model,
209+
type = "random",
210+
dispersion = TRUE,
211+
test = NULL,
212+
diagnostic = NULL,
213+
...
214+
) {
214215
# validate argument
215216
type <- insight::validate_argument(type, c("random", "total"))
216217

@@ -238,14 +239,10 @@ estimate_grouplevel.stanreg <- function(model,
238239
## insight::clean_parameter())
239240
if (!is.null(clean_parameters)) {
240241
# fix for rstanarm, which contains a sigma columns
241-
clean_parameters <- clean_parameters[
242-
clean_parameters$Component != "sigma" & !startsWith(clean_parameters$Parameter, "Sigma["), ,
243-
drop = FALSE # nolint
244-
]
245-
clean_parameters <- clean_parameters[
246-
clean_parameters$Parameter %in% params$Parameter, ,
247-
drop = FALSE
248-
]
242+
# fmt: skip
243+
clean_parameters <- clean_parameters[clean_parameters$Component != "sigma" & !startsWith(clean_parameters$Parameter, "Sigma["), , drop = FALSE] # nolint
244+
# fmt: skip
245+
clean_parameters <- clean_parameters[clean_parameters$Parameter %in% params$Parameter, , drop = FALSE] # nolint
249246

250247
params$Parameter <- insight::trim_ws(sub(":.*", "", clean_parameters$Group))
251248
params$Group <- insight::trim_ws(sub("^[^:]*:", "", clean_parameters$Group))
@@ -318,7 +315,9 @@ estimate_grouplevel.stanreg <- function(model,
318315
),
319316
]
320317
} else {
321-
random <- random[order(random$Group, datawizard::coerce_to_numeric(random$Level), random$Parameter), ] # nolint
318+
random <- random[
319+
order(random$Group, datawizard::coerce_to_numeric(random$Level), random$Parameter),
320+
]
322321
}
323322
random
324323
}

0 commit comments

Comments
 (0)