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
loo_subsample() can sometimes be over-complex. srs_diff_est() is a non-exported internal function used by loo_subsample. srs_diff_est() implements difference estimator Equations 7-9 of Magnusson et al., 2020. It would be useful to export this function and provide user targeted function with documentation.
@vinniott thanks for your interest. Yes I think this would be a good first issue and what you described adding sounds good. We also probably want a bit more detail in the documentation when moving this to an exported user-facing function. For example, we should mention what type/shape the inputs should be and what the contents of the returned list are.
while I have made progress, I think it might be better if I look into stan-dev/bayesplot now and return to loo later on.
Again, thank you for explaining this issue to me.
Maybe you could tag this as "good-first-issue" now so that others can find it easier?
Thanks @vinniott for the skeleton. I think this issue requires also contribution from me. I can write the technical description I'd like to have included in the documentation.
#' Difference estimator with simple random sampling without replacement.
#'
#' The difference estimator `srs_diff()` estimates
#' the expectation $nE[y]$ when we have $n$ approximate values $\tilde{y}_i$,
#' $i=1,\ldots,n$ and $m<n$ accurate values $y_j$, $j \in
#' \mathcal{S}$, where $m$ is the subsample size and $\mathcal{S}$ is
#' a simple random subsample without replacement. The original
#' approach is by Cochran (1977) and we follow the equations 7--9 by
#' Magnusson et al. (2020).
#'
#' @param y_approx (numeric) `n` approximated values.
#' @param y (numeric) `m<n` subsampled values.
#' @param y_idx (integerish) The index of `y` in `y_approx`.
#' @return A named list containing numeric values:
#' * `y_hat`: estimated mean of $y$ (Eq 7),
#' * `v_y_hat`: variance of the mean estimate (Eq 8), and
#' * `hat_v_y`: estimated variance of $y$ (Eq 9).
#'
#' @details Magnusson et al. (2020) Eq (9) first row second `+` should
#' be `-`. Supplementary material Eq (6) has this correct.
#' As `srs_diff_est()` in `loo` package is used for $nE[y]$, there is
#' a proportional difference of $1/n$ compared to the paper.
As srs_diff_est() has been used for elpd_loo which is in sum scale, srs_diff_est() is actually estimating $nE[y]$, while the equations in the paper are for $E[y]$. The question whether we should change the exposed function to estimate $E[y]$ and then adjust other code in loo_subsample.R
Thank you for the technical documentation! I have incorporated it and made a PR #340 .
However, there is no @example yet because I am not fully familiar with the package as a whole.
Activity
jgabry commentedon Mar 2, 2026
Sounds good
vinniott commentedon Mar 11, 2026
Hello,
would this be a good first issue/contribution?
I.e. roxygenise,
#‘ @exportrespectively, this:and also add 1 or 2 examples for users as well as the Magnusson et al. (2020) citation?
Kind regards
MansMeg commentedon Mar 11, 2026
Sounds good to me too.
jgabry commentedon Mar 11, 2026
@vinniott thanks for your interest. Yes I think this would be a good first issue and what you described adding sounds good. We also probably want a bit more detail in the documentation when moving this to an exported user-facing function. For example, we should mention what type/shape the inputs should be and what the contents of the returned list are.
vinniott commentedon Mar 12, 2026
@jgabry thank you for elaborating.
If you want, then I could give it a try and update you here in a week?
jgabry commentedon Mar 12, 2026
Great, thank you!
vinniott commentedon Mar 19, 2026
Hi again,
while I have made progress, I think it might be better if I look into stan-dev/bayesplot now and return to loo later on.
Again, thank you for explaining this issue to me.
Maybe you could tag this as "good-first-issue" now so that others can find it easier?
In case this is helpful for someone, here is my initial roxygen2 skeleton for the export:
master...vinniott:loo:export-srs-diff-est
avehtari commentedon Mar 20, 2026
Thanks @vinniott for the skeleton. I think this issue requires also contribution from me. I can write the technical description I'd like to have included in the documentation.
avehtari commentedon Mar 20, 2026
Here is my proposoal for the documentation
As$nE[y]$ , while the equations in the paper are for $E[y]$ . The question whether we should change the exposed function to estimate $E[y]$ and then adjust other code in
srs_diff_est()has been used forelpd_loowhich is in sum scale,srs_diff_est()is actually estimatingloo_subsample.Radded documentation
vinniott commentedon Mar 22, 2026
Thank you for the technical documentation! I have incorporated it and made a PR #340 .
However, there is no
@exampleyet because I am not fully familiar with the package as a whole.added documentation
added documentation