|
39 | 39 | #' distribution, a practice derived for Gaussian linear models or |
40 | 40 | #' asymptotically, and which only applies to nested models in any case. |
41 | 41 | #' |
42 | | -#' ## `p_worse` and `diag_pnorm` |
| 42 | +#' ## `p_worse` and `diag_diff` |
43 | 43 | #' The values in the `p_worse` column show the probability of each model |
44 | 44 | #' having worse ELPD than the best model. These probabilities are computed |
45 | 45 | #' with a normal approximation using the values from `elpd_diff` and |
46 | 46 | #' `se_diff`. Sivula et al. (2025) present the conditions when the normal |
47 | 47 | #' approximation used for SE and `se_diff` is good, and the column |
48 | | -#' `diag_pnorm` contains possible diagnostic messages: |
| 48 | +#' `diag_diff` contains possible diagnostic messages: |
49 | 49 | #' |
50 | 50 | #' * `N < 100` (small data) |
51 | 51 | #' * `|elpd_diff| < 4` (models make similar predictions) |
@@ -137,24 +137,24 @@ loo_compare.default <- function(x, ...) { |
137 | 137 | # * khat_diff > 0.5: possible outliers in differences (Sivula et al., 2025; Vehtari et al., 2024) |
138 | 138 | N <- nrow(diffs) |
139 | 139 | if (N < 100) { |
140 | | - diag_pnorm <- rep("N < 100", length(elpd_diff)) |
141 | | - diag_pnorm[elpd_diff == 0] <- "" |
| 140 | + diag_diff <- rep("N < 100", length(elpd_diff)) |
| 141 | + diag_diff[elpd_diff == 0] <- "" |
142 | 142 | } else { |
143 | | - diag_pnorm <- rep("", length(elpd_diff)) |
144 | | - diag_pnorm[elpd_diff > -4 & elpd_diff != 0] <- "|elpd_diff| < 4" |
| 143 | + diag_diff <- rep("", length(elpd_diff)) |
| 144 | + diag_diff[elpd_diff > -4 & elpd_diff != 0] <- "|elpd_diff| < 4" |
145 | 145 | khat_diff <- rep(NA, length(elpd_diff)) |
146 | 146 | khat_diff[elpd_diff != 0] <- apply( |
147 | 147 | diffs[, elpd_diff != 0, drop = FALSE], 2, |
148 | 148 | function(x) ifelse(length(unique(x)) <= 20, NA, posterior::pareto_khat(x, tail = "both") |
149 | 149 | )) |
150 | | - diag_pnorm[khat_diff > 0.5] <- "khat_diff > 0.5" |
| 150 | + diag_diff[khat_diff > 0.5] <- "khat_diff > 0.5" |
151 | 151 | } |
152 | 152 | comp <- cbind( |
153 | 153 | data.frame( |
154 | 154 | elpd_diff = elpd_diff, |
155 | 155 | se_diff = se_diff, |
156 | 156 | p_worse = p_worse, |
157 | | - diag_pnorm = diag_pnorm |
| 157 | + diag_diff = diag_diff |
158 | 158 | ), |
159 | 159 | as.data.frame(comp) |
160 | 160 | ) |
@@ -188,7 +188,7 @@ print.compare.loo <- function(x, ..., digits = 1, p_worse = TRUE) { |
188 | 188 | print( |
189 | 189 | cbind(.fr(xcopy, digits), |
190 | 190 | p_worse = .fr(x[, "p_worse"], 2), |
191 | | - diag_pnorm = x[, "diag_pnorm"]), |
| 191 | + diag_diff = x[, "diag_diff"]), |
192 | 192 | quote = FALSE |
193 | 193 | ) |
194 | 194 | } else { |
|
0 commit comments