R语言计算FDRp-value

Python012

R语言计算FDRp-value,第1张

data <- read.table("./FPKM.txt",sep = '\t',header = T)

p1 <-as.matrix(p_value) 

p2 <-as.vector(p1)#格式转换

 p2

p_adjust <- p.adjust(p2,method = "BH")

最新版的r语言没有方差分析表格的解决方法如下:

ANOVA对各疗法的F检验表明,4种药品用于缓解术后疼痛的疗效不同,但是并不能得出哪种药品疗法与其他不同。

多重比较可以解决这个问题.e.g. TukeyHSD()函数提供了对各组均值差异的成对检验;multcomp包中的glht()函数提供了多重均值比较更为全面的方法,既适用于线性模型,也适用于广义线性模型;多重t检验方法针对每组数据进行t检验。代码如下: TukeyHSD(medicine.aov) #par()函数旋转轴标签,增大左边界面积,使标签摆放更美观。 par(las = 2) par(mar = c(5, 8, 4, 2)) plot(TukeyHSD(medicine.aov))

图形中置信区间包含0的药品对比,说明差异不显著。 library(multcomp) #为适合字母阵列摆放,par语句用来增大顶部边界面积 par(mar = c(5, 4, 6, 2)) tuk <- glht(medicine.aov, linfct = mcp(Treatment = "Tukey")) #cld()函数中level选项为设置的显著性水平(这里的0.05对应95%置信区间) plot(cld(tuk, level = 0.05), col = "lightgrey")

有相同字母的组(用箱线图表示)说明均值差异不显著。

多次重复使用t检验会增大犯第一类错误的概率,为了克服这一缺点,需要调整p-值。R软件调整p-值用的是p.adjust()函数,函数使用的不同参数代表不同的调整方法。 attach(medicine) #求数据在各水平下的均值 mu<-c(mean(Response[Treatment==1]), mean(Response[Treatment==2]), mean(Response[Treatment==3]),mean(Response[Treatment==4]))mu #作多重t检验。这里用到的pairwise.t.test()函数用来得到多重比较的p值 pairwise.t.test(Response, Treatment, p.adjust.method = "none")

#观察两个作调整后的p值的情况。p.adjust.method()函数的参数也可换为"hochberg","hommel","bonferroni","BH","BY","fdr"等。 pairwise.t.test(Response, Treatment, p.adjust.method = "holm") #绘制箱线图 plot(medicine$Response~medicine$Treatment)

命令如下:

p<-c(0.001315146,0.001236789,0.001229388,0.000889006,0.000876515,0.000578648,0.000565415,0.000536447,0.000517434,0.000487215,0.000364518,0.000364518,0.000247193,7.93E-05)

p.adjust(p,method=”fdr”,n=length(p))

这样得到的修正后的fdr值为:

0.0013151460,0.0013151460,0.0013151460,0.0011314622,0.0011314622,0.0009001191,0.0009001191,

0.0009001191,0.0009001191,0.0009001191,0.0009001191,0.0009001191,0.0009001191,0.0009001191

可以看到,修正前后面几个P值并不相等,但是修正后的fdr后面几个都变一样的值了。

而且根据fdr的定义,用命令length(p)*p/rank(p)计算出来的结果也和用命令p.adjust(“fdr”)计算出来的结果不一样。