美文网首页
2023-11-10 | Wilcoxon秩和检验+小提琴图&箱

2023-11-10 | Wilcoxon秩和检验+小提琴图&箱

作者: 千万别加香菜 | 来源:发表于2023-11-09 17:48 被阅读0次
    Wilcoxon秩和检验,英文为Wilcoxon rank-sum test,用于检查两组数据平均值是否有显著性

    可以看作非独立样本 t 检验的一种非参数替代方法

    如果数据无法满足 t 检验或者方差分析的假设,例如变量呈明显的偏态分布,或者组间不具有方差齐性,我们可以采用非参数方法。
    对于两组非独立样本,可以使用 Wilcoxon 符号秩和检验来评估观测值是否是从相同的分布中抽得的。

    all = read.table("all-cnv.windowed.weir.fst",header=T)
    select = read.table("CNV-selection.windowed.weir.fst",header=T)
    
    x = all$WEIGHTED_FST
    y = select$WEIGHTED_FST
    wilcox.test(x,y,alternative="less",exact=FALSE,correct=FALSE)
    
    小提琴图(内部包含箱线图)
    library(ggplot2)
    library(ggthemes)
    a=read.table("chart-selection_all-CNV.txt",header=T)
    
    ggplot(a,aes(x=G,y=FST, fill=G))+
      geom_violin()+
      geom_boxplot(fill = "white",  size = 1,  width = .2)+
      geom_hline(yintercept = 0.4318, linetype = "dashed", color = "black")+
      labs(x="",y=expression(paste(italic('F')[ST],'-SNP')))+
      theme_few()+
      theme(legend.position = "none")+
      theme(axis.text = element_text(face="bold"))
    
    image.png

    或者使用ggpval在ggplot2图形上简单快速添加统计P值

    library(ggpval) 
    
    ## 默认为Wilcoxon秩和检验
    add_pval(p, pairs = list(c(1, 2)), response = 'FST')
    # p 为之前的绘图函数
    # 指定1组和2组进行比较
    # response指哪一列进行检验
    
    # 除了添加P值外,还可以指定文本注释,当指定添加文本注释时,统计检验不会进行
    add_pval(p, pairs = list(c(1, 2)), response = 'FST',
             annotation = "指定文本注释")
    

    相关文章

      网友评论

          本文标题:2023-11-10 | Wilcoxon秩和检验+小提琴图&箱

          本文链接:https://www.haomeiwen.com/subject/gvncwdtx.html