数据的处理是否会影响wilcox分析:
log数据不会影响wilcox分析
#log转换并不影响秩和检验结果(没有改变数据排列顺序)
x <- sample(1:100, 100, replace = FALSE)
y <- sample(100:1000, 100, replace = FALSE)
wilcox.test(x,y) ##p-value < 2.2e-16
wilcox.test(log(x), log(y)) #p-value < 2.2e-16
不同组间进行scale会导致wilcox结果差异
min-max标准化(归一化:0,1标准化)和scale标准化改变顺序,将影响秩和检验结果
##min-max标准化(归一化:0,1标准化)
#EX = (x- min)/(max - min)##正向指标
dat<-data.frame(x,y)
normalize <- function(x) {
return ((x - min(x)) / (max(x) - min(x)))
}
dat1=as.data.frame(lapply(dat[1:2],normalize))
x2<-dat1$x
y2<-dat1$y
wilcox.test(x2,y2)#p-value = 0.9445
##scale标准化改变顺序,将影响秩和检验结果
#EX = (x - mean)/σ
x1<-scale(x)
y1<-scale(y)
wilcox.test(x1,y1)##p-value = 0.999
组内scale不会导致wilcox结果差异
rm(list = ls())
set.seed(123)
# 生成三组随机数据
group1 <- runif(20, 1, 10)
group2 <- runif(20, 100, 1000)
df <- data.frame(value = c(group1, group2),
group = rep(c("group1", "group2"), each = 20))
##进行wilcox测试
res <- wilcox.test(value ~ group, data = df, var.equal = TRUE)
res
#W = 0, p-value = 1.451e-11
#进行scale
data <- as.data.frame(scale(df[,1]))
data$group <- rep(c("group1", "group2"), each = 20)
res1 <- wilcox.test(V1 ~ group, data = data, var.equal = TRUE)
res1
#W = 0, p-value = 1.451e-11
组内标准化不影响组内数据排序
组内标准化不影响组内数据排序,所以不影响wilcox 秩序
rm(list = ls())
x <- sample(1:100, 100, replace = FALSE)
y <- sample(100:1000, 100, replace = FALSE)
df <- data.frame(value = c(x, y),
group = rep(c("group1", "group2"), each = 100))
df$order <- rownames(df)
wilcox.test(value ~ group, data = df, var.equal = TRUE)
#W = 0, p-value < 2.2e-16
##标准化
df1 <- as.data.frame(scale(df[,1]))
df1$group <- rep(c("group1", "group2"), each = 100)
wilcox.test(V1 ~ group, data = df1, var.equal = TRUE)
#W = 0, p-value < 2.2e-16
############################
df$order <- rownames(df)
df1$order <- rownames(df1)
##进行排序后测试排序是否改变(同组内进行scale不影响顺序)
dfa <- df[order(df$value),]
df1a <- df1[order(df1$V1),]
identical(dfa$order,df1a$order)
#[1] TRUE
只是进行的测试数据