Closed wds15 closed 4 years ago
rstanarm seems to behave the same way here.
This has to do with the sample_new_levels
argument. Does it work as you expect, when you set sample_new_levels = "gaussian"
?
Using sample_new_levels = "gaussian" makes it look a lot better. So it looks like what I want.
Would it be possible to add a hint in the documentation of posterior_predict to the allow_new_levels option that behind the "..." given to extract_draws there is this important option?
Thanks for the quick response and sorry for the noise... but I was really confused from this; glad it's just another switch...
Let's change the issue to what this should be. Improving the doc would be great. So wherever allow_new_levels
pops up, a hint to the sample_new_levels
should be made, I think. That would maybe have saved my afternoon yesterday and hence possibly others as well.
But isn't sample_new_levels
documented in the same place as allow_new_levels
? Can you clarify where you would like to see the doc updated?
I think all the predict functions should probably get a new section about "Predicting new levels" which you can include with roxygen template stuff.
The posterior_linpred function does not even mention allow_new_levels
nor does it mention sample_new_levels
. The posterior_predict
also does not mention these super important parameters at all. They are hidden behind the ...
.
EDIT: The docs do say something about prepare prediction functions, but that is not clear enough what that all entails - at least that was not clear for me.
Yeah, you are right those arguments are hard to find. I added a paragraph to the details section pointing to these arguments.
Thanks for fixing the doc.
Just wanted to note that I still find the current default way super-dangerous. I mean, what I did is to simulate new random effect levels which do vary from row to row in my data-set... but what I get is just one realisation of the random effect per draw (thus being constant across the entire data-set). I don't understand the default right now, but I am really not sure if users would ever want that. There should be at least a warning being emitted as the model is structurally being wrongly simulated to my understanding.
I understand your concern. Since rstanarm does mostly the same thing here, I would like to hear the opinion of @jgabry and @bgoodri on this issue as well.
With rstanarm, we have to put an extra level into the MCMC part (it gets multiplied by zero) in order to get draws from its posterior distribution. We might be able to make that more sane with a standalone generated quantities block. In any event, brms shouldn't feel constrained by that.
Very well. @wds15 I changed the behavior of sample_new_levels = "uncertainty"
to sample different draws for different new levels of the grouping factor. Does that solve your issue?
Great!
It seems that
posterior_linpred
samples new levels of random effects only once per draw even if the new level varies and as such should be re-drawn multiple times.Here is a minimal example:
The output is:
So the random effect which varies by id is kept constant for an entire draw, but that's just not right as the id varies across the data set which I wish to simulate.
Is this a user error or a bug in brms?
The above code ran with brms 2.13.0, but it is the same misery in 2.10.0
As the new data set as many new id's I would expect that I get a newly drawn random effect for each row of my data set.