@@ -483,6 +483,9 @@ mcmc_rank_hist <- function(x,
483
483
# ' @param plot_diff For `mcmc_rank_ecdf()`, a boolean specifying if the
484
484
# ' difference between the observed rank ECDFs and the theoretical expectation
485
485
# ' should be drawn instead of the unmodified rank ECDF plots.
486
+ # ' @param split_chains Logical indicating whether to split each chain into two parts.
487
+ # ' If TRUE, each chain is split into first and second half with "_1" and "_2" suffixes.
488
+ # ' Defaults to `FALSE`.
486
489
# ' @export
487
490
mcmc_rank_ecdf <-
488
491
function (x ,
@@ -494,7 +497,8 @@ mcmc_rank_ecdf <-
494
497
facet_args = list (),
495
498
prob = 0.99 ,
496
499
plot_diff = FALSE ,
497
- interpolate_adj = NULL ) {
500
+ interpolate_adj = NULL ,
501
+ split_chains = FALSE ) {
498
502
check_ignored_arguments(... ,
499
503
ok_args = c(" K" , " pit" , " prob" , " plot_diff" , " interpolate_adj" , " M" )
500
504
)
@@ -505,8 +509,28 @@ mcmc_rank_ecdf <-
505
509
transformations = transformations ,
506
510
highlight = 1
507
511
)
512
+
513
+ # Split chains if requested
514
+ if (split_chains ) {
515
+ data $ n_chains = data $ n_chains / 2
516
+ data $ n_iterations = data $ n_iterations / 2
517
+ n_samples <- length(unique(data $ iteration ))
518
+ midpoint <- n_samples / 2
519
+
520
+ data <- data %> %
521
+ group_by(.data $ chain ) %> %
522
+ mutate(
523
+ chain = ifelse(
524
+ iteration < = midpoint ,
525
+ paste0(.data $ chain , " _1" ),
526
+ paste0(.data $ chain , " _2" )
527
+ )
528
+ ) %> %
529
+ ungroup()
530
+ }
531
+
508
532
n_iter <- unique(data $ n_iterations )
509
- n_chain <- unique(data $ n_chains )
533
+ n_chain <- length( unique(data $ chain ) )
510
534
n_param <- unique(data $ n_parameters )
511
535
512
536
x <- if (is.null(K )) {
@@ -559,7 +583,9 @@ mcmc_rank_ecdf <-
559
583
group = .data $ chain
560
584
)
561
585
562
- scale_color <- scale_color_manual(" Chain" , values = chain_colors(n_chain ))
586
+ # Update legend title based on split_chains
587
+ legend_title <- if (split_chains ) " Split Chains" else " Chain"
588
+ scale_color <- scale_color_manual(legend_title , values = chain_colors(n_chain ))
563
589
564
590
facet_call <- NULL
565
591
if (n_param == 1 ) {
0 commit comments