Thursday, September 1, 2016

What are covariance matrices anyway? An introduction modeling with the multivariate normal distribution

2 comments:

  1. Thank you for this tutorial. I found it very helpful! One question: How would you compute predicted values for employment and GDP growth from the multivariate normal model in the generated quantities block?

    ReplyDelete
    Replies
    1. Just discovered this helpful post, thank you OP. This reply is belated, but here below is how one would compute predicted values within the generated quantities block. The trick is in the to_row_vector(x) function which converts x so that it will fit into a T x P matrix container:

      generated quantities {
      matrix[T, P] y_pred;
      for (t in 1:T) {
      y_pred[t] = to_row_vector(multi_normal_rng(mu, quad_form_diag(Omega, tau)));
      }

      But really, the T-different rows of predicted values aren't very interesting in this particular example. Each row of GDP and employment prediction is a draw from the same identical distribution. In this model, mu (and also omega and tau) aren't conditional on time or any other predictors. You could get the same TxP predicted values working with the "multi_normal_model" object outside of Stan entirely.

      Delete