<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 页)
我也一直在寻找一种方法来做到这一点,我确信您可以以某种方式编写脚本,但不具备必要的脚本编写能力。
你能找到办法做到这一点吗? 我目前也需要做一些钢德瓦斯,但不知道如何获得连接字母。 任何帮助都会很棒。 谢谢你!