stan-dev / rstanarm

rstanarm R package for Bayesian applied regression modeling
https://mc-stan.org/rstanarm
GNU General Public License v3.0
388 stars 133 forks source link

`stan_biglm` requires biglm package to be imported and loaded #484

Closed ebrown996 closed 4 years ago

ebrown996 commented 4 years ago

If biglm is not loaded and you try to run stan_biglm an error occurs stemming from the fact that it uses the function coef.

set.seed(123)

biglm <- biglm::biglm(formula = Ozone ~ Solar.R + Wind + Temp + Month + Day,
                   data = airquality)
not_NA <- !is.na(fitted(biglm))
  xbar <- colMeans(airquality[not_NA, c("Solar.R", "Wind", "Temp", "Month", "Day")])
  y <- airquality$Ozone[not_NA]
  ybar <- mean(y, na.rm = TRUE)
  s_y <- sd(y)

  model <- stan_biglm(biglm = biglm, xbar = xbar, ybar = ybar,
                      s_y = s_y, chains = 1, iter = 400)
Error in backsolve(R, diag(K)) : invalid 'k' argument

After debugging, found that it is likely that the issue is when we use the coef function in the code for stan_biglm. This seems to work fine when biglm is loaded as it will run biglm::coef.biglm instead and therefore we can suggest the fix that coef is replaced with biglm::coef.biglm and the biglm package is added to the suggests.

Version number 2.19.3

ebrown996 commented 4 years ago

Session information:

R version 3.6.3 (2020-02-29)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS:   /usr/lib64/libblas.so.3.4.2
LAPACK: /opt/mango/R/3.6.3/lib/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] rstanarm_2.19.3   Rcpp_1.0.3        testthat_2.3.2    silver_0.2.7.9001

loaded via a namespace (and not attached):
 [1] splines_3.6.3      gtools_3.8.1       StanHeaders_2.19.2 threejs_0.3.3
 [5] shiny_1.4.0        assertthat_0.2.1   stats4_3.6.3       pillar_1.4.3
 [9] lattice_0.20-40    glue_1.3.1         digest_0.6.25      promises_1.1.0
[13] minqa_1.2.4        colorspace_1.4-1   htmltools_0.4.0    httpuv_1.5.2
[17] Matrix_1.2-18      plyr_1.8.6         dygraphs_1.1.1.6   pkgconfig_2.0.3
[21] rstan_2.19.3       purrr_0.3.3        xtable_1.8-4       scales_1.1.0
[25] processx_3.4.2     later_1.0.0        lme4_1.1-21        tibble_2.1.3
[29] bayesplot_1.7.1    ggplot2_3.3.0      DT_0.12            withr_2.1.2
[33] shinyjs_1.1        cli_2.0.2          survival_3.1-11    magrittr_1.5
[37] crayon_1.3.4       mime_0.9           ps_1.3.2           fansi_0.4.1
[41] nlme_3.1-145       MASS_7.3-51.5      xts_0.12-0         pkgbuild_1.0.6
[45] colourpicker_1.0   rsconnect_0.8.16   tools_3.6.3        loo_2.2.0
[49] prettyunits_1.1.1  lifecycle_0.2.0    matrixStats_0.55.0 stringr_1.4.0
[53] munsell_0.5.0      callr_3.4.2        compiler_3.6.3     rlang_0.4.5
[57] nloptr_1.2.2       grid_3.6.3         ggridges_0.5.2     htmlwidgets_1.5.1
[61] crosstalk_1.0.0    igraph_1.2.4.2     miniUI_0.1.1.1     base64enc_0.1-3
[65] boot_1.3-24        codetools_0.2-16   gtable_0.3.0       inline_0.3.15
[69] markdown_1.1       reshape2_1.4.3     R6_2.4.1           gridExtra_2.3
[73] rstantools_2.0.0   zoo_1.8-7          dplyr_0.8.5        fastmap_1.0.1
[77] shinystan_2.5.0    shinythemes_1.1.2  stringi_1.4.6      parallel_3.6.3
[81] tidyselect_1.0.0
bgoodri commented 4 years ago

Thanks. That sounds like it may have been a recent change in the biglm package. I fixed it in e3f45fa.

ebrown996 commented 4 years ago

Thank you for your quick response. Apologies I wrote biglm::coef.biglm when it should be biglm:::coef.biglm. Also I think it would be good to add the biglm package to the suggests if you think appropriate.

gcaligari commented 3 years ago

Hi, first of all thank you for the package.

I have encountered the same issue as detailed above. I have seen that you had implemented the fix; https://github.com/stan-dev/rstanarm/commit/e3f45fac8d1b79b0c4a8734f04c80aee4322469d, and that it has been reverted back to b <- coef(biglm) since. As with the previous comment I feel that the required solution for this issue is to make use of biglm:::coef instead of coef, and that the previous attempted fix was unsuccessful as it made use of biglm::coef when coef.biglm is an internal function of biglm.

Thanks in advance, Giulia