Skip to content

Commit

Permalink
avoid redundant computations by moving `sqrt(srs_diffe$v_y_hat + srs_…
Browse files Browse the repository at this point in the history
…diffe$hat_v_y)` into `.srs_diff_est_w()`
  • Loading branch information
fweber144 committed Aug 23, 2024
1 parent 59afc97 commit 2727cff
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions R/summary_funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ get_stat <- function(summaries, summaries_baseline = NULL,
y_idx = loo_inds)
value <- srs_diffe$y_hat
# combine estimates of var(y_hat) and var(y)
value_se <- sqrt(srs_diffe$v_y_hat + srs_diffe$hat_v_y)
value_se <- srs_diffe$y_hat_se
} else {
# full LOO estimator
value <- sum((lppd - lppd_baseline), na.rm = TRUE)
Expand Down Expand Up @@ -301,7 +301,7 @@ get_stat <- function(summaries, summaries_baseline = NULL,
w = wobs)
value <- srs_diffe$y_hat / n_full
# combine estimates of var(y_hat) and var(y)
value_se <- sqrt(srs_diffe$v_y_hat + srs_diffe$hat_v_y) / n_full
value_se <- srs_diffe$y_hat_se / n_full
}
# store for later calculations
mse_e <- value
Expand Down Expand Up @@ -453,7 +453,7 @@ get_stat <- function(summaries, summaries_baseline = NULL,
w = wobs)
value <- srs_diffe$y_hat / n_full
# combine estimates of var(y_hat) and var(y)
value_se <- sqrt(srs_diffe$v_y_hat + srs_diffe$hat_v_y) / n_full
value_se <- srs_diffe$y_hat_se / n_full
} else {
# full LOO estimator
value <- mean(wobs * correct) - mean(wobs * correct_baseline)
Expand Down Expand Up @@ -585,5 +585,6 @@ get_nfeat_baseline <- function(object, baseline, stat, ...) {
# which explains the proportional difference of 1/N
est_list$hat_v_y <- (t_pi2_tilde + t_hat_epsilon) - # a (has been checked)
(1 / N) * (t_e^2 - est_list$v_y_hat + 2 * t_pi_tilde * est_list$y_hat - t_pi_tilde^2) # b
est_list$y_hat_se <- sqrt(est_list$v_y_hat + est_list$hat_v_y)
return(est_list)
}

2 comments on commit 2727cff

@avehtari
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit makes the .srs_diff_est_w(() to have different behavior from the one in loo package, so the name of the function should be changed and a comment should be added that the extra line is changing the behavior compared to the original paper, too. Alternatively, revert this commit and keep that combination of variances where it was.

@fweber144
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, I wasn't aware of the connection with the loo package. I've reverted this in commit 348827c.

Please sign in to comment.