2424# ' The data frame should have columns `"Parameter"` (factor), `"Iteration"`
2525# ' (integer), `"Chain"` (integer), and `"Value"` (numeric). See **Examples**, below.
2626# ' }
27- # ' \item{`rhat ()`, `neff_ratio ()`}{
27+ # ' \item{`extract_rhat ()`, `extract_neff_ratio ()`}{
2828# ' Methods return (named) vectors.
2929# ' }
30+ # ' \item{`rhat()`, `neff_ratio()`}{
31+ # ' `r lifecycle::badge("deprecated")` Use `extract_rhat()` and
32+ # ' `extract_neff_ratio()` instead. These names clashed with
33+ # ' [posterior::rhat()] and [posterior::ess_basic()] (and other ESS
34+ # ' functions), which caused confusion because the bayesplot versions
35+ # ' *extract* already-computed values rather than compute them.
36+ # ' }
3037# ' }
3138# '
3239# ' @seealso [MCMC-nuts], [MCMC-diagnostics]
@@ -60,17 +67,50 @@ log_posterior <- function(object, ...) {
6067nuts_params <- function (object , ... ) {
6168 UseMethod(" nuts_params" )
6269}
70+ # extract_rhat -------------------------------------------------------------
71+ # ' @rdname bayesplot-extractors
72+ # ' @export
73+ extract_rhat <- function (object , ... ) {
74+ UseMethod(" extract_rhat" )
75+ }
76+ # extract_neff_ratio -------------------------------------------------------
77+ # ' @rdname bayesplot-extractors
78+ # ' @export
79+ extract_neff_ratio <- function (object , ... ) {
80+ UseMethod(" extract_neff_ratio" )
81+ }
82+
6383# rhat -------------------------------------------------------------
6484# ' @rdname bayesplot-extractors
6585# ' @export
6686rhat <- function (object , ... ) {
67- UseMethod(" rhat" )
87+ lifecycle :: deprecate_warn(
88+ when = " 1.16.0" ,
89+ what = " rhat()" ,
90+ with = " extract_rhat()" ,
91+ details = paste(
92+ " bayesplot's rhat() was renamed to extract_rhat() to make clear" ,
93+ " it only extracts already-computed R-hat values (and to avoid" ,
94+ " masking posterior::rhat(), which computes R-hat)."
95+ )
96+ )
97+ extract_rhat(object , ... )
6898}
6999# neff_ratio -------------------------------------------------------------
70100# ' @rdname bayesplot-extractors
71101# ' @export
72102neff_ratio <- function (object , ... ) {
73- UseMethod(" neff_ratio" )
103+ lifecycle :: deprecate_warn(
104+ when = " 1.16.0" ,
105+ what = " neff_ratio()" ,
106+ with = " extract_neff_ratio()" ,
107+ details = paste(
108+ " bayesplot's neff_ratio() was renamed to extract_neff_ratio() to" ,
109+ " make clear it only extracts already-computed effective sample" ,
110+ " size ratios (and to avoid masking posterior's ESS functions)."
111+ )
112+ )
113+ extract_neff_ratio(object , ... )
74114}
75115
76116
@@ -195,9 +235,9 @@ nuts_params.CmdStanMCMC <- function(object, pars = NULL, ...) {
195235
196236# ' @rdname bayesplot-extractors
197237# ' @export
198- # ' @method rhat stanfit
238+ # ' @method extract_rhat stanfit
199239# '
200- rhat .stanfit <- function (object , pars = NULL , ... ) {
240+ extract_rhat .stanfit <- function (object , pars = NULL , ... ) {
201241 suggested_package(" rstan" )
202242 s <- if (! is.null(pars )) {
203243 rstan :: summary(object , pars = pars , ... )
@@ -210,10 +250,10 @@ rhat.stanfit <- function(object, pars = NULL, ...) {
210250
211251# ' @rdname bayesplot-extractors
212252# ' @export
213- # ' @method rhat stanreg
253+ # ' @method extract_rhat stanreg
214254# ' @template args-regex_pars
215255# '
216- rhat .stanreg <- function (object , pars = NULL , regex_pars = NULL , ... ) {
256+ extract_rhat .stanreg <- function (object , pars = NULL , regex_pars = NULL , ... ) {
217257 suggested_package(" rstanarm" )
218258 r <- summary(object , pars = pars , regex_pars = regex_pars , ... )[, " Rhat" ]
219259 r <- validate_rhat(r )
@@ -226,8 +266,8 @@ rhat.stanreg <- function(object, pars = NULL, regex_pars = NULL, ...) {
226266
227267# ' @rdname bayesplot-extractors
228268# ' @export
229- # ' @method rhat CmdStanMCMC
230- rhat .CmdStanMCMC <- function (object , pars = NULL , ... ) {
269+ # ' @method extract_rhat CmdStanMCMC
270+ extract_rhat .CmdStanMCMC <- function (object , pars = NULL , ... ) {
231271 .rhat <- utils :: getFromNamespace(" rhat" , " posterior" )
232272 s <- object $ summary(pars , rhat = .rhat )[, c(" variable" , " rhat" )]
233273 r <- setNames(s $ rhat , s $ variable )
@@ -238,9 +278,9 @@ rhat.CmdStanMCMC <- function(object, pars = NULL, ...) {
238278
239279# ' @rdname bayesplot-extractors
240280# ' @export
241- # ' @method neff_ratio stanfit
281+ # ' @method extract_neff_ratio stanfit
242282# '
243- neff_ratio .stanfit <- function (object , pars = NULL , ... ) {
283+ extract_neff_ratio .stanfit <- function (object , pars = NULL , ... ) {
244284 suggested_package(" rstan" )
245285 s <- if (! is.null(pars )) {
246286 rstan :: summary(object , pars = pars , ... )
@@ -254,9 +294,9 @@ neff_ratio.stanfit <- function(object, pars = NULL, ...) {
254294
255295# ' @rdname bayesplot-extractors
256296# ' @export
257- # ' @method neff_ratio stanreg
297+ # ' @method extract_neff_ratio stanreg
258298# '
259- neff_ratio .stanreg <- function (object , pars = NULL , regex_pars = NULL , ... ) {
299+ extract_neff_ratio .stanreg <- function (object , pars = NULL , regex_pars = NULL , ... ) {
260300 suggested_package(" rstanarm" )
261301 s <- summary(object , pars = pars , regex_pars = regex_pars , ... )
262302 ess <- s [, " n_eff" ]
@@ -272,8 +312,8 @@ neff_ratio.stanreg <- function(object, pars = NULL, regex_pars = NULL, ...) {
272312
273313# ' @rdname bayesplot-extractors
274314# ' @export
275- # ' @method neff_ratio CmdStanMCMC
276- neff_ratio .CmdStanMCMC <- function (object , pars = NULL , ... ) {
315+ # ' @method extract_neff_ratio CmdStanMCMC
316+ extract_neff_ratio .CmdStanMCMC <- function (object , pars = NULL , ... ) {
277317 s <- object $ summary(pars , " n_eff" = " ess_basic" )[, c(" variable" , " n_eff" )]
278318 ess <- setNames(s $ n_eff , s $ variable )
279319 tss <- prod(dim(object $ draws())[1 : 2 ])
0 commit comments