150
150
# ' @param max_samples Integer. Maximum number of resamples when `random = TRUE`. Must be positive. Default is 100.
151
151
# ' @param subpop Logical. If TRUE, will run meta-analyses with groups. Default is FALSE.
152
152
# ' @param trace Logical. If TRUE, prints progress messages. Default is FALSE.
153
- # ' @param .iter_size Numeric. The size of each iteration step. Default is 2.
153
+ # ' @param .iter_step Numeric. The size of each iteration step. Default is 2.
154
154
# ' @param .only_max_m Logical. If TRUE, will only run the maximum number of individuals. Default is FALSE.
155
155
# ' @param .lists A list containing already created meta inputs. Default is NULL.
156
156
# '
@@ -171,7 +171,7 @@ run_meta_permutations <- function(rv,
171
171
random = FALSE ,
172
172
max_samples = 100 ,
173
173
trace = FALSE ,
174
- .iter_size = 2 ,
174
+ .iter_step = 2 ,
175
175
.only_max_m = FALSE ,
176
176
.lists = NULL ) {
177
177
@@ -266,7 +266,7 @@ run_meta_permutations <- function(rv,
266
266
267
267
m_iter <- NULL
268
268
m_iter <- .get_sequence(input [[" All" ]],
269
- .iter_size = .iter_size ,
269
+ .iter_step = .iter_step ,
270
270
grouped = subpop )
271
271
if (.only_max_m ) m_iter <- max(m_iter )
272
272
@@ -688,17 +688,6 @@ run_meta_loocv <- function(rv,
688
688
}
689
689
690
690
691
- # ' @title Plot meta
692
- # '
693
- # ' @noRd
694
- # '
695
- plot_meta <- function () {
696
-
697
-
698
-
699
-
700
- }
701
-
702
691
# ' @title Plot meta (permutations)
703
692
# '
704
693
# ' @noRd
@@ -738,43 +727,39 @@ plot_meta_permutations <- function(rv,
738
727
739
728
if (random ) {
740
729
741
- out <- rv $ meta_tbl_resample %> %
742
- dplyr :: mutate(m == as.integer(m )) %> %
743
- dplyr :: filter(type == set_target )
730
+ if (! is.null(rv $ meta_nresample ))
731
+ out <- dplyr :: filter(rv $ meta_tbl_resample ,
732
+ sample < = rv $ meta_nresample )
733
+ else out <- rv $ meta_tbl_resample
744
734
745
- if ( subpop ) {
746
- out <- out %> %
747
- dplyr :: filter(group != " All " )
748
- }
735
+ out <- out % > %
736
+ dplyr :: mutate( m = as.integer( m )) %> %
737
+ dplyr :: filter(type == set_target )
738
+ if ( subpop ) out <- dplyr :: filter( out , group != " All " )
749
739
750
740
stopifnot(all(! is.na(out $ est )), nrow(out ) > 0 )
751
741
752
742
max_samples <- max(unique(out $ sample ))
743
+ max_samples
753
744
754
745
out_mean <- out %> %
755
746
dplyr :: group_by(type , group , m ) %> %
756
747
dplyr :: summarize(
757
748
n = dplyr :: n(),
758
749
error = mean(error , na.rm = TRUE ),
759
- lci = mean(error_lci , na.rm = TRUE ),
760
- uci = mean(error_uci , na.rm = TRUE )) %> %
750
+ error_lci = mean(error_lci , na.rm = TRUE ),
751
+ error_uci = mean(error_uci , na.rm = TRUE )) %> %
761
752
dplyr :: rowwise() %> %
762
753
dplyr :: mutate(
763
- within_threshold = any(
764
- dplyr :: c_across(c(error , lci , uci )) > =
765
- - rv $ error_threshold &
766
- dplyr :: c_across(c(error , lci , uci )) < =
767
- rv $ error_threshold ),
768
- close_to_threshold = any(
769
- dplyr :: c_across(c(error , lci , uci )) > =
770
- - (rv $ error_threshold * 2 ) &
771
- dplyr :: c_across(c(error , lci , uci )) < =
772
- (rv $ error_threshold * 2 )),
773
- color = dplyr :: case_when(
774
- (lci < - rv $ error_threshold &
775
- uci > rv $ error_threshold ) ~ " Yes" ,
754
+ within_threshold =
755
+ (error > = - rv $ error_threshold &
756
+ error < = rv $ error_threshold ),
757
+ overlaps_with_threshold =
758
+ (error_lci < = rv $ error_threshold &
759
+ error_uci > = - rv $ error_threshold ),
760
+ status = dplyr :: case_when(
776
761
within_threshold ~ " Yes" ,
777
- close_to_threshold ~ " Near" ,
762
+ ! within_threshold & overlaps_with_threshold ~ " Near" ,
778
763
TRUE ~ " No" )) %> %
779
764
quiet() %> %
780
765
suppressMessages() %> %
@@ -787,44 +772,41 @@ plot_meta_permutations <- function(rv,
787
772
plot_subtitle <- paste(
788
773
" <b>Maximum number of samples:</b>" , max_samples )
789
774
790
- p_error1 <- ggplot2 :: geom_hline(
791
- yintercept = rv $ error_threshold ,
792
- color = " black" ,
793
- linetype = " dotted" )
794
- p_error2 <- ggplot2 :: geom_hline(
795
- yintercept = - rv $ error_threshold ,
796
- color = " black" ,
797
- linetype = " dotted" )
798
-
799
775
p.optimal <- out_mean %> %
800
776
ggplot2 :: ggplot(
801
777
ggplot2 :: aes(x = as.factor(m ),
802
778
y = error ,
803
779
group = group ,
804
780
shape = group ,
805
- color = color )) +
781
+ color = status )) +
806
782
807
783
ggplot2 :: geom_hline(
808
784
yintercept = 0 ,
809
785
linewidth = 0.3 ,
810
786
linetype = " solid" ) +
811
787
812
- p_error1 +
813
- p_error2 +
788
+ ggplot2 :: geom_hline(
789
+ yintercept = rv $ error_threshold ,
790
+ color = " black" ,
791
+ linetype = " dotted" ) +
792
+ ggplot2 :: geom_hline(
793
+ yintercept = - rv $ error_threshold ,
794
+ color = " black" ,
795
+ linetype = " dotted" ) +
814
796
815
797
ggplot2 :: geom_jitter(
816
798
data = out ,
817
799
mapping = ggplot2 :: aes(x = as.factor(m ),
818
800
y = error ,
819
801
group = group ,
820
802
shape = group ,
821
- color = color ),
803
+ color = status ),
822
804
position = ggplot2 :: position_jitterdodge(dodge.width = 0.4 ),
823
805
size = 3.5 , color = " grey80" , alpha = 0.9 ) +
824
806
825
807
ggplot2 :: geom_linerange(
826
- ggplot2 :: aes(ymin = lci ,
827
- ymax = uci ),
808
+ ggplot2 :: aes(ymin = error_lci ,
809
+ ymax = error_uci ),
828
810
show.legend = TRUE ,
829
811
position = ggplot2 :: position_dodge(width = 0.4 ),
830
812
linewidth = 2.2 , alpha = 0.3 ) +
@@ -855,6 +837,7 @@ plot_meta_permutations <- function(rv,
855
837
margin = ggplot2 :: margin(b = 2 )),
856
838
plot.subtitle = ggtext :: element_markdown(
857
839
size = 14 , hjust = 1 , margin = ggplot2 :: margin(b = 15 )))
840
+ p.optimal
858
841
859
842
if (rv $ which_meta == " mean" ) {
860
843
p.optimal <- p.optimal +
@@ -869,26 +852,14 @@ plot_meta_permutations <- function(rv,
869
852
870
853
stopifnot(all(! is.na(out $ est )), nrow(out ) > 0 )
871
854
872
- if (subpop ) {
873
- out <- out %> %
874
- dplyr :: filter(group != " All" )
875
- }
855
+ if (subpop ) out <- dplyr :: filter(out , group != " All" )
876
856
877
857
stopifnot(all(! is.na(out $ est )), nrow(out ) > 0 )
878
858
879
859
txt_color <- paste0(
880
860
" Within error threshold (\u 00B1" ,
881
861
rv $ error_threshold * 100 , " %)?" )
882
862
883
- p_error1 <- ggplot2 :: geom_hline(
884
- yintercept = rv $ error_threshold ,
885
- color = " black" ,
886
- linetype = " dotted" )
887
- p_error2 <- ggplot2 :: geom_hline(
888
- yintercept = - rv $ error_threshold ,
889
- color = " black" ,
890
- linetype = " dotted" )
891
-
892
863
out <- out %> %
893
864
dplyr :: group_by(type ) %> %
894
865
dplyr :: rowwise() %> %
@@ -926,7 +897,7 @@ plot_meta_permutations <- function(rv,
926
897
pal_values <- c(" A" = " #77b131" , " B" = " #009da0" )
927
898
928
899
txt_color <- " Groups:"
929
- txt_caption <- " (*) Asterisks indicate significant subpopulations."
900
+ txt_caption <- " (*) Asterisks indicate subpopulations were found ."
930
901
931
902
} # Note: refers to finding subpops within the population.
932
903
@@ -938,8 +909,14 @@ plot_meta_permutations <- function(rv,
938
909
shape = group ,
939
910
color = color )) +
940
911
941
- p_error1 +
942
- p_error2 +
912
+ ggplot2 :: geom_hline(
913
+ yintercept = rv $ error_threshold ,
914
+ color = " black" ,
915
+ linetype = " dotted" ) +
916
+ ggplot2 :: geom_hline(
917
+ yintercept = - rv $ error_threshold ,
918
+ color = " black" ,
919
+ linetype = " dotted" ) +
943
920
944
921
ggplot2 :: geom_hline(
945
922
yintercept = 0 ,
0 commit comments