Force latent value parameter to equal zero before time t_p in multivariate structural time series


#1

I want to specify a multivariate Bayesian structural time series model in Stan. Each time series corresponds to the sale of a particular product at time t at location l. Say some product was not available at any location before a certain time period t_p, but other products were. How would I specify a model to account for the fact that a product p was not available before t_p? Could I specify a conditional zero somehow in the transformed_parameter block (as Ben Goodrich recommends here) and then multiply the unknown parameter by that “transformed parameter” for times before t_p? Or does this somehow violate some fundamental laws of probability? Is there some better way to do this? Thanks.


#2

If you are interested in some parameters determining the sales of products, the time points before the product was available don’t provide any information. You simply need to not take the time points where the product was not available into account when computing the likelihood, e.g.:

model {
  for(p in 1:n_products) {
    for(t in time_first_available[p]:n_time) {
       sales_observed[p,t] ~ normal( sales_predicted_by_model[p,t], sigma);
    }
  }
}

As to your suggestion, I think (maybe someone more knowledgeable will correct me) that if you force zeroes in transformed parameters, your model might be wrong. Lets imagine that instead of the above, we run:

transformed parameters {
  ...
  for(p in 1:n_products) {
    for(t in 1:time_first_available[p]) {
       sales_predicted_by_model[p,t] = 0;
    }
  }
}

model {
  for(p in 1:n_products) {
    sales_observed[p] ~ normal(sales_predicted_by_model[p], sigma);
  }
}

The likelihood terms corresponding to the times before the product was available would have the same effect as having multiple statements of this form in the model block:

 0 ~ normal(0, sigma);

If sigma is fixed (a constant in code or given in data), this term is constant, has zero derivative wrt. parameters and will have no influence on inferences about your parameters. However, if sigma is a parameter (or a function of some parameters), these terms will not be constant, will have nonzero derivative and will push the model to favor smaller sigma than is justifiable by the data.

(not checked the codes actually compile, but I hope the intention is clear).


#3

This isn’t quite true the way it’s stated if those data points inform shared parameters in a hierarchical model (so depends on the model), but that’s just nitpicking. I agree that they shouldn’t directly enter the likelihood for that product.