richarddmorey / BayesFactor

BayesFactor R package for Bayesian data analysis with common statistical models.
https://richarddmorey.github.io/BayesFactor/
131 stars 48 forks source link

`posterior()` fails with `invalid class "ddenseModelMatrix" object` error #169

Closed IndrajeetPatil closed 7 months ago

IndrajeetPatil commented 7 months ago
library(BayesFactor)
data(puzzles)
bf = lmBF(RT ~ shape + color + shape:color + ID, data=puzzles)
#> Error in validObject(.Object) : 
#>   invalid class "ddenseModelMatrix" object: superclass "xMatrix" not defined in the environment of the object's class
posterior(bf, iterations = 1000, progress = FALSE, columnFilter="^ID$")
#> Error in validObject(.Object): invalid class "ddenseModelMatrix" object: superclass "xMatrix" not defined in the environment of the object's class

Created on 2023-11-21 with reprex v2.0.2


Session info

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.2 (2023-10-31)
#>  os       macOS Sonoma 14.1.1
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/Stockholm
#>  date     2023-11-21
#>  pandoc   3.1.8 @ /usr/local/bin/ (via rmarkdown)
#>  quarto   1.4.504 @ /usr/local/bin/quarto
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package      * version    date (UTC) lib source
#>  BayesFactor  * 0.9.12-4.5 2023-09-21 [1] CRAN (R 4.3.1)
#>  cli            3.6.1.9000 2023-10-03 [1] local
#>  coda         * 0.19-4     2020-09-30 [1] CRAN (R 4.3.0)
#>  digest         0.6.33     2023-07-07 [1] CRAN (R 4.3.0)
#>  evaluate       0.23       2023-11-01 [1] CRAN (R 4.3.1)
#>  fastmap        1.1.1      2023-02-24 [1] CRAN (R 4.3.0)
#>  fs             1.6.3      2023-07-20 [1] CRAN (R 4.3.0)
#>  glue           1.6.2      2022-02-24 [1] CRAN (R 4.3.0)
#>  htmltools      0.5.7      2023-11-03 [1] RSPM (R 4.3.0)
#>  knitr          1.45       2023-10-30 [1] CRAN (R 4.3.1)
#>  lattice        0.22-5     2023-10-24 [1] RSPM (R 4.3.0)
#>  lifecycle      1.0.4      2023-11-07 [1] RSPM (R 4.3.0)
#>  magrittr       2.0.3      2022-03-30 [1] CRAN (R 4.3.0)
#>  Matrix       * 1.6-3      2023-11-14 [1] RSPM (R 4.3.0)
#>  MatrixModels   0.5-3      2023-11-06 [1] RSPM (R 4.3.0)
#>  mvtnorm        1.2-3      2023-08-25 [1] CRAN (R 4.3.0)
#>  pbapply        1.7-2      2023-06-27 [1] CRAN (R 4.3.0)
#>  purrr          1.0.2      2023-08-10 [1] CRAN (R 4.3.0)
#>  R.cache        0.16.0     2022-07-21 [1] CRAN (R 4.3.0)
#>  R.methodsS3    1.8.2      2022-06-13 [1] CRAN (R 4.3.0)
#>  R.oo           1.25.0     2022-06-12 [1] CRAN (R 4.3.0)
#>  R.utils        2.12.3     2023-11-18 [1] RSPM (R 4.3.0)
#>  Rcpp           1.0.11     2023-07-06 [1] CRAN (R 4.3.0)
#>  reprex         2.0.2      2022-08-17 [1] CRAN (R 4.3.0)
#>  rlang          1.1.2      2023-11-04 [1] RSPM (R 4.3.0)
#>  rmarkdown      2.25       2023-09-18 [1] CRAN (R 4.3.1)
#>  rstudioapi     0.15.0     2023-07-07 [1] CRAN (R 4.3.0)
#>  sessioninfo    1.2.2.9000 2023-11-03 [1] local
#>  stringi        1.8.1      2023-11-13 [1] RSPM (R 4.3.0)
#>  stringr        1.5.1      2023-11-14 [1] RSPM (R 4.3.0)
#>  styler         1.10.2     2023-10-05 [1] Github (r-lib/styler@12f7eb6)
#>  vctrs          0.6.4      2023-10-12 [1] CRAN (R 4.3.1)
#>  withr          2.5.2      2023-10-30 [1] CRAN (R 4.3.1)
#>  xfun           0.41       2023-11-01 [1] CRAN (R 4.3.1)
#>  yaml           2.3.7      2023-01-23 [1] CRAN (R 4.3.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
#>  * ── Packages attached to the search path.
#> 
#> ──────────────────────────────────────────────────────────────────────────────
IndrajeetPatil commented 7 months ago

I am wondering this is coming from updates to the {MatrixModels} package.

> traceback()
17: stop(msg, ": ", errors, domain = NA)
16: validObject(.Object)
15: .nextMethod(.Object = .Object, ... = ...)
14: callNextMethod()
13: initialize(value, ...)
12: initialize(value, ...)
11: new("ddenseModelMatrix", as(m, "generalMatrix"), assign = attr(m, 
        "assign"), contrasts = if (is.null(ctr <- attr(m, "contrasts"))) list() else ctr)
10: model.Matrix(formula(fmla), data = data, sparse = sparse)
9: oneDesignMatrix(trm, data = data, dataTypes = dataTypes, sparse = sparse)
8: FUN(X[[i]], ...)
7: lapply(trms, function(trm, data, dataTypes) {
       oneDesignMatrix(trm, data = data, dataTypes = dataTypes, 
           sparse = sparse)
   }, data = data, dataTypes = dataTypes)
6: fullDesignMatrix(formula, data, dataTypes)
5: nWayFormula(formula = formula, data = data, dataTypes = dataTypes, 
       rscaleFixed = rscaleFixed, rscaleRandom = rscaleRandom, rscaleEffects = rscaleEffects, 
       iterations = iterations, posterior = TRUE, ...)
4: posterior(model = model@numerator[[1]], data = model@data, iterations = iterations, 
       ...)
3: posterior(model = model@numerator[[1]], data = model@data, iterations = iterations, 
       ...)
2: posterior(bf, iterations = 1000, progress = FALSE, columnFilter = "^ID$")
1: posterior(bf, iterations = 1000, progress = FALSE, columnFilter = "^ID$")
richarddmorey commented 7 months ago

I can't replicate this. Here's my session info; do you see any obvious relevant differences?

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.2 (2023-10-31)
#>  os       macOS Sonoma 14.0
#>  system   aarch64, darwin20
#>  ui       RStudio
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/London
#>  date     2023-11-22
#>  rstudio  2023.06.1+524 Mountain Hydrangea (desktop)
#>  pandoc   3.1.3 @ /usr/local/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────
#>  ! package      * version    date (UTC) lib source
#>    BayesFactor  * 0.9.12-4.5 2023-09-21 [1] CRAN (R 4.3.1)
#>  P cli            3.6.1      2023-03-23 [?] CRAN (R 4.3.0)
#>  P coda         * 0.19-4     2020-09-30 [?] CRAN (R 4.3.0)
#>  P digest         0.6.33     2023-07-07 [?] CRAN (R 4.3.0)
#>  P evaluate       0.21       2023-05-05 [?] CRAN (R 4.3.0)
#>  P fastmap        1.1.1      2023-02-24 [?] CRAN (R 4.3.0)
#>  P glue           1.6.2      2022-02-24 [?] CRAN (R 4.3.0)
#>  P htmltools      0.5.5      2023-03-23 [?] CRAN (R 4.3.0)
#>  P knitr          1.44       2023-09-11 [?] CRAN (R 4.3.0)
#>  P lattice        0.21-8     2023-04-05 [?] CRAN (R 4.3.0)
#>  P lifecycle      1.0.3      2022-10-07 [?] CRAN (R 4.3.0)
#>  P magrittr       2.0.3      2022-03-30 [?] CRAN (R 4.3.0)
#>  P Matrix       * 1.6-3      2023-11-14 [?] CRAN (R 4.3.1)
#>  P MatrixModels   0.5-3      2023-11-06 [?] CRAN (R 4.3.1)
#>    mvtnorm        1.2-3      2023-08-25 [1] CRAN (R 4.3.0)
#>  P pbapply        1.7-2      2023-06-27 [?] CRAN (R 4.3.0)
#>  P Rcpp           1.0.11     2023-07-06 [?] CRAN (R 4.3.0)
#>    renv           1.0.1      2023-08-10 [1] CRAN (R 4.3.0)
#>  P rlang          1.1.1      2023-04-28 [?] CRAN (R 4.3.0)
#>  P rmarkdown      2.23       2023-07-01 [?] CRAN (R 4.3.0)
#>  P rstudioapi     0.15.0     2023-07-07 [?] CRAN (R 4.3.0)
#>  P sessioninfo    1.2.2      2021-12-06 [?] CRAN (R 4.3.0)
#>  P stringi        1.7.12     2023-01-11 [?] CRAN (R 4.3.0)
#>  P stringr        1.5.0      2022-12-02 [?] CRAN (R 4.3.0)
#>  P xfun           0.39       2023-04-20 [?] CRAN (R 4.3.0)
#>  P yaml           2.3.7      2023-01-23 [?] CRAN (R 4.3.0)
#> 
#>  [1] /Users/saprm3/Documents/GitHub/BayesFactor/renv/library/R-4.3/aarch64-apple-darwin20
#>  [2] /Users/saprm3/Library/Caches/org.R-project.R/R/renv/sandbox/R-4.3/aarch64-apple-darwin20/ac5c2659
#> 
#>  P ── Loaded and on-disk path mismatch.
#> 
#> ──────────────────────────────────────────────────────────────────────
IndrajeetPatil commented 7 months ago

I am not yet sure if it's relevant, but a few of your packages are not up-to-date with their CRAN versions. Maybe you can update your packages, refresh the R session, and try again and see if you can replicate this issue?

FWIW, I can also reproduce this issue on GitHub's machines in the context of my R package's unit tests.

richarddmorey commented 7 months ago

updated packages; still no error.

sessioninfo::session_info()
# ─ Session info ───────────────────────────────────────────────────────
# setting  value
# version  R version 4.3.2 (2023-10-31)
# os       macOS Sonoma 14.0
# system   aarch64, darwin20
# ui       RStudio
# language (EN)
# collate  en_US.UTF-8
# ctype    en_US.UTF-8
# tz       Europe/London
# date     2023-11-22
# rstudio  2023.06.1+524 Mountain Hydrangea (desktop)
# pandoc   3.1.3 @ /usr/local/bin/pandoc
# 
# ─ Packages ───────────────────────────────────────────────────────────
# ! package      * version    date (UTC) lib source
# BayesFactor  * 0.9.12-4.5 2023-09-21 [1] CRAN (R 4.3.1)
# P cli            3.6.1      2023-03-23 [?] CRAN (R 4.3.0)
# P coda         * 0.19-4     2020-09-30 [?] CRAN (R 4.3.0)
# P glue           1.6.2      2022-02-24 [?] CRAN (R 4.3.0)
# P lattice        0.22-5     2023-10-24 [?] CRAN (R 4.3.1)
# P lifecycle      1.0.4      2023-11-07 [?] CRAN (R 4.3.1)
# P magrittr       2.0.3      2022-03-30 [?] CRAN (R 4.3.0)
# P Matrix       * 1.6-3      2023-11-14 [?] CRAN (R 4.3.1)
# P MatrixModels   0.5-3      2023-11-06 [?] CRAN (R 4.3.1)
# mvtnorm        1.2-3      2023-08-25 [1] CRAN (R 4.3.0)
# P pbapply        1.7-2      2023-06-27 [?] CRAN (R 4.3.0)
# P Rcpp           1.0.11     2023-07-06 [?] CRAN (R 4.3.0)
# P renv           1.0.3      2023-09-19 [?] CRAN (R 4.3.1)
# P rlang          1.1.2      2023-11-04 [?] CRAN (R 4.3.1)
# P rstudioapi     0.15.0     2023-07-07 [?] CRAN (R 4.3.0)
# P sessioninfo    1.2.2      2021-12-06 [?] CRAN (R 4.3.0)
# P stringi        1.8.1      2023-11-13 [?] CRAN (R 4.3.1)
# P stringr        1.5.1      2023-11-14 [?] CRAN (R 4.3.1)
# P yaml           2.3.7      2023-01-23 [?] CRAN (R 4.3.0)
# 
# [1] /Users/saprm3/Documents/GitHub/BayesFactor/renv/library/R-4.3/aarch64-apple-darwin20
# [2] /Users/saprm3/Library/Caches/org.R-project.R/R/renv/sandbox/R-4.3/aarch64-apple-darwin20/ac5c2659
# 
# P ── Loaded and on-disk path mismatch.
# 
# ──────────────────────────────────────────────────────────────────────
strengejacke commented 7 months ago

For the record, here is what I get:

library(BayesFactor)
#> Loading required package: coda
#> Loading required package: Matrix
#> ************
#> Welcome to BayesFactor 0.9.12-4.5. If you have questions, please contact Richard Morey (richarddmorey@gmail.com).
#> 
#> Type BFManual() to open the manual.
#> ************
data(puzzles)
bf <- lmBF(RT ~ shape + color + shape:color + ID, data = puzzles)
#> Error in validObject(.Object) : 
#>   invalid class "ddenseModelMatrix" object: superclass "xMatrix" not defined in the environment of the object's class
posterior(bf, iterations = 1000, progress = FALSE, columnFilter = "^ID$")
#> Error in validObject(.Object): invalid class "ddenseModelMatrix" object: superclass "xMatrix" not defined in the environment of the object's class
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.2 (2023-10-31 ucrt)
#>  os       Windows 11 x64 (build 22631)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  German_Germany.utf8
#>  ctype    German_Germany.utf8
#>  tz       Europe/Berlin
#>  date     2023-11-22
#>  pandoc   3.1.1 @ C:/Users/DL/AppData/Local/Pandoc/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package      * version    date (UTC) lib source
#>  BayesFactor  * 0.9.12-4.5 2023-09-21 [1] CRAN (R 4.3.1)
#>  cli            3.6.1      2023-03-23 [1] CRAN (R 4.3.0)
#>  coda         * 0.19-4     2020-09-30 [1] CRAN (R 4.3.0)
#>  digest         0.6.33     2023-07-07 [1] CRAN (R 4.3.1)
#>  evaluate       0.23       2023-11-01 [1] CRAN (R 4.3.2)
#>  fastmap        1.1.1      2023-02-24 [1] CRAN (R 4.3.0)
#>  fs             1.6.3      2023-07-20 [1] CRAN (R 4.3.1)
#>  glue           1.6.2      2022-02-24 [1] CRAN (R 4.3.0)
#>  htmltools      0.5.7      2023-11-03 [1] CRAN (R 4.3.2)
#>  knitr          1.45       2023-10-30 [1] CRAN (R 4.3.1)
#>  lattice        0.22-5     2023-10-24 [1] CRAN (R 4.3.2)
#>  lifecycle      1.0.4      2023-11-07 [1] CRAN (R 4.3.2)
#>  magrittr       2.0.3      2022-03-30 [1] CRAN (R 4.3.0)
#>  Matrix       * 1.6-3      2023-11-14 [1] CRAN (R 4.3.2)
#>  MatrixModels   0.5-3      2023-11-06 [1] CRAN (R 4.3.2)
#>  mvtnorm        1.2-3      2023-08-25 [1] CRAN (R 4.3.1)
#>  pbapply        1.7-2      2023-06-27 [1] CRAN (R 4.3.1)
#>  purrr          1.0.2      2023-08-10 [1] CRAN (R 4.3.1)
#>  R.cache        0.16.0     2022-07-21 [1] CRAN (R 4.3.0)
#>  R.methodsS3    1.8.2      2022-06-13 [1] CRAN (R 4.3.0)
#>  R.oo           1.25.0     2022-06-12 [1] CRAN (R 4.3.0)
#>  R.utils        2.12.3     2023-11-18 [1] CRAN (R 4.3.2)
#>  Rcpp           1.0.11     2023-07-06 [1] CRAN (R 4.3.1)
#>  reprex         2.0.2      2022-08-17 [1] CRAN (R 4.3.0)
#>  rlang          1.1.2      2023-11-04 [1] CRAN (R 4.3.2)
#>  rmarkdown      2.25       2023-09-18 [1] CRAN (R 4.3.1)
#>  sessioninfo    1.2.2      2021-12-06 [1] CRAN (R 4.3.0)
#>  stringi        1.8.1      2023-11-13 [1] CRAN (R 4.3.2)
#>  stringr        1.5.1      2023-11-14 [1] CRAN (R 4.3.2)
#>  styler         1.10.2     2023-08-29 [1] CRAN (R 4.3.1)
#>  vctrs          0.6.4      2023-10-12 [1] CRAN (R 4.3.1)
#>  withr          2.5.2      2023-10-30 [1] CRAN (R 4.3.1)
#>  xfun           0.41       2023-11-01 [1] CRAN (R 4.3.2)
#>  yaml           2.3.7      2023-01-23 [1] CRAN (R 4.3.0)
#> 
#>  [1] C:/Users/DL/AppData/Local/R/win-library/4.3
#>  [2] C:/Program Files/R/R-4.3.2/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Created on 2023-11-22 with reprex v2.0.2

I can't see any version discrepancies, it's weird why there's no error for you, but for me, running the same example. CRAN checks seem to be OK, though I'm not sure how much test coverage your package has.

IndrajeetPatil commented 7 months ago

@richarddmorey Is it possible that you are running the example inside a renv project, and it's using cached, older versions of packages that is leading to different results?

Do you see the same behaviour if you run the example above outside renv project with up-to-date packages?

richarddmorey commented 7 months ago

@richarddmorey Is it possible that you are running the example inside a renv project, and it's using cached, older versions of packages that is leading to different results?

Do you see the same behaviour if you run the example above outside renv project with up-to-date packages?

Could be, though I would have thought update.packages() should have fixed that. I'll try and get back to you.

richarddmorey commented 7 months ago

Re-ran without renv, still no error (session info below). It is interesting that it happens on GitHub machines - that's linux, right? So it is a cross platform issue?

sessioninfo::session_info()
# ─ Session info ───────────────────────────────────────────────────────
# setting  value
# version  R version 4.3.2 (2023-10-31)
# os       macOS Sonoma 14.0
# system   aarch64, darwin20
# ui       RStudio
# language (EN)
# collate  en_US.UTF-8
# ctype    en_US.UTF-8
# tz       Europe/London
# date     2023-11-22
# rstudio  2023.06.1+524 Mountain Hydrangea (desktop)
# pandoc   3.1.3 @ /usr/local/bin/pandoc
# 
# ─ Packages ───────────────────────────────────────────────────────────
# package      * version    date (UTC) lib source
# BayesFactor  * 0.9.12-4.5 2023-09-21 [1] CRAN (R 4.3.1)
# cli            3.6.1      2023-03-23 [2] CRAN (R 4.3.0)
# coda         * 0.19-4     2020-09-30 [1] CRAN (R 4.3.0)
# glue           1.6.2      2022-02-24 [2] CRAN (R 4.3.0)
# lattice        0.22-5     2023-10-24 [2] CRAN (R 4.3.1)
# lifecycle      1.0.4      2023-11-07 [2] CRAN (R 4.3.1)
# magrittr       2.0.3      2022-03-30 [2] CRAN (R 4.3.0)
# Matrix       * 1.6-3      2023-11-14 [1] CRAN (R 4.3.1)
# MatrixModels   0.5-3      2023-11-06 [1] CRAN (R 4.3.1)
# mvtnorm        1.2-3      2023-08-25 [1] CRAN (R 4.3.0)
# pbapply        1.7-2      2023-06-27 [1] CRAN (R 4.3.0)
# Rcpp           1.0.11     2023-07-06 [1] CRAN (R 4.3.0)
# rlang          1.1.2      2023-11-04 [2] CRAN (R 4.3.1)
# rstudioapi     0.15.0     2023-07-07 [1] CRAN (R 4.3.0)
# sessioninfo    1.2.2      2021-12-06 [1] CRAN (R 4.3.0)
# stringi        1.8.1      2023-11-13 [2] CRAN (R 4.3.1)
# stringr        1.5.1      2023-11-14 [2] CRAN (R 4.3.1)
# 
# [1] /Users/saprm3/Library/R/arm64/4.3/library
# [2] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
# 
# ──────────────────────────────────────────────────────────────────────
strengejacke commented 7 months ago

@IndrajeetPatil checked on Mac OS X, I checked on Windows 11. And GitHub installs all three OSes. Not sure what's going on here, still strange that you cannot reproduce the issue?

richarddmorey commented 7 months ago

Yes, quite strange. I just tried in a fresh posit cloud project, and still no error (session info below). Can you try on a fresh posit cloud instance?

[Edit: just noticed that Matrix is quite old on the posit cloud instance!]

sessioninfo::session_info()
# ─ Session info ────────────────────────────────────────────────────────────────────────────────────────
# setting  value
# version  R version 4.3.2 (2023-10-31)
# os       Ubuntu 20.04.6 LTS
# system   x86_64, linux-gnu
# ui       RStudio
# language (EN)
# collate  C.UTF-8
# ctype    C.UTF-8
# tz       UTC
# date     2023-11-22
# rstudio  2023.09.1+494.pro2 Desert Sunflower (server)
# pandoc   NA
# 
# ─ Packages ────────────────────────────────────────────────────────────────────────────────────────────
# package      * version    date (UTC) lib source
# BayesFactor  * 0.9.12-4.5 2023-09-21 [1] RSPM (R 4.3.0)
# cli            3.6.1      2023-03-23 [1] RSPM (R 4.3.0)
# coda         * 0.19-4     2020-09-30 [1] RSPM (R 4.3.0)
# glue           1.6.2      2022-02-24 [1] RSPM (R 4.3.0)
# lattice        0.21-9     2023-10-01 [2] CRAN (R 4.3.2)
# lifecycle      1.0.4      2023-11-07 [1] RSPM (R 4.3.0)
# magrittr       2.0.3      2022-03-30 [1] RSPM (R 4.3.0)
# Matrix       * 1.6-1.1    2023-09-18 [2] CRAN (R 4.3.2)
# MatrixModels   0.5-3      2023-11-06 [1] RSPM (R 4.3.0)
# mvtnorm        1.2-3      2023-08-25 [1] RSPM (R 4.3.0)
# pbapply        1.7-2      2023-06-27 [1] RSPM (R 4.3.0)
# Rcpp           1.0.11     2023-07-06 [1] RSPM (R 4.3.0)
# rlang          1.1.2      2023-11-04 [1] RSPM (R 4.3.0)
# sessioninfo    1.2.2      2021-12-06 [1] RSPM (R 4.3.0)
# stringi        1.8.1      2023-11-13 [1] RSPM (R 4.3.0)
# stringr        1.5.1      2023-11-14 [1] RSPM (R 4.3.0)
# 
# [1] /cloud/lib/x86_64-pc-linux-gnu-library/4.3
# [2] /opt/R/4.3.2/lib/R/library
# 
# ───────────────────────────────────────────────────────────────────────────────────────────────────────
richarddmorey commented 7 months ago

Got it! Updating packages on posit cloud updated the following packages, and I reproduced the error. This seems to narrow things down a bit?

update.packages()
# lattice :
#  Version 0.21-9 installed in /opt/R/4.3.2/lib/R/library 
#  Version 0.22-5 available at http://rspm/default/__linux__/focal/latest
# Update? (Yes/no/cancel) Yes
# Matrix :
#  Version 1.6-1.1 installed in /opt/R/4.3.2/lib/R/library 
#  Version 1.6-3 available at http://rspm/default/__linux__/focal/latest
# Update? (Yes/no/cancel) Yes

New session info:

sessioninfo::session_info()
# ─ Session info ────────────────────────────────────────────────────────────────────────────────────────
# setting  value
# version  R version 4.3.2 (2023-10-31)
# os       Ubuntu 20.04.6 LTS
# system   x86_64, linux-gnu
# ui       RStudio
# language (EN)
# collate  C.UTF-8
# ctype    C.UTF-8
# tz       UTC
# date     2023-11-22
# rstudio  2023.09.1+494.pro2 Desert Sunflower (server)
# pandoc   NA
# 
# ─ Packages ────────────────────────────────────────────────────────────────────────────────────────────
# package      * version    date (UTC) lib source
# BayesFactor  * 0.9.12-4.5 2023-09-21 [1] RSPM (R 4.3.0)
# cli            3.6.1      2023-03-23 [1] RSPM (R 4.3.0)
# coda         * 0.19-4     2020-09-30 [1] RSPM (R 4.3.0)
# glue           1.6.2      2022-02-24 [1] RSPM (R 4.3.0)
# lattice        0.22-5     2023-10-24 [1] RSPM (R 4.3.0)
# lifecycle      1.0.4      2023-11-07 [1] RSPM (R 4.3.0)
# magrittr       2.0.3      2022-03-30 [1] RSPM (R 4.3.0)
# Matrix       * 1.6-3      2023-11-14 [1] RSPM (R 4.3.0)
# MatrixModels   0.5-3      2023-11-06 [1] RSPM (R 4.3.0)
# mvtnorm        1.2-3      2023-08-25 [1] RSPM (R 4.3.0)
# pbapply        1.7-2      2023-06-27 [1] RSPM (R 4.3.0)
# Rcpp           1.0.11     2023-07-06 [1] RSPM (R 4.3.0)
# rlang          1.1.2      2023-11-04 [1] RSPM (R 4.3.0)
# sessioninfo    1.2.2      2021-12-06 [1] RSPM (R 4.3.0)
# stringi        1.8.1      2023-11-13 [1] RSPM (R 4.3.0)
# stringr        1.5.1      2023-11-14 [1] RSPM (R 4.3.0)
# 
# [1] /cloud/lib/x86_64-pc-linux-gnu-library/4.3
# [2] /opt/R/4.3.2/lib/R/library
# 
# ───────────────────────────────────────────────────────────────────────────────────────────────────────
strengejacke commented 7 months ago

That makes sense - it seems that errors started occuring after Matrix was updated on CRAN.

richarddmorey commented 7 months ago

What's strange is that I'm not seeing it on my Mac, which seems to have the most recent Matrix.

IndrajeetPatil commented 7 months ago

What's strange is that I'm not seeing it on my Mac, which seems to have the most recent Matrix.

That is indeed strange because I am also on macOS and I can reproduce this issue! Daniel can do so on Windows, and GitHub Ubuntu machines can also reproduce this issue.

richarddmorey commented 7 months ago

For reference, this code seems to generate the error, irrespective of {BayesFactor}:

df = structure(list(RT = c(4, 2, 1, 2, 3, 2, -4, 1, -2, 2, 1, 0, 3, 
                      1, 2, 0, 4, -1, -1, 0, -3, 0, 0, -5, 4, 1, 2, 0, 4, 0, -4, -2, 
                      -1, 1, 0, -5, 0, -2, -1, 0, 3, 1, -5, 0, -5, 0, 2, -5), ID = structure(c(1L, 
                                                                                               2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 
                                                                                               5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 
                                                                                               8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 
                                                                                               11L, 12L), levels = c("1", "2", "3", "4", "5", "6", "7", "8", 
                                                                                                                     "9", "10", "11", "12"), class = "factor"), shape = structure(c(1L, 
                                                                                                                                                                                    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
                                                                                                                                                                                    2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                                                                                                                                                                    1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), levels = c("round", 
                                                                                                                                                                                                                                                            "square"), class = "factor"), color = structure(c(2L, 2L, 2L, 
                                                                                                                                                                                                                                                                                                              2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
                                                                                                                                                                                                                                                                                                              2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                                                                                                                                                                                                                                                                                              1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), levels = c("color", 
                                                                                                                                                                                                                                                                                                                                                                              "monochromatic"), class = "factor")), class = "data.frame", row.names = c(NA, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                        -48L))

X0 = MatrixModels::model.Matrix( ~ shape - 1, data = df, sparse = FALSE)

But this code works:

X1 = model.matrix(~ shape - 1, data = df)

and they should yield the same design matrix (and they do in cases where I don't see the error). So this is either an issue with {Matrix} or {MatrixModels}.

IndrajeetPatil commented 7 months ago

@richarddmorey Thanks for tracing the source of the problem!

Would you be open to writing to Martin (maechler@stat.math.ethz.ch) to explain the issue and checking if this can be fixed upstream? IINM, he maintains both of these packages.

richarddmorey commented 7 months ago

Did you see these:

(This may explain why it is not reproducible on my system)

IndrajeetPatil commented 7 months ago
library(BayesFactor)
#> Loading required package: coda
#> Loading required package: Matrix
#> ************
#> Welcome to BayesFactor 0.9.12-4.5. If you have questions, please contact Richard Morey (richarddmorey@gmail.com).
#> 
#> Type BFManual() to open the manual.
#> ************
data(puzzles)
bf = lmBF(RT ~ shape + color + shape:color + ID, data=puzzles)
invisible(posterior(bf, iterations = 1000, progress = FALSE, columnFilter="^ID$"))

Created on 2023-11-23 with reprex v2.0.2

IndrajeetPatil commented 7 months ago

Thanks for sending these resources! After compiling {MatrixModels} from source, the issue is resolved! 🥳