@@ -606,13 +606,13 @@ ppc_pit_ecdf <- function(y,
606
606
if (is.null(pit )) {
607
607
pit <- ppc_data(y , yrep ) %> %
608
608
group_by(.data $ y_id ) %> %
609
- dplyr :: group_map(~ mean(.x $ value [.x $ is_y ] > = .x $ value [! .x $ is_y ])) %> %
609
+ dplyr :: group_map(
610
+ ~ mean(.x $ value [.x $ is_y ] > .x $ value [! .x $ is_y ]) +
611
+ runif(1 , max = mean(.x $ value [.x $ is_y ] == .x $ value [! .x $ is_y ]))
612
+ ) %> %
610
613
unlist()
611
614
if (is.null(K )) {
612
- K <- min(
613
- length(unique(ppc_data(y , yrep )$ rep_id )) + 1 ,
614
- length(pit )
615
- )
615
+ K <- nrow(yrep ) + 1
616
616
}
617
617
} else {
618
618
inform(" 'pit' specified so ignoring 'y', and 'yrep' if specified." )
@@ -632,20 +632,22 @@ ppc_pit_ecdf <- function(y,
632
632
ggplot() +
633
633
aes(
634
634
x = 1 : K / K ,
635
- y = ecdf(pit )(seq(0 , 1 , length.out = K )) - (plot_diff == TRUE ) * 1 : K / K ,
635
+ y = ecdf(pit )(seq(0 , 1 , length.out = K )) -
636
+ (plot_diff == TRUE ) * seq(0 , 1 , length.out = K ),
636
637
color = " y"
637
638
) +
638
639
geom_step(show.legend = FALSE ) +
639
640
geom_step(aes(
640
- y = lims $ upper [- 1 ] / N - (plot_diff == TRUE ) * 1 : K / K ,
641
+ y = lims $ upper [- 1 ] / N - (plot_diff == TRUE ) * seq( 0 , 1 , length.out = K ) ,
641
642
color = " yrep"
642
- ), show.legend = FALSE ) +
643
+ ),
644
+ linetype = 2 , show.legend = FALSE ) +
643
645
geom_step(aes(
644
- y = lims $ lower [- 1 ] / N - (plot_diff == TRUE ) * 1 : K / K ,
646
+ y = lims $ lower [- 1 ] / N - (plot_diff == TRUE ) * seq( 0 , 1 , length.out = K ) ,
645
647
color = " yrep"
646
- ), show.legend = FALSE ) +
647
- yaxis_title( FALSE ) +
648
- xaxis_title( FALSE ) +
648
+ ),
649
+ linetype = 2 , show.legend = FALSE ) +
650
+ labs( y = " ECDF " , x = " PIT " ) +
649
651
yaxis_ticks(FALSE ) +
650
652
scale_color_ppc() +
651
653
bayesplot_theme_get()
@@ -671,10 +673,13 @@ ppc_pit_ecdf_grouped <-
671
673
if (is.null(pit )) {
672
674
pit <- ppc_data(y , yrep , group ) %> %
673
675
group_by(.data $ y_id ) %> %
674
- dplyr :: group_map(~ mean(.x $ value [.x $ is_y ] > = .x $ value [! .x $ is_y ])) %> %
676
+ dplyr :: group_map(
677
+ ~ mean(.x $ value [.x $ is_y ] > .x $ value [! .x $ is_y ]) +
678
+ runif(1 , max = mean(.x $ value [.x $ is_y ] == .x $ value [! .x $ is_y ]))
679
+ ) %> %
675
680
unlist()
676
681
if (is.null(K )) {
677
- K <- length(unique(ppc_data( y , yrep ) $ rep_id ) ) + 1
682
+ K <- nrow( yrep ) + 1
678
683
}
679
684
} else {
680
685
inform(" 'pit' specified so ignoring 'y' and 'yrep' if specified." )
@@ -723,13 +728,14 @@ ppc_pit_ecdf_grouped <-
723
728
geom_step(aes(
724
729
y = .data $ lims_upper - (plot_diff == TRUE ) * .data $ x ,
725
730
color = " yrep"
726
- ), show.legend = FALSE ) +
731
+ ),
732
+ linetype = 2 , show.legend = FALSE ) +
727
733
geom_step(aes(
728
734
y = .data $ lims_lower - (plot_diff == TRUE ) * .data $ x ,
729
735
color = " yrep"
730
- ), show.legend = FALSE ) +
731
- xaxis_title( FALSE ) +
732
- yaxis_title( FALSE ) +
736
+ ),
737
+ linetype = 2 , show.legend = FALSE ) +
738
+ labs( y = " ECDF " , x = " PIT " ) +
733
739
yaxis_ticks(FALSE ) +
734
740
bayesplot_theme_get() +
735
741
facet_wrap(" group" ) +
0 commit comments