linux&Perl&R  

R软件入门教程---秩和检验

单变量秩和检验

样本资料如下:15,12,14,32,12,15,11。已知总体均数为20。

 

程序如下:

          c(15,12,14,32,12,15,11)->x

          wilcox.test(x,mu=20,alternative=”two.sided”, conf.level = 0.95)

 

结果如下:Wilcoxon signed rank test with continuity correction

data:  x

V = 7, p-value = 0.2702

alternative hypothesis: true mu is not equal to 20

 输出p值为0.2702。

   

2、  配对设计资料的秩和检验

资料如下:

甲:12,14,15,12,21,31,26,21

          乙:21,32,15,21,12,14,12,15

 

程序如下:

          c(12,14,15,12,21,31,26,21)->x

          c(21,32,15,21,12,14,12,15)->y

          wilcox.test(x,y,paired=TRUE, conf.level = 0.95)

 

结果如下:

           Wilcoxon signed rank test with continuity correction

data:  x and y

V = 15, p-value = 0.9322

alternative hypothesis: true mu is not equal to 0

 

3、  成组设计资料的秩和检验

如资料同上,非配对设计:

甲:12,14,15,12,21,31,26,21

          乙:21,32,15,21,12,14,12,15

 

程序如下:

         c(12,14,15,12,21,31,26,21)->x

          c(21,32,15,21,12,14,12,15)->y

          wilcox.test(x,y,paired=FALSE, conf.level = 0.95)

 

结果如下:

          Wilcoxon rank sum test with continuity correction

data:  x and y

W = 34.5, p-value = 0.8305

alternative hypothesis: true mu is not equal to 0

 

T检验、秩和检验小结:

T检验、秩和检验的参数格式大致是一样的。

t.test ,wilcox.test(x,(y), alternative = ("two.sided", "less", "greater"),mu = …,

paired = (FALSE,TRUE), conf.level = 0.95)

     可以只有一个变量x,也可以有两个,alternative指定双侧还是单侧检验,mu指定总体均数,paired指定是否配对,conf.level指定检验水准。


via http://www.stathome.cn/html/S-plus_R/Rrumen/2009/0604/472.html 


读数据

data <- read.table("fpkm.matrix.log2",header=F,sep=" ")

转换成矩阵

data=as.matrix(data)

查看

ls.str()

做秩和检验

p=apply(x,1,function(x) wilcox.test(x[1:14],x[15:28])$p.value) 

写入文件

write.table(p,file="fpkm.matrix.pvalue")

计算值小于0.05的值

length(p[p<0.05])

多重检验

q=p*18065

整体出错概率小于0.05的值

length(q[q<0.05])

写文件

write.table(q,file="fpkm.matrix.qvalue")

via http://zhaoguoguang.blog.163.com/blog/static/18198620920118810614155/

2012-08-09 热度-1 R

评论

热度(1)

©linux&Perl&R Powered by LOFTER