Reputation: 143
I have a Bayesian code for estimating a model (a bit complicated model) in RStan. After estimating the model I took 500 samples of parameter sets from the posterior distribution to simulate data from the model for future (next 1 month). Finally I took the means of the predicted values (500 predicted values for each time point) and then compared them with the actual observations (with a plot).
My question is- how can I calculate the intervals of these means of the predicted values?
Example: After drawing the sample of parameters from the posterior distribution, I simulated variables X1,X2,....X30 from the model using these parameters:
X1= (33,25,10,19,25)
X2= (11,10,15,13.5,17)
.......
X30= (40,33.3,50,29,45.1)
Now I find mean(X1); mean(X2);....mean(X30) and plot them against time. I want to find intervals for these means.
Upvotes: 1
Views: 77
Reputation: 3822
Example posterior draws for each X1 ... X30:
m <- matrix(data = rep(rnorm(500, 0, 1), 30), nrow = 500, ncol = 30, byrow = FALSE)
colnames(m) <- paste0("X", 1:30)
Get credible interval of these draws:
ci <- apply(m, 2, quantile, probs = c(0.1, 0.9))
colnames(ci) <- paste0("X", 1:30)
Upvotes: 3