-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get_response(<brms>)
fails with aterm
s
#779
Comments
just a quick update
where rope_range is:
I don't know why it was difficult to calculate automatically the default rope range. But this fixed the issue. |
This is actually an issue in library(brms)
library(bayestestR)
fit4 <- brm(count | trunc(ub = 104) ~ zBase * Trt,
data = epilepsy, family = poisson(),
backend = "cmdstanr", cores = 4)
insight::get_response(fit4) # source = "environment"
#> Error in `[.data.frame`(model_data, , rn, drop = FALSE) :
#> undefined columns selected
insight::get_response(fit4, source = "mf")
#> Error in `[.data.frame`(model_data, , rn, drop = FALSE) :
#> undefined columns selected |
get_response(<brms>)
fails with a truncated response
The issue is a general issue with |
get_response(<brms>)
fails with a truncated responseget_response(<brms>)
fails with aterm
s
* `get_response(<brms>)` fails with a truncated response Fixes #779 * add test * news, version * fix tests * fix inaccuracy in test
When the library(brms)
fit4 <- brm(am | trials(1) ~ hp,
data = mtcars, family = binomial(),
backend = "cmdstanr", cores = 4)
insight::get_response(fit4) # source = "environment"
#> Error in `[.data.frame`(model_data, , rn, drop = FALSE) :
#> undefined columns selected
insight::get_response(fit4, source = "mf")
#> Error in `[.data.frame`(model_data, , rn, drop = FALSE) :
#> undefined columns selected This also means that your fix at #781 is wrong for this bug:
Originally posted by @mattansb in easystats/performance#596 (comment) |
* Fix aterms in brms-responses Fixes #779 * fix, add tests * spelling, lintr * styler * minor
I'm still getting this error (along with other related[?] ones) with a multivariate brms model with missing data imputation. Example based on the marginaleffects brms vignette (https://marginaleffects.com/vignettes/brms.html) library(marginaleffects)
library(brms)
dat <- read.csv("https://vincentarelbundock.github.io/Rdatasets/csv/carData/TitanicSurvival.csv")
dat$survived <- ifelse(dat$survived == "yes", 1, 0)
dat$woman <- ifelse(dat$sex == "female", 1, 0) |> as.factor()
sum(is.na(dat$age)) # <-- 263 missing values
mod_miss <- brm(bf(survived ~ woman*mi(age) + passengerClass, family=bernoulli(link = "logit")) +
bf(age | mi() ~ passengerClass + woman) +
set_rescor(FALSE),
data = dat,
backend = "cmdstanr",
cores=4)
#--------------------------------------
## Example 1
plot_slopes(mod_miss,
variables = "woman",
condition = "age")
# Error in `[.data.frame`(model_data, , rn, drop = FALSE) :
# undefined columns selected
#--------------------------------------
## Example 2
slopes(mod_miss,
newdata = datagrid(
woman = 1,
passengerClass = "1st"))
# Error: The following variables can neither be found in 'data' nor in 'data2':
# 'age'
# In addition: Warning message:
# These variables were not found: survived, age, . Try specifying the `newdata` argument explicitly and make sure
# the missing variable is included.
#--------------------------------------
## Example 3
slopes(mod_miss,
variables = "age",
newdata = datagrid(woman = 0:1)) |>
posterior_draws()
# Error: There is no valid predictor variable. Please change the `variables` argument or supply a new data frame to the
# `newdata` argument.
# In addition: Warning message:
# These variables were not found: miage. Try specifying the `newdata` argument explicitly and make sure the
# missing variable is included. And the tracebacks. #--------------------------------------
## Example 1
8: stop("undefined columns selected")
7: `[.data.frame`(model_data, , rn, drop = FALSE)
6: model_data[, rn, drop = FALSE]
5: get_response.default(model)
4: insight::get_response(model)
3: sanitize_condition(model, condition, variables, modeldata = modeldata)
2: plot_comparisons(model, variables = variables, condition = condition,
by = by, newdata = newdata, type = type, vcov = vcov, conf_level = conf_level,
wts = wts, draw = draw, rug = rug, gray = gray, comparison = slope,
...)
1: plot_slopes(mod_miss, variables = "woman", condition = "age")
#--------------------------------------
## Example 2
7: stop(format_message(string = string, ..., line_length = line_length,
indent = indent), call. = call)
6: format_alert(..., type = "error")
5: insight::format_error(pred_both[["error"]][["message"]])
4: get_contrasts(structure(list(formula = structure(list(forms = list(
survived = structure(list(formula = survived ~ woman * mi(age) +
passengerClass, pforms = list(), pfix = list(), family = structure(list(
family = "bernoulli", link = "logit", linkfun = function (mu)
link(mu, link = slink), linkinv = function (eta)
inv_link(eta, link = slink), dpars = "mu", type = "int",
ybounds = c(0, 1), closed = c(TRUE, TRUE), ad = c("weights",
"subset", "index"), specials = c("binary", "sbi_logit"
)), class = c("brmsfamily", "family")), resp = "survived",
mecor = TRUE), class = c("brmsformula", "bform")), age = structure(list(
formula = age | mi() ~ passengerClass + woman, pforms = list(),
pfix = list(), resp = "age", family = structure(list(
family = "gaussian", link = "identity", linkfun = function (mu)
link(mu, link = slink), linkinv = function (eta)
inv_link(eta, link = slink), dpars = c("mu", "sigma"
), type = "real", ybounds = c(-Inf, Inf), closed = c(NA,
NA), ad = c("weights", "subset", "se", "cens", "trunc",
"mi", "index"), normalized = c("_time_hom", "_time_het",
"_lagsar", "_errorsar", "_fcor"), specials = c("residuals",
"rescor")), class = c("brmsfamily", "family")), mecor = TRUE), class = c("brmsformula",
...
3: do.call("get_contrasts", args)
2: comparisons(model, newdata = newdata, variables = variables,
vcov = vcov, conf_level = conf_level, type = type, wts = wts,
hypothesis = hypothesis, equivalence = equivalence, df = df,
p_adjust = p_adjust, by = by, eps = eps, numderiv = numderiv,
comparison = slope, cross = FALSE, internal_call = TRUE,
...)
1: slopes(mod_miss, newdata = datagrid(woman = 1, passengerClass = "1st"))
#--------------------------------------
## Example 3
7: stop(format_message(string = string, ..., line_length = line_length,
indent = indent), call. = call)
6: format_alert(..., type = "error")
5: insight::format_error(msg)
4: sanitize_variables(model = model, newdata = newdata, modeldata = modeldata,
variables = variables, cross = cross, by = by, comparison = comparison,
eps = eps)
3: comparisons(model, newdata = newdata, variables = variables,
vcov = vcov, conf_level = conf_level, type = type, wts = wts,
hypothesis = hypothesis, equivalence = equivalence, df = df,
p_adjust = p_adjust, by = by, eps = eps, numderiv = numderiv,
comparison = slope, cross = FALSE, internal_call = TRUE,
...)
2: slopes(mod_miss, variables = "age", newdata = datagrid(woman = 0:1))
1: posterior_draws(slopes(mod_miss, variables = "age", newdata = datagrid(woman = 0:1)))
sessionInfo()
|
Maybe related to #896? Not sure, will check later. |
Hi,
I'm trying to use describe_posterior with a model fitted with brm but I get this error:
My model is:
I suspect that trunc function is causing some trouble as I've fitted the same model without trunc and describe_posterior is working well.
Do you have any suggestions?
The text was updated successfully, but these errors were encountered: