1

I did write a basic GLM code in rstanarm. When I execute the following code it is giving the mean of the predictor variables of all the iterations done:

  summary(TestGLM) 
  print(TestGLM)  

I wanted the value of the predictor variables at each and every iteration for my solution. Can anyone please help me solve this problem?

lebelinoz
  • 4,890
  • 10
  • 33
  • 56
Alex_P
  • 133
  • 2
  • 9
  • Took a quick look in [the manual](https://cran.r-project.org/web/packages/rstanarm/rstanarm.pdf). Did you have any luck with `prior_summary` and `summary.stanreg`? If not I guess you can `str(TestGLM)` and poke around. – Eric Fail Oct 03 '17 at 14:09
  • @EricFail Thanks for your response. I can get the values using str(TestGLM) and also found ggmcmc(TestGLM) for getting the values. I was wondering what does posterior_predict(TestGLM) does as it also giving me the values. Please let me know if you have any idea regarding posterior_predict() – Alex_P Oct 03 '17 at 14:31
  • Have a look at page 23 in the rstanarm manual I linked above. – Eric Fail Oct 03 '17 at 15:07
  • @EricFail Thanks! – Alex_P Oct 03 '17 at 16:09

1 Answers1

3

You can extract the draws for each of the coefficients as follows:

require(rstanarm)

TestGLM <- stan_glm(mpg ~ wt, data = mtcars)
draws <- as.data.frame(TestGLM)
print(colnames(draws))
str(draws)

# See http://mc-stan.org/rstanarm/reference/as.matrix.stanreg.html
ssp3nc3r
  • 3,662
  • 2
  • 13
  • 23