Skip to content

Commit

Permalink
minor renaming of internal functions
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-buerkner committed Nov 8, 2024
1 parent bfc6398 commit 8ed8036
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion R/conditional_effects.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ":"))
}
Expand Down
2 changes: 1 addition & 1 deletion R/exclude_pars.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions R/formula-ac.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", ...)
}

Expand Down
11 changes: 6 additions & 5 deletions R/formula-re.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ":"))
Expand All @@ -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")]
}
Expand Down
4 changes: 2 additions & 2 deletions R/formula-sp.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion R/priors.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion R/rename_pars.R
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions R/stan-predictor.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 8ed8036

Please sign in to comment.