<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 值
1 6月-8月 0.1637
2 11 月-8 月 0.1093
3 11 月-7 月 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。 根據您的數據,如果您可以透過轉換來修正方差,則只需執行變異數分析並使用 Tukey 變異數分析或類似變異數分析即可,如果不能,則依賴 Welch 變異數分析。
事實證明,並不總是需要滿足常態性假設:
生態學實驗,作者:AJ 木頭下。 2006年。 劍橋大學出版社(第 192-193 頁)
我也一直在尋找一種方法來做到這一點,我確信您可以以某種方式編寫腳本,但不具備必要的腳本編寫能力。
你能找到辦法做到這一點嗎? 我目前也需要做一些鋼德瓦斯,但不知道如何獲得連接字母。 任何幫助都會很棒。 謝謝你!