1-
2- # ' Do Tukey Test and calculate letter placement
1+ # ' Perform Tukey Test and calculate letter placement
32# ' @importFrom stats TukeyHSD aov as.formula median quantile reorder
43# ' @importFrom dplyr left_join
54# ' @importFrom rlang as_name
@@ -28,13 +27,14 @@ get_tukey_letters <- function(data, x, y, group = NULL, test = c("tukey", "krusk
2827 # stop("Factor names cannot contain dashes. Please recode factor levels before proceeding.")
2928 # }
3029 if (inherits(x , " quosure" ) & is.null(group )){
31- letters .df <- place_tukey_letters(data , as_name(x ), as_name(y ), test = test ,
32- where = where , threshold = threshold )
30+ letters .df <- place_tukey_letters(data = data , x = as_name(x ), y = as_name(y ),
31+ test = test , where = where ,
32+ threshold = threshold )
3333 } else {
3434 if (type == " two-way" ){
35- letters .df <- place_tukey_letters(data , sapply(x , as_name ), as_name( y ),
36- test = test , where = where ,
37- threshold = threshold )
35+ letters .df <- place_tukey_letters(data = data , x = sapply(x , as_name ),
36+ y = as_name( y ), test = test ,
37+ where = where , threshold = threshold )
3838 } else if (type == " one-way" ){
3939 letters .df <- purrr :: map_dfr(unique(data [[as_name(group )]]), function (gr ){
4040 data %> % filter(!! group == gr ) %> %
@@ -47,6 +47,7 @@ get_tukey_letters <- function(data, x, y, group = NULL, test = c("tukey", "krusk
4747 letters .df
4848}
4949
50+ # ' Place Tukey Letters
5051# ' @noRd
5152place_tukey_letters <- function (data , x , y , test = c(" tukey" , " kruskalmc" ),
5253 where = c(" box" ," whisker" ),
@@ -56,16 +57,16 @@ place_tukey_letters <- function(data, x, y, test = c("tukey", "kruskalmc"),
5657 xlab <- x
5758 } else {
5859 form <- as.formula(paste(y , paste(x , collapse = " *" ), sep = " ~" ))
59- xlab <- paste(x , collapse = " :" )
60+ xlab <- paste(x , collapse = " :" )
6061 data [,xlab ] <- apply(data [,x ], 1 , paste , collapse = " :" )
6162 }
6263 if (test == " tukey" ){
6364 tukey <- TukeyHSD(aov(form , data = data ))[[xlab ]][,4 ]
6465 tukey <- tukey [which(! is.na(tukey ))]
6566 letters .df <- data.frame (" Letter" = multcompLetters(tukey , threshold = threshold )$ Letters )
6667 } else if (test == " kruskalmc" ){
67- test <- pgirmess :: kruskalmc(form , data = data , probs = threshold )
68- diff <- test $ dif.com [," difference " ]
68+ test <- pgirmess :: kruskalmc(form , data = data , probs = threshold )
69+ diff <- test $ dif.com [," stat.signif " ]
6970 names(diff ) <- rownames(test $ dif.com )
7071 letters .df <- data.frame (" Letter" = multcompLetters(diff )$ Letters )
7172 }
@@ -91,31 +92,33 @@ place_tukey_letters <- function(data, x, y, test = c("tukey", "kruskalmc"),
9192 letters .df
9293}
9394
95+ # ' Calculate standard error of the mean error bar
9496# ' @importFrom stats sd
9597# ' @noRd
9698get_sem <- function (x ){
9799 mean(x ) + sd(x )/ sqrt(length(x ))
98100}
99101
102+ # ' Calculate standard deviation error bar
100103# ' @importFrom stats sd
101104# ' @noRd
102105get_sd <- function (x ){
103106 mean(x ) + sd(x )
104107}
105108
109+ # ' Calculate cl normal error bar
106110# ' @noRd
107111get_cl_normal <- function (x ){
108112 Hmisc :: smean.cl.normal(x )[[3 ]]
109113}
110114
115+ # ' Calculate cl boot error bar
111116# ' @noRd
112117get_cl_boot <- function (x ){
113118 Hmisc :: smean.cl.boot(x )[[3 ]]
114119}
115120
116121# ' Check whether color specifications exists.
117- # '
118- # ' @export
119122# ' @import grDevices
120123# ' @description Function to check whether all specified colors are
121124# ' actual colors.
@@ -146,7 +149,7 @@ get_cl_boot <- function(x){
146149# ' test <- c('#FH0000', 3, '#FF00991', 'lavendel', '#AABBCCFFF')
147150# ' is.color(test)
148151# ' is.color(test, return.colors=TRUE)
149- # '
152+ # ' @export
150153is.color <- function (x , return .colors = FALSE ) {
151154 # numeric colors, max 8
152155 if (is.numeric(x )) {
@@ -171,12 +174,14 @@ is.color <- function(x, return.colors = FALSE) {
171174 }
172175}
173176
177+ # ' Calculate quantile
174178# ' @importFrom stats quantile
175179# ' @noRd
176180get_quantile <- function (x ){
177181 quantile(x , na.rm = TRUE )[4 ]
178182}
179183
184+ # ' Calculate boxplot whisker
180185# ' @importFrom stats IQR
181186# '@noRd
182187get_whisker <- function (x ){
0 commit comments