Short summary of the problem
similar to Error: Family 'cumulative' requires either positive integers or ordered factors as responses. · Issue #790 · paul-buerkner/brms · GitHub
f0=formula(Score ~ 1)
db=data.frame(Score=factor(rep(c(“Low”, “Medium”,“High”),10),
ordered=T, levels=c(“Low”, “Medium”,“High”)))
is.ordered(db$Score)
glimpse(db)
m0=brm(f0,data=db, family=cumulative(“logit”))
What am I missing?
Thanks
H
Error: Family ‘cumulative’ requires either positive integers or ordered factors as responses.
code_to_run_your_model(if_applicable)
If possible, add also code to simulate data or attach a (subset of) the dataset you work with.
Please also provide the following information in addition to your question:
Operating System:
brms Version:
Don’t forget to add relevant tags to your topic (top right of this form) especially for application area. Delete this text before posting your question :-) Thx!
Looking forward to your topic!
joels
March 15, 2023, 10:15pm
2
Your code runs without error for me with brms 2.18.8 and cmdstan 2.31.0. Here’s a reproducible example:
library(brms)
library(tidyverse)
f0 = formula(Score ~ 1)
db = data.frame(Score=factor(rep(c("Low", "Medium", "High"), 10),
ordered=T, levels=c("Low", "Medium","High")))
is.ordered(db$Score)
#> [1] TRUE
glimpse(db)
#> Rows: 30
#> Columns: 1
#> $ Score <ord> Low, Medium, High, Low, Medium, High, Low, Medium, High, Low, Me…
m0 = brm(f0, data=db, family=cumulative("logit"),
backend="cmdstanr", silent=2, refresh=0)
#> Running MCMC with 4 sequential chains...
#>
#> Chain 1 finished in 0.2 seconds.
#> Chain 2 finished in 0.2 seconds.
#> Chain 3 finished in 0.2 seconds.
#> Chain 4 finished in 0.2 seconds.
#>
#> All 4 chains finished successfully.
#> Mean chain execution time: 0.2 seconds.
#> Total execution time: 0.9 seconds.
m0
#> Family: cumulative
#> Links: mu = logit; disc = identity
#> Formula: Score ~ 1
#> Data: db (Number of observations: 30)
#> Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
#> total post-warmup draws = 4000
#>
#> Population-Level Effects:
#> Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#> Intercept[1] -0.73 0.40 -1.52 0.03 1.00 1647 2046
#> Intercept[2] 0.73 0.39 -0.02 1.52 1.00 3955 2804
#>
#> Family Specific Parameters:
#> Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#> disc 1.00 0.00 1.00 1.00 NA NA NA
#>
#> Draws were sampled using sample(hmc). For each parameter, Bulk_ESS
#> and Tail_ESS are effective sample size measures, and Rhat is the potential
#> scale reduction factor on split chains (at convergence, Rhat = 1).
sessionInfo()
#> R version 4.2.2 (2022-10-31)
#> Platform: aarch64-apple-darwin20 (64-bit)
#> Running under: macOS Ventura 13.2.1
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
#> 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 utils datasets methods base
#>
#> other attached packages:
#> [1] lubridate_1.9.2 forcats_1.0.0 stringr_1.5.0 dplyr_1.1.0.9000
#> [5] purrr_1.0.1 readr_2.1.4 tidyr_1.3.0 tibble_3.2.0
#> [9] ggplot2_3.4.1 tidyverse_2.0.0 brms_2.18.8 Rcpp_1.0.10
#>
#> loaded via a namespace (and not attached):
#> [1] minqa_1.2.5 TH.data_1.1-1 colorspace_2.1-0
#> [4] ellipsis_0.3.2 estimability_1.4.1 markdown_1.5
#> [7] base64enc_0.1-3 fs_1.6.1 rstudioapi_0.14
#> [10] farver_2.1.1 rstan_2.26.13 DT_0.27
#> [13] fansi_1.0.4 mvtnorm_1.1-3 bridgesampling_1.1-2
#> [16] codetools_0.2-18 splines_4.2.2 R.methodsS3_1.8.2
#> [19] knitr_1.42 shinythemes_1.2.0 bayesplot_1.10.0
#> [22] projpred_2.4.0 jsonlite_1.8.4 nloptr_2.0.3
#> [25] R.oo_1.25.0 shiny_1.7.4 compiler_4.2.2
#> [28] emmeans_1.8.5 backports_1.4.1 Matrix_1.5-3
#> [31] fastmap_1.1.1 cli_3.6.0 later_1.3.0
#> [34] htmltools_0.5.4 prettyunits_1.1.1 tools_4.2.2
#> [37] igraph_1.4.1 coda_0.19-4 gtable_0.3.1
#> [40] glue_1.6.2 reshape2_1.4.4 posterior_1.4.0
#> [43] V8_4.2.2 styler_1.9.1 vctrs_0.5.2.9000
#> [46] nlme_3.1-160 crosstalk_1.2.0 tensorA_0.36.2
#> [49] xfun_0.37 ps_1.7.2 lme4_1.1-31
#> [52] timechange_0.2.0 mime_0.12 miniUI_0.1.1.1
#> [55] lifecycle_1.0.3 gtools_3.9.4 MASS_7.3-58.1
#> [58] zoo_1.8-11 scales_1.2.1 colourpicker_1.2.0
#> [61] hms_1.1.2 promises_1.2.0.1 Brobdingnag_1.2-9
#> [64] parallel_4.2.2 sandwich_3.0-2 inline_0.3.19
#> [67] shinystan_2.6.0 gamm4_0.2-6 yaml_2.3.7
#> [70] curl_5.0.0 gridExtra_2.3 loo_2.5.1
#> [73] StanHeaders_2.26.13 stringi_1.7.12 dygraphs_1.1.1.6
#> [76] checkmate_2.1.0 boot_1.3-28 pkgbuild_1.4.0
#> [79] cmdstanr_0.5.2 rlang_1.1.0 pkgconfig_2.0.3
#> [82] matrixStats_0.63.0 distributional_0.3.1 evaluate_0.20
#> [85] lattice_0.20-45 rstantools_2.3.0 htmlwidgets_1.6.1
#> [88] processx_3.8.0 tidyselect_1.2.0 plyr_1.8.8
#> [91] magrittr_2.0.3 R6_2.5.1 generics_0.1.3
#> [94] multcomp_1.4-23 DBI_1.1.3 mgcv_1.8-41
#> [97] pillar_1.8.1 withr_2.5.0 xts_0.13.0
#> [100] survival_3.4-0 abind_1.4-5 crayon_1.5.2
#> [103] utf8_1.2.3 tzdb_0.3.0 rmarkdown_2.20
#> [106] grid_4.2.2 data.table_1.14.8 callr_3.7.3
#> [109] threejs_0.3.3 reprex_2.0.2 digest_0.6.31
#> [112] xtable_1.8-4 R.cache_0.16.0 httpuv_1.6.9
#> [115] R.utils_2.12.2 RcppParallel_5.1.7 stats4_4.2.2
#> [118] munsell_0.5.0 shinyjs_2.1.0
Created on 2023-03-15 with reprex v2.0.2
Thanks,
Yes interesting. After restart of Rstudio(2022.12.0 Build 353), the code runs for me again. R version 4.2.2 (2022-10-31 ucrt), rstan 2.26.1, 2.18.0.
I’ll update the packages…
H