marcdotson / category-captainship

An empirical generalization of the category captainship paper.
MIT License
1 stars 1 forks source link

Construct a hierarchical Bayesian synthetic control model #80

Open marcdotson opened 2 years ago

marcdotson commented 2 years ago

It should be a simple HLM, but over what parameters given that alpha in the base model is a deterministic function of the betas.

marcdotson commented 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.

  1. What is the implied prior on alpha given that it is a function of the betas?
  2. What prior do you specify on the betas to induce the desired prior on alpha?

We can do this analytically and using a prior predictive check.

morganbale commented 2 years ago

@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?

marcdotson commented 2 years ago

@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

morganbale commented 2 years ago

@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?