Skip to content

Commit

Permalink
correctly store basis information in brmsframe objects
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-buerkner committed Jan 29, 2025
1 parent 9d1acf2 commit 89f3c86
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions R/brmsframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ brmsframe.brmsterms <- function(x, data, frame = NULL, basis = NULL, ...) {
x$frame <- frame
x$frame$re <- subset2(x$frame$re, resp = x$resp)
}
if (!is.null(basis)) {
x$frame$basis <- basis[c("resp_levels")]
}
data <- subset_data(data, x)
x$frame$resp <- frame_resp(x, data = data)
x$frame$ac <- frame_ac(x, data = data)
Expand Down
4 changes: 2 additions & 2 deletions R/data-response.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ data_response.brmsframe <- function(x, data, check_response = TRUE,
Y <- model.response(model.frame(x$respform, data, na.action = na.pass))
out <- list(N = N, Y = unname(Y))
if (is_binary(x$family)) {
bin_levels <- x$basis$resp_levels
bin_levels <- x$frame$basis$resp_levels
if (is.null(bin_levels)) {
bin_levels <- levels(as.factor(out$Y))
}
Expand All @@ -100,7 +100,7 @@ data_response.brmsframe <- function(x, data, check_response = TRUE,
out$Y <- as.integer(as_factor(out$Y, levels = bin_levels)) - 1
}
if (is_categorical(x$family)) {
out$Y <- as.integer(as_factor(out$Y, levels = x$basis$resp_levels))
out$Y <- as.integer(as_factor(out$Y, levels = x$frame$basis$resp_levels))
}
if (is_ordinal(x$family) && is.ordered(out$Y)) {
diff <- ifelse(has_extra_cat(x$family), 1L, 0L)
Expand Down

0 comments on commit 89f3c86

Please sign in to comment.