Open marcdotson opened 2 years ago
Here's working code of a hierarchical linear model (HLM) that we can adapt as a first stab at making this work.
alpha
given that it is a function of the betas
?betas
to induce the desired prior on alpha
?We can do this analytically and using a prior predictive check.
@marcdotson can you look at line 52 in the new bscm-hierarchy Rmd file (bscm-hierarchy branch)? I am not sure if you want the betas created how I have them or how y_train is created with an error term variable and an equation. Maybe can you check the model file too? I just set the sd as a number, but I see you have a covariance matrix in your example, I think I only need that for a multivariate normal. Should beta be multivariate normal?
@morganbale if beta
is a vector and not a scalar, then yes, you'll need it to be distributed multivariate normal. I don't think there's a multivariate equivalent of rnorm()
, but I've used an rmvrnom()
from another package before. In the model you'll end up with covariance matrix as well.
That said, it might be a good idea to start simulating data using the Stan model. The blog post I shared above demonstrates how you can do that. It's basically a reshuffling of the actual Stan code file, so you don't have to specify the model in both R and Stan. It also means you get access to using LKJ priors for the required covariance matrix, which don't have an R implementation.
And it's fine to start with a multivariate normal initially. That'll be complicated enough as we build up the hierarchical model. And then we can worry about the horseshoe prior.
https://getyarn.io/yarn-clip/8cc13a57-1689-45bf-a36f-f81e6ff5069e
@marcdotson Ok I see what you mean. Following your blog post I have adjusted the code. I left beta as a vector of weights (one for each store/control), I wasn't sure that it made sense for beta to be a matrix since its just weights to create synthetic control. The theta (higher level) parameter is a vector of length K for each store attribute that would be included in Z.
When you get a chance, can you look through and see if everything looks okay?
It should be a simple HLM, but over what parameters given that
alpha
in the base model is a deterministic function of thebetas
.