I am confused as to how to minimize output from StanArm in an Rmarkdown file. I am using Regression and Other Stories to teach and reworking examples I have used in the past and ideally I want to not see all the output I see below. I did first search documentation before I posted here. I am a beginner using Stan_glm, (one could argue given my increased workload and family load given the pandemic this was not the time to learn while also teaching, but I was so excited about the new book I wanted to teach with it) . Thank you for your help. I wonder if there is something small I am missing about controlling output.
Student Only Model Using Stan GLM Defaults
lm_stan_default <- stan_glm(Balance ~ Student, data = Credit)
Hi @LauraK, good question! I think this is an example of missing information in our documentation. You should be able to set refresh=0 as an additional argument to avoid printing the iteration updates. Does that work for you?
I just opened an issue in the rstanarm github repository about this so that we remember to document it better going forward:
Yeah, I think that’s worth considering. Especially for models that run pretty quickly I think you’re right that it makes sense to suppress the iteration output by default. For slower models (and with MCMC there are lots of slower models unfortunately!) it’s nice to see updates so you can check the progress and know that it’s running and not just silently stuck. If the default is not to show the updates then I think what could end up happening a lot is that people with slow models would start running them and then wonder if it’s working properly (because it’s just silent but taking a long time), but they would need to cancel their progress and rerun their model in order to turn on the progress updates, which would be annoying. If we could automatically estimate how long a model would take to run then I guess we could have a default that depends on that, but that can be pretty hard. Anyway, I think there are arguments both ways. At a minimum it needs to be documented better, but we should also revisit the issue of what the default should be. Thanks a lot for the feedback, I really appreciate it!
I’m actually having the opposite issue. I would like to see the iteration updates but since updating R and rstanarm they have been supressed for me. When checking old and new rstanarm and rstan documentation and source code it appears there has been no change to the deafult. Or have I missed something? refresh = 0 should supress them and refresh = >0 should show them (or refresh = NULL). I have run the model with these options direct in the R console and through Rmarkdown in RStudio and still I see no iteration updates. Thanks in advance.
R Studio 1.3.1093
R 4.0.3 (2020-10-10)
Running under: macOS Catalina 10.15.6
Hey Rachel, you’re right and you didn’t miss anything. This is definitely strange! I have the same exact versions of everything as you do (except I have Catalina 10.15.7 instead of 10.15.6), and refresh works as expected for me.
In addition to checking the files @torkar asked about, can you try this (seems like a lot of steps but they’re super quick):
Close all R sessions you have open
Start a fresh R session in RStudio or in the terminal
Run remove.packages(c("rstanarm", "rstan")).
Run install.packages("rstanarm") and if it asks you if you want to install rstan from source say no
In RStudio (but not inside RMarkdown) or in the terminal try
fit <- stan_glm(mpg ~ wt, data = mtcars)
and let us know if you still don’t see any printed output.
Actually I think I figured out what’s going on. Right after I responded I realized I forgot to check my version of rstan. I currently have the development version (not the CRAN version) of rstan installed. The printed iteration updates from rstanarm are coming internally from rstan so it’s really the version of rstan that matter for this. I just switched back to the CRAN version of rstan as a test and now I’m seeing the same problem that you are with rstanarm in parallel.
So I think this should be fixed by the next release of rstan, although I’m still not sure what the actual cause of the problem is.
If you don’t want to wait until then (I don’t know when that will be yet but probably sometime this winter) then you can try installing the development version of rstan from github with
# install 'remotes' package first if necessary
remotes::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan")
Unfortunately, unlike installing the rstan binary from CRAN, installing rstan from source via github requires compiling the c++ code in rstan. If you don’t already have the c++ toolchain set up then you can use these instructions before trying to install rstan:
If you try that let us know if it solves the problem with rstanarm or if you run into trouble installing rstan.
Thanks @jonah I tried installing the development version of rstan but I’m having issues with the Rtools for Mac. I believe this may be because I don’t have full admin access on this laptop (university owned) and it’s preventing the software to run after installed. I was able to to install the development version of Rstan on my friend’s computer (but it’s with Linux) and everything worked fine, including the iteration updates.