Hi, I am trying to plot generated quantities against data variables. I have a sample of N observations, for which I construct a model, which I use to generate a scalar quantity for each of the N observations.
generated quantities{
real effect_unit[N];
}
Since I have one generated quantity per observation, I’d like to plot effect_unit and a variables in my dataset, let’s say height. Obviously, the effect and height must match for each observation. Now, since effect_unit is an aleatory variable, I would be ok with plotting its mean (or median) against the corresponding covariate.
I tried a bunch of ways but I cannot come up with anything. Is there a simple way to access the stanfit object and export the mean of effect_unit (across iterations and chains) to my original .csv dataset?
I saw @ mjskay package in this post, I suspect it could help, but I am not proficient enough to understand how.