easystats / bayestestR

:ghost: Utilities for analyzing Bayesian models and posterior distributions
https://easystats.github.io/bayestestR/
GNU General Public License v3.0
577 stars 55 forks source link

error using describe_posterior #617

Closed FatemahSakr closed 10 months ago

FatemahSakr commented 1 year ago

Describe the bug I have updated my macOS to Monterey (12.6.7) then my R, Rstudio (now version 4.2.2). I tried to run my script using stan_glm and describe posterior, the models run fine however describe_posteribe through this error: Error in [.data.frame(model_data, , rn, drop = FALSE) : undefined columns selected

To Reproduce

m <- stan_glm(scale(X[,14]) ~ age_sampl_mn_frac + genotype , data = X, seed =111, chains = 4, cores= cpu.cores, iter= 10000,adapt_delta = 0.95, diagnostic_file = file.path(tempdir(), "df1.csv"))

xx <- describe_posterior(m, centrality = "median", dispersion = TRUE, ci= my.prob, ci_method= "HDI", test = c( "p_direction", "bayesfactor"))

Specifiations (please complete the following information):

strengejacke commented 1 year ago

This could still be a bug from #618. There are also some tests failing, seems like not all remaining bugs have been fixed yet. @mattansb @DominiqueMakowski any idea?

mattansb commented 1 year ago

This is is due to the DV being a non-proper column name X[,14].


library(rstanarm)
library(bayestestR)

m1 <- stan_glm(scale(mtcars[, 9]) ~ hp,
               data = mtcars, 
               cores = 4, refresh = 0)

m2 <- stan_glm(scale(am) ~ hp,
               data = mtcars, 
               cores = 4, refresh = 0)

describe_posterior(m1, test = c("p_direction", "bayesfactor"))
#> Error in `[.data.frame`(model_data, , rn, drop = FALSE) : 
#>   undefined columns selected

describe_posterior(m2, test = c("p_direction", "bayesfactor"))
#> Warning message:
#> Bayes factors might not be precise.
#>   For precise Bayes factors, sampling at least 40,000 posterior samples is recommended.
#> Summary of Posterior Distribution 
#> 
#> Parameter   |    Median |        95% CI |     pd |    BF |  Rhat |     ESS
#> --------------------------------------------------------------------------
#> (Intercept) |      0.52 | [-0.31, 1.37] | 89.20% | 0.177 | 1.000 | 3165.00
#> hp          | -3.51e-03 | [-0.01, 0.00] | 90.90% | 0.179 | 1.000 | 3638.00
strengejacke commented 1 year ago

Here's the source of the error:

library(insight)
m1 <- lm(scale(mtcars[, 9]) ~ hp,
               data = mtcars)
insight::find_response(m1)
#> [1] "mtcars"
insight::get_response(m1)
#> Error in `[.data.frame`(model_data, , rn, drop = FALSE): undefined columns selected

Created on 2023-09-30 with reprex v2.0.2