sci审稿返回意见:power calculation

前段时间投了一篇纯生信分析的文章,审稿人的意见是统计分析缺少“power calculation”,也就是功效分析。

在假设检验中,当H0为真而拒绝H0接受H1时,被称为一类错误,犯错的改率使用α表示,也就是我们的p.value需要小于的临界值。当H1为真而决绝H1接受H0时,就被称为二类错误,犯错概率用β表示。在我的理解中,1-β就是power calculation

R包“pwr”包含了多种计算功效的方法。参考

https://blog.csdn.net/gdyflxw/article/details/53997995?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-2.pc_relevant_default&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-2.pc_relevant_default&utm_relevant_index=3

pwr包中没有对秩和检验wilcox.test的pwr计算。需要使用其他的包:“rstatix”。具体使用方法参考:

https://www.datanovia.com/en/lessons/wilcoxon-test-in-r/#effect-size

但是这个包仍然不能计算power calculation,只能计算effect size。

The r value varies from 0 to close to 1. The interpretation values for r commonly in published literature are: 0.10 - < 0.3 (small effect), 0.30 - < 0.5 (moderate effect) and >= 0.5 (large effect).(这里的r就是指用函数wilcox_effsize计算出的effect size)。

我在补数据的时候,用于计算功效值的都是melt类型的数据,也就是使用reshape2包的melt函数改造后的窄数据。对于这种窄数据我写了个小函数包装计算功效值的过程。

pwr_my <- function(data,group,variable=NULL,value,method="t.test",sig.level=0.05){
  library(pwr)
  if(is.null(variable)){data$variable = as.factor(rep(value,nrow(data)))
  variable="variable"}
  variable_list <- data[,variable][!duplicated(data[,variable])]
  group_list <- data[,group][!duplicated(data[,group])]
  pwr_list <- data.frame(variable=variable_list,p=rep(NA,length(variable_list)),pwr=rep(NA,length(variable_list)))

  for(i in 1:length(variable_list)){
    pwr <- data[data[,variable]==variable_list[i],]
    n1 <- length(which(pwr[,group]==group_list[1]))
    n2 <- length(which(pwr[,group]==group_list[2]))
    sd1 <- sd(pwr[,value][pwr[,group]==group_list[1]],na.rm = T)
    sd2 <- sd(pwr[,value][pwr[,group]==group_list[2]],na.rm = T)
    s <- sqrt(((n1-1)*sd1^2+(n2-1)*sd2^2)/(n1+n2-2))

    if(method=="t.test"){
    mean1 <- mean(pwr[,value][pwr[,group]==group_list[1]],na.rm = T)
    mean2 <- mean(pwr[,value][pwr[,group]==group_list[2]],na.rm = T)
    colnames(pwr)[colnames(pwr)==variable]="variable"
    colnames(pwr)[colnames(pwr)==group]="group"
    colnames(pwr)[colnames(pwr)==value]="value"
    d <- (mean1-mean2)/s
    temp.test <- t.test(value~group,data = pwr)
    pwr_list[i,"p"] <- temp.test[["p.value"]]
    pwr_list[i,"pwr"] <- pwr.t2n.test(n1=n1,n2 = n2,d = d,sig.level = 0.05)[["power"]]}

    if(method=="wilcox"){
      library(rstatix)
      colnames(pwr)[colnames(pwr)==variable]="variable"
      colnames(pwr)[colnames(pwr)==group]="group"
      colnames(pwr)[colnames(pwr)==value]="value"
      temp.test <- wilcox.test(value~group,data = pwr)
      pwr_list[i,"p"] <- temp.test[["p.value"]]
      colnames(pwr_list)[which(colnames(pwr_list)=="pwr")] <- "effect size"
      pwr_list[i,"effect size"] <- wilcox_effsize(value ~ group, data = pwr)[,"effsize"]
    }
  }
  print(pwr_list)
}

data:melt类型的data。包括变量比如基因:variable,比较的两个不同组别:group,基因表达值value

group:t检验的两个分组

variable:多个不同的检验变量(比如比较多个基因在两个group之间的表达差异,这个variable就是多个基因)

value:variable对应的每个具体的value

method:默认t.test,除此之外还有wilcox(这个计算出来的就是effect size)

sig.level:检验的显著性水平,默认0.05

这种类型的数据就只需要pwr_my(data = data, group = "group",variable = "variable",value ="value" )

image

如果只有一个变量,没有那么多variable,只需要输入variable=“NULL”或者不输入,默认就是NULL。

如:pwr_my(data = data,value = "pyrscore",group = "pyr_group")

image

你可能感兴趣的:(sci审稿返回意见:power calculation)