@@ -558,8 +558,9 @@ ppc_pit_ecdf <- function(y,
558
558
K = NULL ,
559
559
prob = .99 ,
560
560
plot_diff = TRUE ,
561
- adj_method = " interpolate" ) {
562
- check_ignored_arguments(... )
561
+ interpolate_adj = FALSE ) {
562
+ check_ignored_arguments(... ,
563
+ ok_args = c(" K" , " pit" , " prob" , " plot_diff" , " interpolate_adj" ))
563
564
564
565
if (is.null(pit )) {
565
566
pit <- ppc_data(y , yrep ) %> %
@@ -578,24 +579,23 @@ ppc_pit_ecdf <- function(y,
578
579
}
579
580
N <- length(pit )
580
581
gamma <- adjust_gamma(N ,
581
- K = K ,
582
- conf_level = prob ,
583
- adj_method = adj_method
584
- )
582
+ K = K ,
583
+ prob = prob ,
584
+ interpolate_adj = interpolate_adj )
585
585
lims <- ecdf_intervals(N , K = K , gamma = gamma )
586
586
ggplot() +
587
587
aes_(
588
- x = 0 : K / K ,
589
- y = ecdf(pit )(0 : K / K ) - (plot_diff == TRUE ) * 0 : K / K ,
588
+ x = 1 : K / K ,
589
+ y = ecdf(pit )(seq( 0 , 1 , length.out = K )) - (plot_diff == TRUE ) * 1 : K / K ,
590
590
color = " y"
591
591
) +
592
592
geom_step(show.legend = FALSE ) +
593
593
geom_step(aes(
594
- y = lims $ upper / N - (plot_diff == TRUE ) * 0 : K / K ,
594
+ y = lims $ upper [ - 1 ] / N - (plot_diff == TRUE ) * 1 : K / K ,
595
595
color = " yrep"
596
596
), show.legend = FALSE ) +
597
597
geom_step(aes(
598
- y = lims $ lower / N - (plot_diff == TRUE ) * 0 : K / K ,
598
+ y = lims $ lower [ - 1 ] / N - (plot_diff == TRUE ) * 1 : K / K ,
599
599
color = " yrep"
600
600
), show.legend = FALSE ) +
601
601
yaxis_title(FALSE ) +
@@ -613,20 +613,21 @@ ppc_pit_ecdf_grouped <-
613
613
yrep ,
614
614
group ,
615
615
... ,
616
- K ,
617
- pit ,
616
+ K = NULL ,
617
+ pit = NULL ,
618
618
prob = .99 ,
619
619
plot_diff = TRUE ,
620
- adj_method = " interpolate" ) {
621
- check_ignored_arguments(... )
620
+ interpolate_adj = FALSE ) {
621
+ check_ignored_arguments(... ,
622
+ ok_args = c(" K" , " pit" , " prob" , " plot_diff" , " interpolate_adj" ))
622
623
623
- if (missing (pit )) {
624
+ if (is.null (pit )) {
624
625
pit <- ppc_data(y , yrep , group ) %> %
625
626
group_by(y_id ) %> %
626
627
dplyr :: group_map(~ mean(.x $ value [.x $ is_y ] > = .x $ value [! .x $ is_y ])) %> %
627
628
unlist()
628
- if (missing (K )) {
629
- K0 <- length(unique(ppc_data(y , yrep )$ rep_id ))
629
+ if (is.null (K )) {
630
+ K <- length(unique(ppc_data(y , yrep )$ rep_id )) + 1
630
631
}
631
632
} else {
632
633
inform(" 'pit' specified so ignoring 'y', and 'yrep' if specified." )
@@ -638,9 +639,9 @@ ppc_pit_ecdf_grouped <-
638
639
N_g <- sum(group == g )
639
640
adjust_gamma(
640
641
N_g ,
641
- K = min(N_g , K0 ),
642
- conf_level = prob ,
643
- adj_method = adj_method
642
+ K = min(N_g , K ),
643
+ prob = prob ,
644
+ interpolate_adj = interpolate_adj
644
645
)
645
646
})
646
647
names(gammas ) <- unique(group )
@@ -649,26 +650,26 @@ ppc_pit_ecdf_grouped <-
649
650
group_by(group ) %> %
650
651
dplyr :: group_map(~ data.frame (
651
652
ecdf_value = ecdf(.x $ pit )(
652
- seq(0 , 1 , length.out = min(nrow(.x ) + 1 , K0 + 1 ))),
653
+ seq(0 , 1 , length.out = min(nrow(.x ), K ))),
653
654
group = .y [1 ],
654
655
lims_upper = ecdf_intervals(
655
656
N = nrow(.x ),
656
- K = min(nrow(.x ), K0 ),
657
+ K = min(nrow(.x ), K ),
657
658
gamma = gammas [[unlist(.y [1 ])]]
658
- )$ upper / nrow(.x ),
659
+ )$ upper [ - 1 ] / nrow(.x ),
659
660
lims_lower = ecdf_intervals(
660
661
N = nrow(.x ),
661
- K = min(nrow(.x ), K0 ),
662
+ K = min(nrow(.x ), K ),
662
663
gamma = gammas [[unlist(.y [1 ])]]
663
- )$ lower / nrow(.x ),
664
- x = seq(0 , 1 , length.out = min(nrow(.x ) + 1 , K0 + 1 ))
664
+ )$ lower [ - 1 ] / nrow(.x ),
665
+ x = seq(0 , 1 , length.out = min(nrow(.x ), K ))
665
666
)) %> %
666
667
dplyr :: bind_rows()
667
668
ggplot(data ) +
668
669
aes_(
669
- x = ~ x ,
670
+ x = ~ x ,
670
671
y = ~ ecdf_value - (plot_diff == TRUE ) * x ,
671
- group = ~ group ,
672
+ group = ~ group ,
672
673
color = " y"
673
674
) +
674
675
geom_step(show.legend = FALSE ) +
0 commit comments