Skip to content

Commit 1b7d88c

Browse files
committed
Merge branch 'master' of https://github.com/stan-dev/posterior
2 parents b451955 + c70139f commit 1b7d88c

4 files changed

Lines changed: 78 additions & 57 deletions

File tree

NEWS.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# posterior 1.7.0
22

3+
### Enhancements
4+
5+
* Add `truncate` argument to `uniformity_test()` to allow for custom truncation
6+
37
### Bug Fixes
48

59
* Fix several minor issues occurring in edge cases.
@@ -9,7 +13,7 @@
913
* Extend and export several functions related to the generalized
1014
Pareto distribution for use in other packages. (#408)
1115
* Support Pareto PIT functionality via `pareto_pit`. (#435)
12-
* Allow more warnings to be turned off via option
16+
* Allow more warnings to be turned off via option
1317
`posterior.warn_on_merge_chains`.
1418
* Improve documentation in many places.
1519
* Improve tests by checking for edge cases.
@@ -41,16 +45,16 @@ Pareto distribution for use in other packages. (#408)
4145
`pareto_khat_threshold()`, `pareto_min_ss()`, `pareto_convergence_rate()`)
4246
* `thin_draws()` now automatically thins draws based on ESS by default,
4347
and non-integer thinning is possible.
44-
* Matrix multiplication of `rvar`s can now be done with the base matrix
48+
* Matrix multiplication of `rvar`s can now be done with the base matrix
4549
multiplication operator (`%*%`) instead of `%**%` in R >= 4.3.
4650
* `variables()`, `variables<-()`, `set_variables()`, and `nvariables()` now
4751
support a `with_indices` argument, which determines whether variable names
4852
are retrieved/set with (`"x[1]"`, `"x[2]"` ...) or without (`"x"`) indices
4953
(#208).
5054
* Add `extract_variable_array()` function to extract variables with indices
5155
into arrays of iterations x chains x any remaining dimensions (#340).
52-
* For types that support `factor` variables (`draws_df`, `draws_list`, and
53-
`draws_rvars`), `extract_variable()` and `extract_variable_matrix()` can
56+
* For types that support `factor` variables (`draws_df`, `draws_list`, and
57+
`draws_rvars`), `extract_variable()` and `extract_variable_matrix()` can
5458
now return `factor`s.
5559

5660
# posterior 1.5.0
@@ -72,7 +76,7 @@ Pareto distribution for use in other packages. (#408)
7276
### Bug Fixes
7377

7478
* Ensure `rfun()` works with primitive functions (#290) and dots arguments (#291).
75-
* Provide implementations of `vctrs::vec_proxy_equal()`,
79+
* Provide implementations of `vctrs::vec_proxy_equal()`,
7680
`vctrs::vec_proxy_compare()`, and `vctrs::vec_proxy_order()`.
7781
* Minor future-proofing of `cbind(<rvar>)`, `rbind(<rvar>)`, and `chol(<rvar>)`
7882
for R 4.4 (#304).
@@ -84,8 +88,8 @@ Pareto distribution for use in other packages. (#408)
8488

8589
### Bug Fixes
8690

87-
* Delay applying `tibble::num()` formatting to output from `summarise_draws()`
88-
until `print()` is called so that summary output can be easily converted to a
91+
* Delay applying `tibble::num()` formatting to output from `summarise_draws()`
92+
until `print()` is called so that summary output can be easily converted to a
8993
vanilla data frame (#275).
9094

9195

@@ -99,18 +103,18 @@ Pareto distribution for use in other packages. (#408)
99103
* The `draws_df()`, `draws_list()`, and `draws_rvars()` formats now support
100104
discrete variables stored as `factors` / `ordered`s (or `rvar_factor`s /
101105
`rvar_ordered`s). If converted to formats that do not support discrete
102-
variables with named levels (`draws_matrix()` and `draws_array()`),
106+
variables with named levels (`draws_matrix()` and `draws_array()`),
103107
factor-like variables are converted to `numeric`s.
104108
* Made `match()` and `%in%` generic and added support for `rvar`s to both
105109
functions.
106110
* Added `modal_category()`, `entropy()`, and `dissent()` functions for
107111
summarizing discrete draws.
108-
* Allow lists of draws objects to be passed as the first argument to
112+
* Allow lists of draws objects to be passed as the first argument to
109113
`bind_draws()` (#253).
110114
* Improving formatting of `summarise_draws` output via `tibble::num`.
111115
* `print.rvar()` and `format.rvar()` now default to a smaller number of
112116
significant digits in more cases, including when printing in data frames.
113-
This is controlled by the new `"posterior.digits"` option (see
117+
This is controlled by the new `"posterior.digits"` option (see
114118
`help("posterior-package")`).
115119
* Implemented faster `vec_proxy.rvar()` and `vec_restore.rvar()`, improving
116120
performance of `rvar`s in `tibble`s (and elsewhere `vctrs` is used).
@@ -144,9 +148,9 @@ Pareto distribution for use in other packages. (#408)
144148
* Support remaining modes of `diag()` for `rvar`s (#246).
145149
* Better parsing for named indices in `as_draws_rvars()`, including nested use
146150
of `[`, like `x[y[1],2]` (#243).
147-
* Allow 0-length `rvar`s with `ndraws() > 1` (#242).
151+
* Allow 0-length `rvar`s with `ndraws() > 1` (#242).
148152
* Ensure 0-length `rvar`s can be cast to `draws` formats (#242).
149-
* Don't treat length-1 `rvar`s with more than 1 dimension as scalars when
153+
* Don't treat length-1 `rvar`s with more than 1 dimension as scalars when
150154
casting to other formats (#248).
151155

152156

@@ -173,9 +177,9 @@ casting to other formats (#248).
173177

174178
### Bug Fixes
175179

176-
* fix hidden variables in `bind_draws.draws_df` when binding
180+
* fix hidden variables in `bind_draws.draws_df` when binding
177181
more than two objects thanks to Jouni Helske (#204)
178-
* fix output of `pillar::glimpse()` when used on a data frame containing
182+
* fix output of `pillar::glimpse()` when used on a data frame containing
179183
`rvar`s (#210)
180184
* drop `"draws"` and `"draws_df"` classes from `draws_df` objects if meta data
181185
columns are removed by a `dplyr` operation (#202)
@@ -187,7 +191,7 @@ columns are removed by a `dplyr` operation (#202)
187191

188192
### Enhancements
189193

190-
* use `matrixStats` to speed up convergence functions (#190) and
194+
* use `matrixStats` to speed up convergence functions (#190) and
191195
`rvar` summaries (#200)
192196

193197
### Bug Fixes
@@ -200,7 +204,7 @@ Karl Dunkle Werner and Alexey Stukalov (#188)
200204
### Other Changes
201205

202206
* No longer check for constant-per-chain input in effective
203-
sample size diagnostics as this is overly conservative
207+
sample size diagnostics as this is overly conservative
204208
especially for `ess_tail`. (#198)
205209

206210

R/uniformity_test.R

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#' @param pit Numeric vector of PIT values in `[0, 1]`.
3030
#' @param test Character string. One of `"POT"`, `"PIET"`, or `"PRIT"`.
3131
#' See details above.
32+
#' @param truncate Boolean. Determines whether the truncated (TRUE) or
33+
#' untruncated (FALSE) Cauchy combination test (CCT) is used. By default it
34+
#' is NULL in which case the truncated CCT is computed for `POT` and `PRIT`
35+
#' and the untruncated CCT is computed for `PIET`.
3236
#'
3337
#' @return A list with components:
3438
#' * `pvalue`: Global p-value from the Cauchy combination test.
@@ -49,13 +53,10 @@
4953
#' correlations. arXiv preprint arXiv:2506.12489.
5054
#'
5155
#' @export
52-
uniformity_test <- function(pit, test) {
56+
uniformity_test <- function(pit, test, truncate = NULL) {
5357

54-
choices <- c("POT", "PRIT", "PIET")
55-
if (!test %in% choices) {
56-
stop("'test' should be one of ", paste(dQuote(choices), collapse = ", "), call. = FALSE)
57-
}
58-
test <- match.arg(test, choices = choices)
58+
test <- rlang::arg_match(test, values = c("POT", "PRIT", "PIET"))
59+
if (is.null(truncate)) truncate <- (test != "PIET")
5960

6061
test_fn <- switch(test,
6162
POT = .pot_test,
@@ -67,7 +68,7 @@ uniformity_test <- function(pit, test) {
6768
std_cauchy_values <- .compute_cauchy(test_fn(pit_sorted))
6869
p_value_CCT <- .cauchy_combination_test(
6970
test_fn(pit),
70-
truncate = test != "PIET"
71+
truncate = truncate
7172
)
7273
pointwise_contributions <- .compute_shapley_values(std_cauchy_values)
7374

@@ -83,9 +84,9 @@ uniformity_test <- function(pit, test) {
8384

8485
#' Compute Shapley values
8586
#'
86-
#' Calculates the average marginal contribution of players across
87+
#' Calculates the average marginal contribution of players across
8788
#' all random arrival orders in a cooperative game.
88-
#' Used to provide a principled approach for quantifying
89+
#' Used to provide a principled approach for quantifying
8990
#' point-specific influences in a way that reflects local miscalibration.
9091
#'
9192
#' @param x Numeric vector of Cauchy-transformed PIT values.
@@ -99,11 +100,11 @@ uniformity_test <- function(pit, test) {
99100
if (n == 1) {
100101
return(0)
101102
}
102-
103+
103104
# Harmonic number
104105
# H_n = sum(1/i) for i = 1 to n
105106
harmonic_number <- sum(1 / seq_len(n))
106-
107+
107108
shapley_values <- numeric(n)
108109
for (i in seq_len(n)) {
109110
mean_others <- sum(x[-i]) / (n - 1)
@@ -120,7 +121,7 @@ uniformity_test <- function(pit, test) {
120121
#' H0: The value obtained via the inverse CDF transformation F^(-1)(x_i)
121122
#' follows the distribution of X under uniformity.
122123
#' HA: The p-value p_(i) provides evidence against uniformity.
123-
#'
124+
#'
124125
#' @param x Numeric vector of PIT values in `[0, 1]`.
125126
#' @return Numeric vector of p-values.
126127
#' @noRd
@@ -138,7 +139,7 @@ uniformity_test <- function(pit, test) {
138139
#' under uniformity.
139140
#' HA: The p-value p_(i) provides evidence against uniformity
140141
#' at the i-th order statistic u_(i).
141-
#'
142+
#'
142143
#' @param x Numeric vector of PIT values in `[0, 1]`.
143144
#' @return Numeric vector of p-values.
144145
#' @noRd
@@ -153,12 +154,12 @@ uniformity_test <- function(pit, test) {
153154
}
154155

155156
#' Pointwise Rank-based Individual Tests Combination (PRIT)
156-
#'
157+
#'
157158
#' Uniformity test based on a binomial distribution.
158159
#' H0: The number of observations falling at or below x_i
159160
#' follows a binomial distribution under uniformity.
160161
#' HA: The p-value p_i provides evidence against uniformity.
161-
#'
162+
#'
162163
#' @param x Numeric vector of PIT values in `[0, 1]`.
163164
#' @return Numeric vector of p-values.
164165
#' @noRd
@@ -168,7 +169,7 @@ uniformity_test <- function(pit, test) {
168169
probs1 <- pbinom(scaled_ecdf - 1, n, x)
169170
probs2 <- pbinom(scaled_ecdf, n, x)
170171
p_values <- 2 * pmin(1 - probs1, probs2)
171-
172+
172173
return(p_values)
173174
}
174175

man/uniformity_test.Rd

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)