<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />如果您運行 Tukey 的 JMP 之類的類似測試,則會生成“連接字母報告”。 然而,我們的數據是非正態的,並且方差是異質的,因此我們需要使用 Kruskal-Wallis 檢驗來檢查方差,然後使用 Steel-Dwass 來比較所有處理對的均值。 做了這樣的分析後,我們怎樣才能得到類似的信件報告呢?
謝謝,
扎克
我能夠使用 readxl 庫直接讀取 xls 輸入
圖書館(“readxl”)
輸入的excel文件應該這樣設置,有兩列。 其中 A,B 是列,1,2,3 是行
甲乙
成對比較 p.value
1六月至八月 0.1637
2 11 月至 8 月 0.1093
3十一月至七月 0.9316
您(或其他人)能否發布一個小輸入文件的完整示例,上述過程的代碼和輸出以執行在非參數分析後顯示緊湊字母,並從 excel 或文本輸入文件進行事後成對比較。
我想我會更新這篇文章,因為我找到了一種在非參數分析和事後成對比較之後生成緊湊字母顯示的方法。
注意:這需要開源和現成的統計程序 R(我使用 RStudio,一個更用戶友好的版本)。
在 JMP 中執行非參數分析後,將具有成對 p 值的結果表導出到 Excel 表中。 然後,您需要格式化比較字段,使其位於一個單元格中,並用一個“-”分隔正在比較的變量。
然後,在 R 中,使用以下腳本創建一個函數https://rdrr.io/github/GegznaV/spMisc/src/R/eval_glue.R ::
#' [!] Format, parse and evaluate expression in a string
#'
#' A wrapper function to format and parse a string and evaluate it
#' as an expression. \code{eval_(X)} is a wrapper for
#' \code{eval(parse(text = glue::glue(X)))}.
#'
#' @details
#' It's a good practice to write backticks (`) arround variable names
#' to prevent from errors in situations, where variables have uncommon
#' names. See examples.
#'
#' @param ... Strings to be formatted and evaluated as an expression.
#' @param .open [\code{character(1)}: ‘\{’] \cr
#' The opening delimiter. Doubling the full delimiter escapes it.
#' @param .close [\code{character(1)}: ‘\}’] \cr
#' The closing delimiter. Doubling the full delimiter escapes it.
#' @inheritParams glue::glue
#' @inheritParams base::eval
#'
#' @export
#' @seealso Format and interpolate a string (\code{\link[glue]{glue}}).\cr
#' Evaluate an (unevaluated) expression (\code{\link[base]{eval}}).\cr
#' Parse expressions (\code{\link[base]{parse}}).
#' @examples
#' library("spMisc")
#'
#' AA <- "nn"
#'
#' glue::glue("{AA} <- 3")
#'
#' eval_glue("{AA} <- 3")
#'
#' AA
#'
#' nn
#'
#' # It's a good practice to write backticks (`) arround variable names
#' # to prevent from errors in situations, where variables have uncommon
#' # names:
#'
#' BB <- "A B"
#'
#' eval_glue("`{BB}` <- 8")
#'
#' `A B`
#'
eval_glue <- function(..., envir = parent.frame(),
.sep = "", .open = "{", .close = "}") {
x2 <- glue::glue(..., .envir = envir, .open = .open, .close = .close)
eval(parse(text = x2), envir = envir)
}
在此之後,從此腳本中創建另一個函數https://github.com/GegznaV/biostat/blob/master/R/make_cld_df.R ::
#' **[!!]** Make a data frame with cld
#'
#' Compute a compact letter display (cld) of statistically significant
#' differences in pairwise comparisons and output he results as a dataframe.
#'
#' @note
#' This function is based on code in function [rcompanion::cldList()]
#' from package \pkg{rcompanion} by Salvatore Mangiafico.
#'
#' @param swap_compared_names (logical) \cr If `TRUE`, group names are swapped
#' from, e.g., "2-1" or "second-first" to "1-2" or "first-second". This leads to
#' different order of cld letters and different order of compared groups (if
#' without swapping the result is incorrect order of groups.)
#'
#' @inheritParams rcompanion::cldList
#' @inheritParams multcompView::multcompLetters
#'
#' @export
#' @keywords internal
# @param comparison_order (character) Character vector with desired order of groups.
make_cld_df <- function(
formula = NULL,
data = NULL,
comparison = NULL,
p.value = NULL,
threshold = 0.05,
print.comp = FALSE,
remove.space = TRUE,
remove.equal = TRUE,
# remove.zero = TRUE,
swap.colon = TRUE,
swap.vs = FALSE,
reversed = FALSE,
swap_compared_names = FALSE,
# comparison_order = NULL,
...) {
if (!is.null(formula)) {
# # **[!!!]** Formula interface needs review.
# p.value = eval(parse(text = paste0("data", "$", all.vars(formula[[2]])[1])))
# comparison = eval(parse(text = paste0("data", "$", all.vars(formula[[3]])[1])))
p.value <- eval_glue("data${all.vars(formula[[2]])[1]}")
comparison <- eval_glue("data${all.vars(formula[[3]])[1]}")
}
significant_difference <- p.value < threshold
# if (sum(significant_difference) == 0) {
# stop("No significant differences.", call. = FALSE)
# }
if (remove.space == TRUE) {
comparison <- gsub(" ", "", comparison)
}
if (remove.equal == TRUE) {
comparison <- gsub("=", "", comparison)
}
# if (remove.zero == TRUE) {
# comparison = gsub("0", "", comparison)
# }
if (swap.colon == TRUE) {
comparison <- gsub(":", "-", comparison)
}
if (swap.vs == TRUE) {
comparison <- gsub("vs", "-", comparison)
}
if (swap_compared_names == TRUE) {
part_1 <- stringr::str_extract(comparison, ".*(?=-)")
part_2 <- stringr::str_extract(comparison, "(?<=-).*")
comparison <- paste0(part_2, "-", part_1)
}
comparison
names(significant_difference) <- comparison
if (print.comp == TRUE) {
Y <- data.frame(Comparisons = names(significant_difference))
cat("\n\n")
print(Y)
cat("\n\n")
}
MCL <- multcompView::multcompLetters(significant_difference, reversed = reversed)
regular_cld <- as.character(MCL$Letters)
spaced_cld <- as.character(MCL$monospacedLetters)
if (is.null(MCL$monospacedLetters)) {
spaced_cld <- regular_cld
} else {
spaced_cld <- spaced_cld
}
res <- data.frame(
group = names(MCL$Letters),
cld = as.character(MCL$Letters),
spaced_cld = gsub(" ", "_", spaced_cld)
)
structure(res, class = c("cld_object", class(res)))
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Helper function
# cld_update <- function(res) {
# res$MonoLetter <- gsub(" ", "_", res$MonoLetter)
# names(res) <- c("Group", "cld", "spaced_cld")
# structure(res, class = c("cld_object", class(res)))
# }
然後,您可以將新製作的 make_cld_df 函數以下列形式應用於您的數據:
x<-make_cld_df(p.value~pairwisecomparison, data=data.
然後調用 x
我會檢查以確保增強請求在 JMP 願望清單中,如果沒有,請將其添加到清單中
看來程序沒有內置方法,而且我不精通編碼(因此使用 JMP 而不是 SAS)。 我想 SAS 對此有更多選擇,但由於易於使用,我改用 JMP。 根據您的數據,如果您可以通過轉換糾正方差,則只需運行 ANOVA 並使用 Tukey 或類似方法可能會很好,如果不能,則依賴 Welch ANOVA。
事實證明,並不總是必須滿足正態性假設:
生態學實驗,作者:AJ 木頭下。 2006 年。 劍橋大學出版社(第 192-193 頁)
我也一直在尋找一種方法來做到這一點,我相信你可以以某種方式編寫腳本,但沒有必要的腳本能力。
你能找到一種方法來做到這一點嗎? 我目前也需要做一些鋼鐵笨蛋,但不知道如何獲得連接字母。 任何幫助都會很棒。 謝謝!