Skip to content
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

Fix print() method for model_parameters.stanmvreg() #173

Closed
IndrajeetPatil opened this issue Dec 24, 2019 · 3 comments
Closed

Fix print() method for model_parameters.stanmvreg() #173

IndrajeetPatil opened this issue Dec 24, 2019 · 3 comments
Labels
Bug 🐛 Something isn't working

Comments

@IndrajeetPatil
Copy link
Member

# setup
set.seed(123)
library(rstanarm)
#> Loading required package: Rcpp
#> Registered S3 method overwritten by 'xts':
#>   method     from
#>   as.zoo.xts zoo
#> rstanarm (Version 2.19.2, packaged: 2019-10-01 20:20:33 UTC)
#> - Do not expect the default priors to remain the same in future rstanarm versions.
#> Thus, R scripts should specify priors explicitly, even if they are just the defaults.
#> - For execution on a local, multicore CPU with excess RAM we recommend calling
#> options(mc.cores = parallel::detectCores())
#> - bayesplot theme set to bayesplot::theme_default()
#>    * Does _not_ affect other ggplot2 plots
#>    * See ?bayesplot_theme_set for details on theme setting
pbcLong$ybern <- as.integer(pbcLong$logBili >= mean(pbcLong$logBili))

# model
mod <-
  rstanarm::stan_mvmer(
    formula = list(
      ybern ~ year + (1 | id),
      albumin ~ sex + year + (year | id)
    ),
    data = pbcLong,
    family = list(binomial, gaussian),
    chains = 1, cores = 1, seed = 12345, iter = 1000
  )
#> Fitting a multivariate glmer model.
#> 
#> Please note the warmup may be much slower than later iterations!
#> 
#> SAMPLING FOR MODEL 'mvmer' NOW (CHAIN 1).
#> Chain 1: 
#> Chain 1: Gradient evaluation took 0.001 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 10 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1: 
#> Chain 1: 
#> Chain 1: Iteration:   1 / 1000 [  0%]  (Warmup)
#> Chain 1: Iteration: 100 / 1000 [ 10%]  (Warmup)
#> Chain 1: Iteration: 200 / 1000 [ 20%]  (Warmup)
#> Chain 1: Iteration: 300 / 1000 [ 30%]  (Warmup)
#> Chain 1: Iteration: 400 / 1000 [ 40%]  (Warmup)
#> Chain 1: Iteration: 500 / 1000 [ 50%]  (Warmup)
#> Chain 1: Iteration: 501 / 1000 [ 50%]  (Sampling)
#> Chain 1: Iteration: 600 / 1000 [ 60%]  (Sampling)
#> Chain 1: Iteration: 700 / 1000 [ 70%]  (Sampling)
#> Chain 1: Iteration: 800 / 1000 [ 80%]  (Sampling)
#> Chain 1: Iteration: 900 / 1000 [ 90%]  (Sampling)
#> Chain 1: Iteration: 1000 / 1000 [100%]  (Sampling)
#> Chain 1: 
#> Chain 1:  Elapsed Time: 6.317 seconds (Warm-up)
#> Chain 1:                3.343 seconds (Sampling)
#> Chain 1:                9.66 seconds (Total)
#> Chain 1:
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> http://mc-stan.org/misc/warnings.html#bulk-ess

# summary
parameters::model_parameters(mod)
#> Error in if (insight::model_info(model)$is_bayesian) {: argument is of length zero

Created on 2019-12-24 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.6.1 (2019-07-05)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  ctype    English_United States.1252  
#>  tz       Europe/Berlin               
#>  date     2019-12-24                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package      * version    date       lib source                               
#>  assertthat     0.2.1      2019-03-21 [1] CRAN (R 3.6.0)                       
#>  backports      1.1.5      2019-10-02 [1] CRAN (R 3.6.1)                       
#>  base64enc      0.1-3      2015-07-28 [1] CRAN (R 3.5.0)                       
#>  bayesplot      1.7.1      2019-12-01 [1] CRAN (R 3.6.1)                       
#>  bayestestR     0.4.0      2019-10-20 [1] CRAN (R 3.6.1)                       
#>  boot           1.3-24     2019-12-20 [1] CRAN (R 3.6.1)                       
#>  callr          3.4.0      2019-12-09 [1] CRAN (R 3.6.1)                       
#>  cli            2.0.0.9000 2019-12-23 [1] Github (r-lib/cli@0293ae7)           
#>  codetools      0.2-16     2018-12-24 [1] CRAN (R 3.5.2)                       
#>  colorspace     1.4-1      2019-03-18 [1] CRAN (R 3.6.0)                       
#>  colourpicker   1.0        2017-09-27 [1] CRAN (R 3.5.1)                       
#>  crayon         1.3.4      2017-09-16 [1] CRAN (R 3.5.1)                       
#>  crosstalk      1.0.0      2016-12-21 [1] CRAN (R 3.5.1)                       
#>  desc           1.2.0      2019-11-11 [1] Github (r-lib/desc@61205f6)          
#>  devtools       2.2.1      2019-09-24 [1] CRAN (R 3.6.1)                       
#>  digest         0.6.23     2019-11-23 [1] CRAN (R 3.6.1)                       
#>  dplyr          0.8.3.9000 2019-10-10 [1] Github (tidyverse/dplyr@dcfc1d1)     
#>  DT             0.11       2019-12-19 [1] CRAN (R 3.6.1)                       
#>  dygraphs       1.1.1.6    2018-07-11 [1] CRAN (R 3.5.1)                       
#>  ellipsis       0.3.0      2019-09-20 [1] CRAN (R 3.6.1)                       
#>  evaluate       0.14       2019-05-28 [1] CRAN (R 3.6.0)                       
#>  fansi          0.4.0      2018-11-05 [1] Github (brodieG/fansi@ab11e9c)       
#>  fastmap        1.0.1      2019-10-08 [1] CRAN (R 3.6.1)                       
#>  fs             1.3.1      2019-05-06 [1] CRAN (R 3.6.0)                       
#>  ggplot2        3.2.1      2019-08-10 [1] CRAN (R 3.6.1)                       
#>  ggridges       0.5.1      2018-09-27 [1] CRAN (R 3.5.1)                       
#>  glue           1.3.1      2019-03-12 [1] CRAN (R 3.6.0)                       
#>  gridExtra      2.3        2017-09-09 [1] CRAN (R 3.5.1)                       
#>  gtable         0.3.0      2019-03-25 [1] CRAN (R 3.6.0)                       
#>  gtools         3.8.1      2018-06-26 [1] CRAN (R 3.5.0)                       
#>  highr          0.8        2019-03-20 [1] CRAN (R 3.6.0)                       
#>  htmltools      0.4.0      2019-10-04 [1] CRAN (R 3.6.1)                       
#>  htmlwidgets    1.5.1      2019-10-08 [1] CRAN (R 3.6.1)                       
#>  httpuv         1.5.2      2019-09-11 [1] CRAN (R 3.6.1)                       
#>  igraph         1.2.4.2    2019-11-27 [1] CRAN (R 3.6.1)                       
#>  inline         0.3.15     2018-05-18 [1] CRAN (R 3.5.1)                       
#>  insight        0.7.1.1    2019-12-24 [1] local                                
#>  knitr          1.26       2019-11-12 [1] CRAN (R 3.6.1)                       
#>  later          1.0.0      2019-10-04 [1] CRAN (R 3.6.1)                       
#>  lattice        0.20-38    2018-11-04 [2] CRAN (R 3.6.1)                       
#>  lazyeval       0.2.2      2019-03-15 [1] CRAN (R 3.6.0)                       
#>  lifecycle      0.1.0      2019-08-01 [1] CRAN (R 3.6.1)                       
#>  lme4           1.1-21     2019-03-05 [1] CRAN (R 3.6.0)                       
#>  loo            2.2.0      2019-12-19 [1] CRAN (R 3.6.1)                       
#>  magrittr       1.5        2014-11-22 [1] CRAN (R 3.5.1)                       
#>  markdown       1.1        2019-08-07 [1] CRAN (R 3.6.1)                       
#>  MASS           7.3-51.5   2019-12-20 [1] CRAN (R 3.6.1)                       
#>  Matrix         1.2-18     2019-11-27 [1] CRAN (R 3.6.1)                       
#>  matrixStats    0.55.0     2019-09-07 [1] CRAN (R 3.6.1)                       
#>  memoise        1.1.0      2017-04-21 [1] CRAN (R 3.6.0)                       
#>  mime           0.8        2019-12-19 [1] CRAN (R 3.6.1)                       
#>  miniUI         0.1.1.1    2018-05-18 [1] CRAN (R 3.5.1)                       
#>  minqa          1.2.4      2014-10-09 [1] CRAN (R 3.5.1)                       
#>  munsell        0.5.0      2018-06-12 [1] CRAN (R 3.5.1)                       
#>  nlme           3.1-140    2019-05-12 [2] CRAN (R 3.6.1)                       
#>  nloptr         1.2.1      2018-10-03 [1] CRAN (R 3.5.1)                       
#>  parameters     0.3.0.1    2019-12-24 [1] Github (easystats/parameters@78e4442)
#>  pillar         1.4.3      2019-12-20 [1] CRAN (R 3.6.1)                       
#>  pkgbuild       1.0.6      2019-10-09 [1] CRAN (R 3.6.1)                       
#>  pkgconfig      2.0.3      2019-09-22 [1] CRAN (R 3.6.1)                       
#>  pkgload        1.0.2      2018-10-29 [1] CRAN (R 3.6.0)                       
#>  plyr           1.8.5      2019-12-10 [1] CRAN (R 3.6.1)                       
#>  prettyunits    1.0.2      2015-07-13 [1] CRAN (R 3.5.1)                       
#>  processx       3.4.1      2019-07-18 [1] CRAN (R 3.6.1)                       
#>  promises       1.1.0      2019-10-04 [1] CRAN (R 3.6.1)                       
#>  ps             1.3.0      2018-12-21 [1] CRAN (R 3.6.0)                       
#>  purrr          0.3.3      2019-10-18 [1] CRAN (R 3.6.1)                       
#>  R6             2.4.1      2019-11-12 [1] CRAN (R 3.6.1)                       
#>  Rcpp         * 1.0.3      2019-11-08 [1] CRAN (R 3.6.1)                       
#>  remotes        2.1.0      2019-06-24 [1] CRAN (R 3.6.0)                       
#>  reshape2       1.4.3      2017-12-11 [1] CRAN (R 3.5.1)                       
#>  rlang          0.4.2      2019-11-23 [1] CRAN (R 3.6.1)                       
#>  rmarkdown      2.0        2019-12-12 [1] CRAN (R 3.6.1)                       
#>  rprojroot      1.3-2      2018-01-03 [1] CRAN (R 3.5.1)                       
#>  rsconnect      0.8.16     2019-12-13 [1] CRAN (R 3.6.1)                       
#>  rstan          2.19.2     2019-07-09 [1] CRAN (R 3.6.1)                       
#>  rstanarm     * 2.19.2     2019-10-03 [1] CRAN (R 3.6.1)                       
#>  rstantools     2.0.0      2019-09-15 [1] CRAN (R 3.6.1)                       
#>  scales         1.1.0      2019-11-18 [1] CRAN (R 3.6.1)                       
#>  sessioninfo    1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                       
#>  shiny          1.4.0      2019-10-10 [1] CRAN (R 3.6.1)                       
#>  shinyjs        1.0        2018-01-08 [1] CRAN (R 3.5.1)                       
#>  shinystan      2.5.0      2018-05-01 [1] CRAN (R 3.5.1)                       
#>  shinythemes    1.1.2      2018-11-06 [1] CRAN (R 3.6.0)                       
#>  StanHeaders    2.19.0     2019-09-07 [1] CRAN (R 3.6.1)                       
#>  stringi        1.4.3      2019-03-12 [1] CRAN (R 3.6.0)                       
#>  stringr        1.4.0      2019-02-10 [1] CRAN (R 3.6.0)                       
#>  survival       3.1-8      2019-12-03 [1] CRAN (R 3.6.1)                       
#>  testthat       2.3.1      2019-12-01 [1] CRAN (R 3.6.1)                       
#>  threejs        0.3.1      2017-08-13 [1] CRAN (R 3.5.1)                       
#>  tibble         2.1.3      2019-06-06 [1] CRAN (R 3.6.1)                       
#>  tidyselect     0.2.5      2018-10-11 [1] CRAN (R 3.5.1)                       
#>  usethis        1.5.1.9000 2019-12-12 [1] Github (r-lib/usethis@23dd62c)       
#>  withr          2.1.2      2018-03-15 [1] CRAN (R 3.5.1)                       
#>  xfun           0.11       2019-11-12 [1] CRAN (R 3.6.1)                       
#>  xtable         1.8-4      2019-04-21 [1] CRAN (R 3.5.3)                       
#>  xts            0.11-2     2018-11-05 [1] CRAN (R 3.6.0)                       
#>  yaml           2.2.0      2018-07-25 [1] CRAN (R 3.5.1)                       
#>  zoo            1.8-6      2019-05-28 [1] CRAN (R 3.6.0)                       
#> 
#> [1] C:/Users/inp099/Documents/R/win-library/3.6
#> [2] C:/Program Files/R/R-3.6.1/library

Trace

> traceback()
3: .extract_parameters_bayesian(model, centrality = centrality, 
       dispersion = dispersion, ci = ci, ci_method = ci_method, 
       test = test, rope_range = rope_range, rope_ci = rope_ci, 
       bf_prior = bf_prior, diagnostic = diagnostic, priors = priors, 
       iterations = iterations, effects = effects, ...)
2: model_parameters.stanreg(mod)
1: parameters::model_parameters(mod)
@IndrajeetPatil IndrajeetPatil added the Bug 🐛 Something isn't working label Dec 24, 2019
@strengejacke
Copy link
Member

most likely related to easystats/bayestestR#31.

strengejacke added a commit that referenced this issue Dec 26, 2019
@strengejacke strengejacke changed the title model_parameters fails with Bayesian multivariate glmer model Fix print() method for model_parameters.stanmvreg() Dec 26, 2019
@strengejacke
Copy link
Member

set.seed(123)
library(rstanarm)

pbcLong$ybern <- as.integer(pbcLong$logBili >= mean(pbcLong$logBili))

# model
mod <-
  rstanarm::stan_mvmer(
    formula = list(
      ybern ~ year + (1 | id),
      albumin ~ sex + year + (year | id)
    ),
    data = pbcLong,
    family = list(binomial, gaussian),
    chains = 1, cores = 1, seed = 12345, iter = 1000
  )

# summary
parameters::model_parameters(mod)
#> Parameter   | Median |    CI |         89% CI |     pd |  Rhat |  ESS |               Prior | Prior_Response
#> ------------------------------------------------------------------------------------------------------------
#>             |  -0.15 | 89.00 | [-1.99,  1.63] | 55.60% | 1.027 |   81 |           NA ( +- ) |               
#>             |   0.41 | 89.00 | [ 0.28,  0.56] |   100% | 0.998 | 1251 |           NA ( +- ) |               
#>             |   3.46 | 89.00 | [ 3.06,  3.79] |   100% | 1.018 |  142 |           NA ( +- ) |               
#>             |   0.07 | 89.00 | [-0.27,  0.45] | 62.60% | 1.005 |  214 |           NA ( +- ) |               
#>             |  -0.13 | 89.00 | [-0.16, -0.10] |   100% | 1.011 |  183 |           NA ( +- ) |               
#> (Intercept) |        |       |                |        |       |      | Normal (0 +- 10.00) |             y1
#> (Intercept) |        |       |                |        |       |      |  Normal (0 +- 0.70) |             y1
#> sexf        |        |       |                |        |       |      |  Normal (0 +- 1.39) |             y2
#> year        |        |       |                |        |       |      |  Normal (0 +- 5.57) |             y2
#> year        |        |       |                |        |       |      |  Normal (0 +- 0.39) |             y2

Created on 2019-12-26 by the reprex package (v0.3.0)

@strengejacke
Copy link
Member

# setup
set.seed(123)
library(rstanarm)
#> Loading required package: Rcpp
#> Registered S3 method overwritten by 'xts':
#>   method     from
#>   as.zoo.xts zoo
#> rstanarm (Version 2.19.2, packaged: 2019-10-01 20:20:33 UTC)
#> - Do not expect the default priors to remain the same in future rstanarm versions.
#> Thus, R scripts should specify priors explicitly, even if they are just the defaults.
#> - For execution on a local, multicore CPU with excess RAM we recommend calling
#> options(mc.cores = parallel::detectCores())
#> - bayesplot theme set to bayesplot::theme_default()
#>    * Does _not_ affect other ggplot2 plots
#>    * See ?bayesplot_theme_set for details on theme setting

pbcLong$ybern <- as.integer(pbcLong$logBili >= mean(pbcLong$logBili))

# model
mod <-
  rstanarm::stan_mvmer(
    formula = list(
      ybern ~ year + (1 | id),
      albumin ~ sex + year + (year | id)
    ),
    data = pbcLong,
    family = list(binomial, gaussian),
    chains = 1, cores = 1, seed = 12345, iter = 1000
  )
#> Fitting a multivariate glmer model.
#> 
#> Please note the warmup may be much slower than later iterations!
#> 
#> SAMPLING FOR MODEL 'mvmer' NOW (CHAIN 1).
#> Chain 1: 
#> Chain 1: Gradient evaluation took 0 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1: 
#> Chain 1: 
#> Chain 1: Iteration:   1 / 1000 [  0%]  (Warmup)
#> Chain 1: Iteration: 100 / 1000 [ 10%]  (Warmup)
#> Chain 1: Iteration: 200 / 1000 [ 20%]  (Warmup)
#> Chain 1: Iteration: 300 / 1000 [ 30%]  (Warmup)
#> Chain 1: Iteration: 400 / 1000 [ 40%]  (Warmup)
#> Chain 1: Iteration: 500 / 1000 [ 50%]  (Warmup)
#> Chain 1: Iteration: 501 / 1000 [ 50%]  (Sampling)
#> Chain 1: Iteration: 600 / 1000 [ 60%]  (Sampling)
#> Chain 1: Iteration: 700 / 1000 [ 70%]  (Sampling)
#> Chain 1: Iteration: 800 / 1000 [ 80%]  (Sampling)
#> Chain 1: Iteration: 900 / 1000 [ 90%]  (Sampling)
#> Chain 1: Iteration: 1000 / 1000 [100%]  (Sampling)
#> Chain 1: 
#> Chain 1:  Elapsed Time: 5.158 seconds (Warm-up)
#> Chain 1:                2.81 seconds (Sampling)
#> Chain 1:                7.968 seconds (Total)
#> Chain 1:
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> http://mc-stan.org/misc/warnings.html#bulk-ess

library(parameters)
model_parameters(mod)
#> # y1 response
#> 
#> Parameter   | Median |        89% CI |     pd |  Rhat |  ESS |               Prior
#> ----------------------------------------------------------------------------------
#> (Intercept) |  -0.15 | [-1.99, 1.63] | 55.60% | 1.027 |   81 | Normal (0 +- 10.00)
#> year        |   0.41 | [ 0.28, 0.56] |   100% | 0.998 | 1251 |  Normal (0 +- 0.70)
#> 
#> # y2 response
#> 
#> Parameter   | Median |         89% CI |     pd |  Rhat | ESS |              Prior
#> ---------------------------------------------------------------------------------
#> (Intercept) |   3.46 | [ 3.06,  3.79] |   100% | 1.018 | 142 | Normal (0 +- 5.57)
#> sexf        |   0.07 | [-0.27,  0.45] | 62.60% | 1.005 | 214 | Normal (0 +- 1.39)
#> year        |  -0.13 | [-0.16, -0.10] |   100% | 1.011 | 183 | Normal (0 +- 0.39)

Created on 2019-12-30 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants