diff --git a/NEWS.md b/NEWS.md index 03f5a1a..20e71d0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,8 +2,17 @@ ### Enhancements -* Add `pareto_smooth` option to `weight_draws`, to Pareto smooth +* Add `exclude` option to `subset_draws()`, which can be used to exclude + the matched selection. +* Add `are_log_weights` option to `pareto_smooth()`, which is necessary + for correct Pareto smoothing computation if the input vector + consists of log weights. +* Add `pareto_smooth` option to `weight_draws()`, to Pareto smooth weights before adding to a draws object. +* Add individual Pareto diagnostic functions (`pareto_khat()`, + `pareto_khat_threshold()`, `pareto_min_ss()`, `pareto_convergence_rate()`) +* `thin_draws()` now automatically thins draws based on ESS by default, + and non-integer thinning is possible. * Matrix multiplication of `rvar`s can now be done with the base matrix multiplication operator (`%*%`) instead of `%**%` in R >= 4.3. * `variables()`, `variables<-()`, `set_variables()`, and `nvariables()` now diff --git a/R/pareto_smooth.R b/R/pareto_smooth.R index e5f1aff..dca53cc 100644 --- a/R/pareto_smooth.R +++ b/R/pareto_smooth.R @@ -250,7 +250,7 @@ pareto_smooth.rvar <- function(x, return_k = FALSE, extra_diags = FALSE, ...) { #' @export pareto_smooth.default <- function(x, tail = c("both", "right", "left"), - r_eff = 1, + r_eff = NULL, ndraws_tail = NULL, return_k = FALSE, extra_diags = FALSE, diff --git a/R/rvar-.R b/R/rvar-.R index 33db28f..a74e42c 100755 --- a/R/rvar-.R +++ b/R/rvar-.R @@ -800,6 +800,13 @@ drop_chain_dim <- function(x) { #' (first one is draws), etc. #' @noRd cleanup_rvar_draws <- function(x) { + assert( + check_numeric(x), + check_logical(x), + check_factor(x), + check_character(x) + ) + if (length(x) == 0) { # canonical NULL rvar is at least 1 draw of nothing # this ensures that (e.g.) extending a null rvar diff --git a/man-roxygen/args-pareto.R b/man-roxygen/args-pareto.R index 92e0937..488e60b 100644 --- a/man-roxygen/args-pareto.R +++ b/man-roxygen/args-pareto.R @@ -15,7 +15,7 @@ #' al. (2024)). #' @param r_eff (numeric) relative effective sample size estimate. If #' `r_eff` is NULL, it will be calculated assuming the draws are -#' from MCMC. Default is 1. +#' from MCMC. Default is NULL. #' @param verbose (logical) Should diagnostic messages be printed? If #' `TRUE`, messages related to Pareto diagnostics will be #' printed. Default is `FALSE`. diff --git a/man/pareto_diags.Rd b/man/pareto_diags.Rd index 7e4f1d3..31420b9 100644 --- a/man/pareto_diags.Rd +++ b/man/pareto_diags.Rd @@ -68,7 +68,7 @@ The default is \code{"both"}.} \item{r_eff}{(numeric) relative effective sample size estimate. If \code{r_eff} is NULL, it will be calculated assuming the draws are -from MCMC. Default is 1.} +from MCMC. Default is NULL.} \item{ndraws_tail}{(numeric) number of draws for the tail. If \code{ndraws_tail} is not specified, it will be calculated as @@ -134,8 +134,8 @@ pareto_diags(d$Sigma) \references{ Aki Vehtari, Daniel Simpson, Andrew Gelman, Yuling Yao and Jonah Gabry (2024). Pareto Smoothed Importance Sampling. -\emph{Journal of Machine Learning Research}. 25(72), 1-58. -https://jmlr.org/papers/v25/19-556.html +\emph{Journal of Machine Learning Research}, 25(72):1-58. +\href{https://jmlr.org/papers/v25/19-556.html}{PDF} } \seealso{ \code{\link{pareto_khat}} for only calculating khat, and diff --git a/man/pareto_khat.Rd b/man/pareto_khat.Rd index 96d0ad2..9df455d 100644 --- a/man/pareto_khat.Rd +++ b/man/pareto_khat.Rd @@ -41,7 +41,7 @@ The default is \code{"both"}.} \item{r_eff}{(numeric) relative effective sample size estimate. If \code{r_eff} is NULL, it will be calculated assuming the draws are -from MCMC. Default is 1.} +from MCMC. Default is NULL.} \item{ndraws_tail}{(numeric) number of draws for the tail. If \code{ndraws_tail} is not specified, it will be calculated as @@ -76,8 +76,8 @@ pareto_khat(d$Sigma) \references{ Aki Vehtari, Daniel Simpson, Andrew Gelman, Yuling Yao and Jonah Gabry (2024). Pareto Smoothed Importance Sampling. -\emph{Journal of Machine Learning Research}. 25(72), 1-58. -https://jmlr.org/papers/v25/19-556.html +\emph{Journal of Machine Learning Research}, 25(72):1-58. +\href{https://jmlr.org/papers/v25/19-556.html}{PDF} } \seealso{ \code{\link{pareto_diags}} for additional related diagnostics, and diff --git a/man/pareto_smooth.Rd b/man/pareto_smooth.Rd index 0f15882..d89b1ab 100644 --- a/man/pareto_smooth.Rd +++ b/man/pareto_smooth.Rd @@ -13,7 +13,7 @@ pareto_smooth(x, ...) \method{pareto_smooth}{default}( x, tail = c("both", "right", "left"), - r_eff = 1, + r_eff = NULL, ndraws_tail = NULL, return_k = FALSE, extra_diags = FALSE, @@ -53,7 +53,7 @@ The default is \code{"both"}.} \item{r_eff}{(numeric) relative effective sample size estimate. If \code{r_eff} is NULL, it will be calculated assuming the draws are -from MCMC. Default is 1.} +from MCMC. Default is NULL.} \item{ndraws_tail}{(numeric) number of draws for the tail. If \code{ndraws_tail} is not specified, it will be calculated as @@ -94,8 +94,8 @@ pareto_smooth(d$Sigma) \references{ Aki Vehtari, Daniel Simpson, Andrew Gelman, Yuling Yao and Jonah Gabry (2024). Pareto Smoothed Importance Sampling. -\emph{Journal of Machine Learning Research}. 25(72), 1-58. -https://jmlr.org/papers/v25/19-556.html +\emph{Journal of Machine Learning Research}, 25(72):1-58. +\href{https://jmlr.org/papers/v25/19-556.html}{PDF} } \seealso{ \code{\link{pareto_khat}} for only calculating khat, and