Closed sadatnfs closed 6 years ago
Hey Nafis!
Sorry I'm so late replying, hectic days with travel and all.
I'm not sure I quite understand the model. From the way you've generated the data, there's no correlation in the Ys except that due to their shared relationships with the Xs.
So defining the independent distributions over Y_xg should be all you need to do. As it's currently written, the last section of code is an unconnected model, that should just be sampling from its prior.
If the model you want is the one you're sampling from, then you're already there. If you wanted additional correlations in the Ys on top of what you are simulating, you would want to do something like:
mu <- cbind(Y1_LL, Y2_LL, Y2_LL)
distribution(Y_all) <- multivariate_normal(mu, Sigma)
Thanks Nick! Ultimately, when I fit my model on real data, I'd want to run the model with some latent correlation/covariance in the Ys (I think I just didn't do a good job of simulating data with correlated Ys !).
I just realized that you replied to me as I was writing this reply, that's pretty much what I'd want!
Question on that: it looks like mu
's dimension is N x 3 for N = nrow(Y)
, but I'm getting this error:
distribution(Y_all) <- multivariate_normal(mu, Sigma)
Error: mean must be a 2D greta array with one column, but has dimensions 2500 x 3
where I evaluated Sigma
as in the code (3x3). Any thoughts?
Aah that's right, because I haven't yet resolved #123, the current implementation expects all the rows to have the same mean vector. You could loop through the rows defining the distribution for each row as a multivariate normal with mu = mu[i,]
as a stopgap.
I'll try to prioritise that fix though.
Awesome that's what I was thinking as well, but just didn't know if it was kosher. Thanks Nick!
Alas, it's giving this weird issue:
Y_all <- as_data(t(cbind(Y_1, Y_2, Y_3)))
mu <- t(cbind(Y1_LL, Y2_LL, Y2_LL))
for(i in 1:nrow(mu)) {
distribution(Y_all[i,]) <- multivariate_normal(mu[,i], Sigma)
}
Error: distributions can only be assigned to data greta arrays
I had to do the double transpose to make multivariate_normal
play well with the dimensionality.
I think it might be best if I hold off until #123 ends up getting resolved eh?
Yeah, the reason you're getting that is that extracting with [
is technically an operation, and greta won't let you define distribution on operation greta arrays, because it's very rare that that is a sensible thing to do.
You can do this:
Y_all <- cbind(Y_1, Y_2, Y_3)
mu <- cbind(Y1_LL, Y2_LL, Y3_LL)
t_mu <- t(mu)
for (i in seq_len(N)) {
Y_all_i <- t(Y_all[i, ])
distribution(Y_all_i) <- multivariate_normal(t_mu[, i], Sigma)
}
Though actually it will take a very long time to define the model, because of the for loop. So yes, it would probably be worth waiting if you can!
Hi Nick
I'd like to model a system of equations for 3 outputs (call them Y1, Y2, Y3), such that they are each influenced by some fixed effects (call them X1, X2, X3), and there exists some correlation between the 3 outputs in some 3x3 matrix structure. Here's my attempt at simulating and setting up the Greta model, but I feel like the correlation structure and multivariate distributions aren't correct. I looked at the issue in #131 but I think that's more for an intertwined network rather than correlated equations eh?
Here's my code. It'd be awesome I could get some feedback! Thanks!
Nafis