@@ -301,15 +301,17 @@ mcmc_areas <- function(x,
301301 bw = NULL ,
302302 adjust = NULL ,
303303 kernel = NULL ,
304- n_dens = NULL ) {
304+ n_dens = NULL ,
305+ bounds = NULL ) {
305306 check_ignored_arguments(... )
306307 area_method <- match.arg(area_method )
307308
308309 data <- mcmc_areas_data(
309310 x , pars , regex_pars , transformations ,
310311 prob = prob , prob_outer = prob_outer ,
311312 point_est = point_est , rhat = rhat ,
312- bw = bw , adjust = adjust , kernel = kernel , n_dens = n_dens
313+ bw = bw , adjust = adjust , kernel = kernel ,
314+ n_dens = n_dens , bounds = bounds
313315 )
314316 datas <- split(data , data $ interval )
315317
@@ -474,13 +476,14 @@ mcmc_areas_ridges <- function(x,
474476 prob = 1 ,
475477 border_size = NULL ,
476478 bw = NULL , adjust = NULL , kernel = NULL ,
477- n_dens = NULL ) {
479+ n_dens = NULL ,
480+ bounds = NULL ) {
478481 check_ignored_arguments(... )
479482 data <- mcmc_areas_ridges_data(x , pars = pars , regex_pars = regex_pars ,
480483 transformations = transformations ,
481484 prob = prob , prob_outer = prob_outer ,
482485 bw = bw , adjust = adjust , kernel = kernel ,
483- n_dens = n_dens )
486+ n_dens = n_dens , bounds = bounds )
484487
485488 datas <- data %> %
486489 split(data $ interval )
@@ -668,8 +671,10 @@ mcmc_areas_data <- function(x,
668671 bw = NULL ,
669672 adjust = NULL ,
670673 kernel = NULL ,
671- n_dens = NULL ) {
674+ n_dens = NULL ,
675+ bounds = NULL ) {
672676 probs <- check_interval_widths(prob , prob_outer )
677+ bounds <- validate_density_bounds(bounds )
673678
674679 # First compute normal intervals so we know the width of the data, point
675680 # estimates, and have prepared rhat values.
@@ -699,6 +704,7 @@ mcmc_areas_data <- function(x,
699704 bw = bw ,
700705 adjust = adjust ,
701706 kernel = kernel ,
707+ bounds = bounds ,
702708 n_dens = n_dens ) %> %
703709 mutate(interval = " inner" )
704710
@@ -710,6 +716,7 @@ mcmc_areas_data <- function(x,
710716 bw = bw ,
711717 adjust = adjust ,
712718 kernel = kernel ,
719+ bounds = bounds ,
713720 n_dens = n_dens ) %> %
714721 mutate(interval = " outer" )
715722
@@ -777,12 +784,14 @@ mcmc_areas_ridges_data <- function(x,
777784 prob = 1 ,
778785 bw = NULL ,
779786 adjust = NULL , kernel = NULL ,
780- n_dens = NULL ) {
787+ n_dens = NULL ,
788+ bounds = NULL ) {
781789 check_ignored_arguments(... )
782790 mcmc_areas_data(x , pars = pars , regex_pars = regex_pars ,
783791 transformations = transformations ,
784792 prob = prob , prob_outer = prob_outer , point_est = " none" ,
785- bw = bw , adjust = adjust , kernel = kernel , n_dens = n_dens )
793+ bw = bw , adjust = adjust , kernel = kernel ,
794+ n_dens = n_dens , bounds = bounds )
786795}
787796
788797
@@ -841,15 +850,24 @@ compute_column_density <- function(df, group_vars, value_var, ...) {
841850
842851# Given a vector of values, compute a density dataframe.
843852compute_interval_density <- function (x , interval_width = 1 , n_dens = 1024 ,
844- bw = NULL , adjust = NULL , kernel = NULL ) {
853+ bw = NULL , adjust = NULL , kernel = NULL ,
854+ bounds = NULL ) {
845855 n_dens <- n_dens %|| % 1024
846856
847857 tail_width <- (1 - interval_width ) / 2
848858 qs <- quantile(x , probs = c(tail_width , 1 - tail_width ))
859+ support <- range(qs )
860+ if (! is.null(bounds )) {
861+ support [1 ] <- max(bounds [1 ], support [1 ])
862+ support [2 ] <- min(bounds [2 ], support [2 ])
863+ if (! (support [1 ] < support [2 ])) {
864+ support <- range(qs )
865+ }
866+ }
849867
850868 args <- c(
851869 # can't be null
852- list (x = x , from = min( qs ) , to = max( qs ) , n = n_dens ),
870+ list (x = x , from = support [ 1 ] , to = support [ 2 ] , n = n_dens ),
853871 # might be null
854872 bw = bw , adjust = adjust , kernel = kernel )
855873
0 commit comments