Skip to content

Commit

Permalink
fix first-order Taylor approximation of the variance (delta method)
Browse files Browse the repository at this point in the history
for RMSE in the case `!is.null(summaries_baseline)`, see
<stan-dev#496 (comment)>
  • Loading branch information
fweber144 committed Jan 12, 2025
1 parent 7e61368 commit 2335538
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions R/summary_funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,23 @@ get_stat <- function(summaries, summaries_baseline = NULL,
cov_mse_e_b <- mean(wobs * ((mu - y)^2 - mse_e) *
((mu_baseline - y)^2 - mse_b)) / (n_full - 1)
}
value_se <- sqrt(value_se^2 - 2 * cov_mse_e_b + var_mse_b)
if (stat != "rmse") {
value_se <- sqrt(value_se^2 - 2 * cov_mse_e_b + var_mse_b)
}
}
if (stat == "mse") {
value <- mse_e - ifelse(is.null(summaries_baseline), 0, mse_b)
} else if (stat == "rmse") {
# simple transformation of mse
value <- sqrt(mse_e) - ifelse(is.null(summaries_baseline), 0, sqrt(mse_b))
# the first-order Taylor approximation of the variance
value_se <- sqrt(value_se^2 / mse_e / 4)
if (is.null(summaries_baseline)) {
value_se <- sqrt(value_se^2 / mse_e / 4)
} else {
value_se <- sqrt((value_se^2 / mse_e -
2 * cov_mse_e_b / sqrt(mse_e * mse_b) +
var_mse_b / mse_b) / 4)
}
} else if (stat == "R2") {
y_mean_w <- mean(wobs * y)
# simple transformation of mse
Expand Down

0 comments on commit 2335538

Please sign in to comment.