the function fitted() or the alias posterior_epred() is not working it is giving this error “Error in .M.kind(x) : object ‘R_Matrix_kind’ not found”
even with the example in the function description.
If I run the model without the random effect the function works without an error.
What is the reason for that and how can I solve this?
I’m using the latest version of R and brms.
Thanks for any help.
There’s a chance someone will see the error message, know what it means, and be able to provide a solution. However, you’re more likely to get help if you provide additional contextual information. For starters, can you provide a minimal reproducible example of the code that results in this error message?
Thank you!
the example is exactly this one presented in the description of the function itself
library(“brms”)
fit <-brm(rating ~ treat + period + carry + (1|subject), data = inhaler)
fitted_values ← fitted(fit)
head(fitted_values)
without the random effect it works
fit <-brm(rating ~ treat + period + carry, data = inhaler)
fitted_values ← fitted(fit)
head(fitted_values)
After which line of code are you getting the error? I don’t get an error when I run that on my machine:
library(brms)
fit <- brm(rating ~ treat + period + carry + (1|subject), data = inhaler)
fitted_values <- fitted(fit)
head(fitted_values)
#> Estimate Est.Error Q2.5 Q97.5
#> [1,] 1.203668 0.2192853 0.7674990 1.616373
#> [2,] 1.200084 0.2180240 0.7573589 1.620979
#> [3,] 1.203559 0.2191030 0.7602297 1.620711
#> [4,] 1.203822 0.2156997 0.7632390 1.598625
#> [5,] 1.205378 0.2139372 0.7606742 1.614966
#> [6,] 1.202271 0.2096235 0.7674645 1.616006
Can you paste the complete output of sessionInfo()
here?
The error come after this line
fitted_values = fitted(fit)
Error in .M.kind(x) : object ‘R_Matrix_kind’ not found
This is the session info
sessionInfo()
R version 4.2.3 (2023-03-15 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=German_Germany.utf8 LC_CTYPE=German_Germany.utf8 LC_MONETARY=German_Germany.utf8 LC_NUMERIC=C
[5] LC_TIME=German_Germany.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] brms_2.19.0 Rcpp_1.0.10
loaded via a namespace (and not attached):
[1] nlme_3.1-162 matrixStats_0.63.0 xts_0.13.0 threejs_0.3.3 rstan_2.26.13 tensorA_0.36.2
[7] tools_4.2.3 backports_1.4.1 utf8_1.2.3 R6_2.5.1 DT_0.27 colorspace_2.1-0
[13] withr_2.5.0 tidyselect_1.2.0 gridExtra_2.3 prettyunits_1.1.1 processx_3.8.0 Brobdingnag_1.2-9
[19] emmeans_1.8.5 curl_5.0.0 compiler_4.2.3 cli_3.6.1 shinyjs_2.1.0 sandwich_3.0-2
[25] colourpicker_1.2.0 posterior_1.4.1 scales_1.2.1 dygraphs_1.1.1.6 checkmate_2.1.0 mvtnorm_1.1-3
[31] callr_3.7.3 stringr_1.5.0 digest_0.6.31 StanHeaders_2.26.13 base64enc_0.1-3 pkgconfig_2.0.3
[37] htmltools_0.5.5 fastmap_1.1.1 htmlwidgets_1.6.2 rlang_1.1.0 shiny_1.7.4 farver_2.1.1
[43] generics_0.1.3 zoo_1.8-11 jsonlite_1.8.4 crosstalk_1.2.0 gtools_3.9.4 dplyr_1.1.1
[49] distributional_0.3.2 inline_0.3.19 magrittr_2.0.3 loo_2.6.0 bayesplot_1.10.0 Matrix_1.5-4
[55] munsell_0.5.0 fansi_1.0.4 abind_1.4-5 lifecycle_1.0.3 stringi_1.7.12 multcomp_1.4-23
[61] MASS_7.3-58.3 pkgbuild_1.4.0 plyr_1.8.8 grid_4.2.3 parallel_4.2.3 promises_1.2.0.1
[67] crayon_1.5.2 miniUI_0.1.1.1 lattice_0.21-8 splines_4.2.3 ps_1.7.4 pillar_1.9.0
[73] igraph_1.4.2 markdown_1.6 estimability_1.4.1 shinystan_2.6.0 reshape2_1.4.4 codetools_0.2-19
[79] stats4_4.2.3 rstantools_2.3.1 glue_1.6.2 V8_4.2.2 RcppParallel_5.1.7 vctrs_0.6.1
[85] httpuv_1.6.9 gtable_0.3.3 ggplot2_3.4.2 mime_0.12 xtable_1.8-4 coda_0.19-4
[91] later_1.3.0 survival_3.5-5 tibble_3.2.1 shinythemes_1.2.0 TH.data_1.1-1 ellipsis_0.3.2
[97] bridgesampling_1.1-2
The error object ‘R_Matrix_kind’ not found
is related to the Matrix
package (since that’s where that object is defined). Your rstan
and StanHeaders
versions are also a little behind (the latest is 2.26.22).
Can you try reinstalling all three from source and checking whether the error is still present:
install.packages("Matrix", type="source")
install.packages(c("StanHeaders","rstan"),
repos = c("https://mc-stan.org/r-packages/", getOption("repos")),
type = "source")
Great! it is working!
Thank you all very much!