Stan_aov in R....why doesn't it work?

I can’t get a simple ancova to run in rstanarm. I can get the bayesian linear model with dummy variables to work fine (which is supposed to be equivalent?) but not the ancova, and unfortunately that’s what my coauthors desire.

The error I get is the same as the one I get when I fit an ancova to the iris dataset, so I provide that for an example:

iris_data = iris                                 #  get iris data

summary(aov(Sepal.Length~Species+Sepal.Width, data=iris_data,)) # frequentist ancova

model = stan_aov(Sepal.Length~Species+Sepal.Width, data=iris_data, prior = R2(location = 0.7)) #Bayesian ancova does not work

I get the error: “Warning messages:
1: There were 6 divergent transitions after warmup. See
http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
to find out why this is a problem and how to eliminate them.
2: Examine the pairs() plot to diagnose sampling problems”

Adding more iterations (iter=4000) or changing step size (adapt_delta = 0.999) do not solve the problem.

  • Operating System: windows 10
  • rstanarm Version: 2.21.1

Hoping ya’ll can help!

Richie

Can you share the output from print(model)? We just fixed a bug in stan_aov() and maybe this is affected. Unfortunately the fix hasn’t made its way onto CRAN yet so you may need to install rstanarm from GitHub unfortunately.

@bgoodri Is installing rstanarm from source via GitHub working on Windows currently?

@Thomas_Richardson Can you try installing rstanarm from GitHub using code

# change 4 to however many cores you can/want to use 
Sys.setenv(MAKEFLAGS = "-j4") 
Sys.setenv("R_REMOTES_NO_ERRORS_FROM_WARNINGS" = "true")
remotes::install_github("stan-dev/rstanarm", INSTALL_opts = "--no-multiarch")

and then see if you can run stan_aov() successfully? Thanks!

image

And this is the summary()

I think in this case the warnings about divergences might be false positives. I went and looked at where the divergences are occurring (by making some plots like the ones in https://mc-stan.org/bayesplot/articles/visual-mcmc-diagnostics.html#mcmc_scatter) and they seem to not be clustered anywhere and could very well be false positives.

Also, to me it looks like results from stan_aov() for the iris data are pretty reasonable. The point estimates for Mean Sq Species and Mean Sq Sepal.Width (in “ANOVA-like table”) are pretty close to the estimates of those quantities from the frequentist version (that doesn’t have to be the case but it’s probably is a sign that nothing is too horribly wrong).

That said, we did fix a major bug in stan_aov() (https://github.com/stan-dev/rstanarm/issues/448) so if you haven’t already I do recommend trying the version from GitHub. To install that:

# unfortunately installing from github (as opposed to cran) it needs to compile everything
# so it's good to tell it to use multiple cores. change 4 here to however many cores you can/want to use
Sys.setenv(MAKEFLAGS = "-j4") 
Sys.setenv("R_REMOTES_NO_ERRORS_FROM_WARNINGS" = "true")
remotes::install_github("stan-dev/rstanarm", INSTALL_opts = "--no-multiarch")