easystats / parameters

:bar_chart: Computation and processing of models' parameters
https://easystats.github.io/parameters/
GNU General Public License v3.0
435 stars 36 forks source link

Error in exp(spurious_coefficients) : non-numeric argument to mathematical function #999

Closed rbcavanaugh closed 2 months ago

rbcavanaugh commented 2 months ago

This error / warning? appears to relate to brms bernoulli models

Code I think it's from: .print_footer_exp <- function(x) in https://github.com/easystats/parameters/blob/e949952b09c90b7b9ab29715e14bce79be9bd9a6/R/format.R#L926.

library(brms)
library(parameters)

df <- data.frame(
  outcome = sample(c(0, 1), 100, replace = TRUE),
  pred = rnorm(100, 0, 1)
)

m = brm(outcome ~ pred, family = bernoulli(), refresh = 0, data = df)

# no error
> parameters::model_parameters(m, exponentiate = TRUE)

# Fixed Effects

Parameter   | Median |       95% CI |     pd |  Rhat |     ESS
--------------------------------------------------------------
(Intercept) |   0.95 | [0.67, 1.43] | 59.27% | 1.000 | 3368.00
pred        |   0.97 | [0.67, 1.41] | 55.70% | 1.000 | 3567.00

Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed using a MCMC distribution approximation.

# error:
> parameters::model_parameters(m, exponentiate = FALSE)

# Fixed Effects

Parameter   | Median |        95% CI |     pd |  Rhat |     ESS
---------------------------------------------------------------
(Intercept) |  -0.05 | [-0.41, 0.36] | 59.27% | 1.000 | 3368.00
pred        |  -0.03 | [-0.40, 0.34] | 55.70% | 1.000 | 3567.00

Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed using a MCMC distribution approximation.
Error in exp(spurious_coefficients) : 
  non-numeric argument to mathematical function
> sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.5.2

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] parameters_0.22.1 brms_2.21.0       Rcpp_1.0.13      

loaded via a namespace (and not attached):
 [1] Brobdingnag_1.2-9    rstan_2.32.6         tidyselect_1.2.1     QuickJSR_1.3.1       lattice_0.20-45      colorspace_2.1-0    
 [7] vctrs_0.6.5          generics_0.1.3       stats4_4.2.2         loo_2.8.0            utf8_1.2.4           rlang_1.1.4         
[13] pkgbuild_1.4.4       pillar_1.9.0         glue_1.7.0           distributional_0.4.0 matrixStats_1.3.0    lifecycle_1.0.4     
[19] stringr_1.5.1        posterior_1.6.0      munsell_0.5.1        gtable_0.3.5         bayestestR_0.14.0    mvtnorm_1.2-5       
[25] codetools_0.2-18     coda_0.19-4.1        inline_0.3.19        callr_3.7.6          ps_1.7.7             datawizard_0.12.2   
[31] parallel_4.2.2       fansi_1.0.6          bayesplot_1.11.1     rstantools_2.4.0     renv_0.17.0          scales_1.3.0        
[37] backports_1.5.0      checkmate_2.3.1      RcppParallel_5.1.8   StanHeaders_2.32.10  abind_1.4-5          gridExtra_2.3       
[43] tensorA_0.36.2.1     ggplot2_3.5.1        stringi_1.8.4        processx_3.8.4       insight_0.20.2       dplyr_1.1.4         
[49] grid_4.2.2           cli_3.6.3            tools_4.2.2          magrittr_2.0.3       tibble_3.2.1         pkgconfig_2.0.3     
[55] MASS_7.3-58.1        Matrix_1.6-5         bridgesampling_1.1-2 R6_2.5.1             nlme_3.1-160         compiler_4.2.2 
strengejacke commented 2 months ago

Congratulation, issue 999 and PR 1000! 🎉

rbcavanaugh commented 2 months ago

Thanks for the quick fix!!