diff --git a/R/conditional_effects.R b/R/conditional_effects.R index 0954aae8..c7737467 100644 --- a/R/conditional_effects.R +++ b/R/conditional_effects.R @@ -934,7 +934,7 @@ make_point_frame <- function(bterms, mf, effects, conditions, model.frame(bterms$respform, mf, na.action = na.pass) ) req_vars <- names(mf) - groups <- get_re_groups(bterms) + groups <- get_re_group_vars(bterms) if (length(groups)) { c(req_vars) <- unlist(strsplit(groups, ":")) } diff --git a/R/exclude_pars.R b/R/exclude_pars.R index 9172c46f..fb3aa017 100644 --- a/R/exclude_pars.R +++ b/R/exclude_pars.R @@ -111,7 +111,7 @@ exclude_pars_re <- function(bframe, save_pars, ...) { c(out) <- paste0("r_", sub_reframe$id, sub_p, "_", sub_reframe$cn) } } - reframe_t <- get_dist_groups(reframe, "student") + reframe_t <- subset_reframe_dist(reframe, "student") if (!save_pars$all && has_rows(reframe_t)) { c(out) <- paste0(c("udf_", "dfm_"), reframe_t$ggn) } diff --git a/R/formula-ac.R b/R/formula-ac.R index 29b1a38d..8b76cc0b 100644 --- a/R/formula-ac.R +++ b/R/formula-ac.R @@ -607,8 +607,8 @@ get_ac_vars <- function(x, var, ...) { setdiff(na.omit(out), "NA") } -# get names of autocor grouping variables -get_ac_groups <- function(x, ...) { +# get names of grouping variables from ac terms +get_ac_group_vars <- function(x, ...) { get_ac_vars(x, "gr", ...) } diff --git a/R/formula-re.R b/R/formula-re.R index 2987310f..fb7cfe87 100644 --- a/R/formula-re.R +++ b/R/formula-re.R @@ -781,7 +781,7 @@ get_group_vars.mvbrmsterms <- function(x, ...) { } .get_group_vars <- function(x, ...) { - out <- c(get_re_groups(x), get_me_groups(x), get_ac_groups(x)) + out <- c(get_re_group_vars(x), get_me_group_vars(x), get_ac_group_vars(x)) out <- out[nzchar(out)] if (length(out)) { c(out) <- unlist(strsplit(out, ":")) @@ -790,13 +790,14 @@ get_group_vars.mvbrmsterms <- function(x, ...) { out } -# get names of grouping variables of re terms -get_re_groups <- function(x, ...) { +# get names of grouping variables from re terms +get_re_group_vars <- function(x, ...) { ufrom_list(get_re(x)$gcall, "groups") } -# extract information about groups with a certain distribution -get_dist_groups <- function(reframe, dist) { +# extract information about groups with a certain distribution from an reframe +subset_reframe_dist <- function(reframe, dist) { + stopifnot(is.reframe(reframe)) out <- subset2(reframe, dist = dist) out[!duplicated(out$group), c("group", "ggn", "id")] } diff --git a/R/formula-sp.R b/R/formula-sp.R index 1fa22ff9..da5d1a1e 100644 --- a/R/formula-sp.R +++ b/R/formula-sp.R @@ -496,8 +496,8 @@ get_sdy <- function(x, data = NULL) { sdy } -# names of grouping variables used in measurement error terms -get_me_groups <- function(x) { +# get names of grouping variables from me terms +get_me_group_vars <- function(x) { uni_me <- get_uni_me(x) out <- lapply(uni_me, eval2) out <- ufrom_list(out, "gr") diff --git a/R/priors.R b/R/priors.R index a161ee56..d3342aa6 100644 --- a/R/priors.R +++ b/R/priors.R @@ -965,7 +965,7 @@ prior_re <- function(bframe, internal = FALSE, ...) { } } } - reframe_t <- get_dist_groups(reframe, "student") + reframe_t <- subset_reframe_dist(reframe, "student") if (isTRUE(nrow(reframe_t) > 0L)) { prior <- prior + brmsprior("gamma(2, 0.1)", class = "df", group = reframe_t$group, lb = "1") diff --git a/R/rename_pars.R b/R/rename_pars.R index 98c7dfff..299f5c4c 100644 --- a/R/rename_pars.R +++ b/R/rename_pars.R @@ -440,7 +440,7 @@ rename_re <- function(bframe, pars, ...) { if (any(grepl("^r_", pars))) { c(out) <- rename_re_levels(bframe, pars = pars) } - reframe_t <- get_dist_groups(reframe, "student") + reframe_t <- subset_reframe_dist(reframe, "student") for (i in seq_rows(reframe_t)) { df_pos <- grepl(paste0("^df_", reframe_t$ggn[i], "$"), pars) df_name <- paste0("df_", reframe_t$group[i]) diff --git a/R/stan-predictor.R b/R/stan-predictor.R index 180217e0..2384ea1c 100644 --- a/R/stan-predictor.R +++ b/R/stan-predictor.R @@ -471,7 +471,7 @@ stan_re <- function(bframe, prior, normalize, ...) { out <- list() # special handling of student-t group effects as their 'df' parameters # are defined on a per-group basis instead of a per-ID basis - reframe_t <- get_dist_groups(reframe, "student") + reframe_t <- subset_reframe_dist(reframe, "student") if (has_rows(reframe_t)) { str_add(out$par) <- " // parameters for student-t distributed group-level effects\n" @@ -619,7 +619,7 @@ stan_re <- function(bframe, prior, normalize, ...) { # define group-level coefficients dfm <- "" - tr <- get_dist_groups(r, "student") + tr <- subset_reframe_dist(r, "student") if (nrow(r) > 1L && r$cor[1]) { # multiple correlated group-level effects str_add(out$data) <- glue(