tag:blogger.com,1999:blog-3240271627873788873.post4894276457609792112..comments2018-02-16T16:02:59.013-05:00Comments on Doing Bayesian Data Analysis: Posterior distribution of predictions in multiple linear regressionJohn K. Kruschkehttp://www.blogger.com/profile/17323153789716653784noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-3240271627873788873.post-42759887118481777072017-08-14T17:11:00.124-04:002017-08-14T17:11:00.124-04:00Thank you for your reply and suggestion! This has...Thank you for your reply and suggestion! This has put me on the right path to working out a solution, and has helped me to understand what's going on more generally when we find the posterior distribution of the predictive value.saira h.noreply@blogger.comtag:blogger.com,1999:blog-3240271627873788873.post-55258397586187186052017-08-13T12:58:56.900-04:002017-08-13T12:58:56.900-04:00At step s in the MCMC chain, use lambda[s] inside ...At step s in the MCMC chain, use lambda[s] inside rbinom() or rpois() to generate the predicted count. <br /><br />If the count probability is a weighted mixture of binom and pois, then choose the result of rbinom() or rpois() with that probability. For example, if it's 0.33 * binom + 0.67 * pois then let <br />w = runif(0,1) <br />and <br />if ( w <= 0.33 ) { y=rbinom(lambda[s]...) } else { y=rpois(lambda[s]...) }<br />John K. Kruschkehttps://www.blogger.com/profile/17323153789716653784noreply@blogger.comtag:blogger.com,1999:blog-3240271627873788873.post-4787655927895476992017-08-11T11:49:39.311-04:002017-08-11T11:49:39.311-04:00Thanks for posting this! It would be amazing to s...Thanks for posting this! It would be amazing to see an explanation of how to find the posterior distributions of predictions for a coupled model. I'm thinking of a zero-inflated Poisson where the zero-inflation is modeled by a binomial distribution. I'm stuck on how to simulate y when it's generated by multiplying lambda (which I can find by using the parameters at probed values of x) by the binomial variable, w[i], to get an effective lambda that models the Poisson count. That extra step, w[i], is throwing me off. <br /><br />I know I can't be the only person with this problem! <br /><br />Thanks for all your great work and for the great blog!saira h.noreply@blogger.comtag:blogger.com,1999:blog-3240271627873788873.post-76526054432625823872017-06-22T18:37:15.826-04:002017-06-22T18:37:15.826-04:00I just made another modification/correction to the...I just made another modification/correction to the originally posted code. The originally posted code had an error in the plotting at the end, in which the `main' argument referred to xProbe1, a variable that didn't exist. The code is now corrected so the plots display the x probe values for any number of predictors.John K. Kruschkehttps://www.blogger.com/profile/17323153789716653784noreply@blogger.comtag:blogger.com,1999:blog-3240271627873788873.post-54902767067123431702017-06-12T10:05:32.446-04:002017-06-12T10:05:32.446-04:00If you happened to view this post within its first...If you happened to view this post within its first day, you'll have seen R code that had a couple vestigial lines that only worked for TWO predictors instead of any number of predictors. I modified the code so it now works with any number of predictors. The updated lines are these:<br /><br />for ( xProbeIdx in 1:nrow(xProbe) ) {<br /><br /> # Predicted mu is b0+b1*x1+b2*x2+... at every step in chain:<br /><br /> muPred = ( mcmcMat[,grep("^beta",colnames(mcmcMat))]<br /><br /> %*% matrix(c(1,xProbe[xProbeIdx,]),ncol=1) )<br />John K. Kruschkehttps://www.blogger.com/profile/17323153789716653784noreply@blogger.com