# Using posterior predicted values in estimation in Stan

I have some data on prices that I would like to predict as a function of covariates. One of those covariates is the predicted rating of that item as estimated from totally separate item rating data. I would like to treat this covariate as an out-of-sample prediction. So I would load the separate price and ratings data in the data step, estimate the parameters of the rating distribution in the model step, and then estimate the parameters of the price model given a proposal from the posterior predictive distribution of ratings.

Is this possible in Stan? Thank you.

P.S. Let me know if you need more details to formulate an answer. I hope this is enough but maybe not.

• Without knowing too much about the details of the model, this sounds like a fairly straightforward regression. If so, then I recommend looking into the rstanarm package which has as a number of "built-in" models that use syntax you may be familiar with if you've ever used lme4. Posterior predictions are quite easy to obtain using this package and there is a growing body of documentation that is easy enough to run through. – Dalton Hance Jul 27 '16 at 15:23
• This is not a straightforward regression because one of the covariates does not have a fixed value. As I mentioned in the question, its value is estimated from separate data. – Brash Equilibrium Jul 27 '16 at 15:36
• Drawing a realization of a covariate from a distribution is technically not difficult. Estimating a model that treats an estimate of a covariate as if it were observed prevents the uncertainty in the estimate from propagating to the uncertainty about everything else. It would be better to do a bivariate likelihood. – Ben Goodrich Jul 27 '16 at 18:05

The above is not specific to Stan but you can perform the above steps in the generated quantities block of a Stan program utilizing the normal_rng function.