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