Skip to content

Commit

Permalink
feature issue #1635
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-buerkner committed Sep 12, 2024
1 parent 39a6fee commit a04ac68
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Package: brms
Encoding: UTF-8
Type: Package
Title: Bayesian Regression Models using 'Stan'
Version: 2.21.6
Date: 2024-06-06
Version: 2.21.7
Date: 2024-09-12
Authors@R:
c(person("Paul-Christian", "Bürkner", email = "paul.buerkner@gmail.com",
role = c("aut", "cre")),
Expand Down
23 changes: 23 additions & 0 deletions R/numeric-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,26 @@ log1m_inv_softit <- function(x) {
y <- log1p_exp(x)
-log1p(y)
}

# names of built-in stan functons reimplemented in R within brms
names_stan_functions <- function() {
c("logit", "inv_logit", "cloglog", "inv_cloglog", "Phi", "incgamma",
"square", "cbrt", "exp2", "pow", "inv", "inv_sqrt", "inv_square",
"hypot", "log1m", "step", "logm1", "expp1", "logit_scaled",
"inv_logit_scaled", "multiply_log", "log1p_exp", "log1m_exp",
"log_diff_exp", "log_sum_exp", "log_mean_exp", "log_expm1",
"log_inv_logit", "log1m_inv_logit", "scale_unit", "fabs", "log_softmax",
"softmax", "inv_odds", "softit", "inv_softit", "log_inv_softit",
"log1m_inv_softit")
}

# create an environement with all the reimplemented stan functions in it
# see issue #1635 for discussion of this approach
env_stan_functions <- function(...) {
env <- new.env(...)
brms_env <- asNamespace("brms")
for (f in names_stan_functions()) {
env[[f]] <- get(f, brms_env)
}
env
}
2 changes: 1 addition & 1 deletion R/prepare_predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ prepare_predictions.bframenl <- function(x, draws, sdata, ...) {
out <- list(
family = x$family,
nlform = x$formula[[2]],
env = environment(x$formula),
env = env_stan_functions(parent = environment(x$formula)),
ndraws = nrow(draws),
nobs = sdata[[paste0("N", usc(x$resp))]],
used_nlpars = x$used_nlpars,
Expand Down

0 comments on commit a04ac68

Please sign in to comment.