You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@youngahn For transformed parameters (e.g., learning rates), our stan models look something like this:
parameters {
// group-level pars
real mu_A_pr;
real sigma_A;
// person-level (non-centered)
vector[N] A_pr;
}
transformed parameters {
// person-level transformed
vector[N] A;
for (i in 1:N) {
A[i] = Phi_approx(mu_A_pr + sigma_A * A_pr[i]);
}
}
Then, we later compute the group-level mean for the given parameter like so:
generated quantities {
real mu_A;
mu_A = Phi_approx(mu_A_pr);
...
}
This is actually not fully correct assuming that we want mu_A to indicate the mean across person-level parameters after undergoing the transformation. This can easily be observed with a simulation:
Above, mu_A will consistently mis-estimate actual_mu_A, as it is capturing the group-level median rather than mean. The reason is outlined in #117. The fix is actually rather simple, although it requires some post-hoc simulation. Instead of simply taking mu_A = Phi_approx(mu_A_pr) in the Stan model, we could do something like the following externally:
In the above, we simulate 10000 "people/examples" from each MCMC iteration in the group-level distribution, do the transformation, and then compute the mean of the simulated examples. 10000 is arbitrary, but higher values will produce less approximation error so it it a reasonable default. The resulting mu_A will now actually be the posterior distribution on the group-level A parameter on the (0,1) scale.
NOTE: this is only relevant for the transformed parameters. e.g., if we use Phi_approx or similar for bounded parameters. In the case of parameters that are not transformed/are unbounded, the above steps are redundant (mu_A and actual_mu_A would be the same if we did not need Phi_approx/pnorm)
NOTE 2: This is all related to #117, although the solution was not spelled out in that issue. It is not really a huge bug, but still one that should be addressed. Any comparisons that people have made between the group-level parameters are still valid, although the estimand has unintentionally been the median rather than the mean 🤓
The text was updated successfully, but these errors were encountered:
Actually, I think we could do better by doing the full simulation within the generated quantities block, avoiding the need to do something externally in both R and Python. Perhaps we could create a custom function that take the group mean and SD as input and does the simulation, returning the corrected values as needed 🤔
e.g., the following function signature should do the trick for the parameters that use Phi_approx:
functions {
real Phi_approx_group_mean_rng(real mu, real sigma, int n_samples) {
vector[n_samples] par;
for (i in 1:n_samples) {
par[i] = Phi_approx(normal_rng(mu, sigma));
}
return mean(par);
}
}
then in generated quantities later on:
// Group-level means
mu_A = Phi_approx_group_mean_rng(mu_A_pr, sigma_A, 10000);
...
@youngahn For transformed parameters (e.g., learning rates), our stan models look something like this:
Then, we later compute the group-level mean for the given parameter like so:
This is actually not fully correct assuming that we want
mu_A
to indicate the mean across person-level parameters after undergoing the transformation. This can easily be observed with a simulation:Above,
mu_A
will consistently mis-estimateactual_mu_A
, as it is capturing the group-level median rather than mean. The reason is outlined in #117. The fix is actually rather simple, although it requires some post-hoc simulation. Instead of simply takingmu_A = Phi_approx(mu_A_pr)
in the Stan model, we could do something like the following externally:In the above, we simulate
10000
"people/examples" from each MCMC iteration in the group-level distribution, do the transformation, and then compute the mean of the simulated examples.10000
is arbitrary, but higher values will produce less approximation error so it it a reasonable default. The resultingmu_A
will now actually be the posterior distribution on the group-levelA
parameter on the(0,1)
scale.NOTE: this is only relevant for the transformed parameters. e.g., if we use
Phi_approx
or similar for bounded parameters. In the case of parameters that are not transformed/are unbounded, the above steps are redundant (mu_A
andactual_mu_A
would be the same if we did not needPhi_approx/pnorm
)NOTE 2: This is all related to #117, although the solution was not spelled out in that issue. It is not really a huge bug, but still one that should be addressed. Any comparisons that people have made between the group-level parameters are still valid, although the estimand has unintentionally been the median rather than the mean 🤓
The text was updated successfully, but these errors were encountered: