I would appreciate any help to specify my brms model below in order to be able to pass multiple columns of weights to the model as illustrated in the stan code below.
I need to do this in brms or stanarm rather than stan directly because I want to use functions of https://github.com/mjskay/tidybayes that are currently not supported by a stanfit object.
//this is what I want the brms model specification to be able to do
data {
...
real<lower=0> weights[N, 10]; // data block of model weights
}
model {
...
// likelihood
for (n in 1:N)
for (w in 1:10) {
target += weights[n, w] * binomial_logit_lpmf(Y[n] | trials[n], mu[n]);
}
}
This question has also been posted here. Thanks in advance for any help.
Please avoid openening multiple threats for the same issue just because you don’t immediately receive an answer. Neither brms nor rstanarm support multi column weights and I don’t really see the purpose of that.
I don’t understand why you are doing this, but unless I’m misunderstanding completely you could perhaps flatten your dataframe into something with n*w rows and a single weights column.
Thanks, @mjskay, for this very helpful insight. I am doing this to account for Uncertainty in the Design Stage.
If I am understanding correctly your explanation, the solution to my problem would be to change the structure of the weights from wide to long format with this:
Assuming I am getting it right, how would I then account in my brms or rstanarm model for the fact that each id has a distribution of weights represented by the variable draw, rather than a single weight?
Thanks, @mjskay. This is a very smart way to address the problem.
Still, because brms and stanarm only accept a single column of weights, only a single column of weights must be declared in the data block. Then I could use my updated Stan model via the update command as suggested by @Guido_Bielethere.
In my new dataframe data_long the former values of the columns weights.w_1 to weights.w_10 - representing the distribution of weights per observation - are now linked by the same value of the variable id.
That needs to be accounted for in the data block :
data { ...
real<lower=0>; weights[N, 10]; // data block of model weights in wide format
}
where real<lower=0> weights[N, 10] needs to be converted into real<lower=0> weights_prime[k].
This k here could be a new variable defined in the dt_long representing the values of the variable weights for each value of the variable id. Not certain how to define that variable. Probably transformed data block could be the right place to do these things.
Ah, the point I was trying to make is that weights_prime is the same as the single column of weights you created by making the data frame into a long format. So I would have thought that already solved your problem as far as the model specification with brms or rstanarm is concerned (but not the post-processing part as I understand it).
@mjskay, indeed your solution addresses my problem as far as passing multiple columns of weights to brms or stanarm is concerned. Thank you very much for this very smart way of solving the problem.