Tuesday, August 3, 2010

R::CHISQ TEST

V1V3.GEN.CHISQ.HIV<-as.matrix(read.csv("/home/student/test/V1V3.genera.csv",sep=",")) k<-0;l<-0;m<-0;n<-0;u<-0;v<-0;g<-0;h<-0 for(row in 10:221) { a<-0;b<-0;c<-0;d<-0; for( col in 2:41) { if(V1V3.GEN.CHISQ.HIV[7,col]=="Y") { if(as.numeric(V1V3.GEN.CHISQ.HIV[row,col])!=0) a=a+1 if(as.numeric(V1V3.GEN.CHISQ.HIV[row,col])==0) b=b+1 } } k=k+a l=l+b for( col in 2:41) { if(V1V3.GEN.CHISQ.HIV[7,col]=="N") { if(as.numeric(V1V3.GEN.CHISQ.HIV[row,col])!=0) c=c+1 if(as.numeric(V1V3.GEN.CHISQ.HIV[row,col])==0) d=d+1 } } m=m+c n=n+d hmat<-matrix(c(a,c,b,d),2) hh<-chisq.test(hmat,correct=FALSE)$p.value cat(V1V3.GEN.CHISQ.HIV[row,1],a,b,c,d,hh,file="/home/student/test/V1V3.genera.CHISQHIV.txt", fill=TRUE,sep="\t", append=TRUE) if(hh<=0.05) { cat(V1V3.GEN.CHISQ.HIV[row,1],a,b,c,d,hh,file="/home/student/test/V1V3.GENERA.CHISQHIV.SIG.txt", fill=TRUE,sep="\t", append=TRUE) } } X<-as.matrix(read.table("/home/student/test/V1V3.genera.CHISQHIV.txt")) colnames(X)<-c("BACTERIA","HIVPBP","HIVPBA","HIVABP","HIVABA","P.VALUE") write.table(X, file="/home/student/test/V1V3.genera.CHISQHIV.column.txt",sep="\t",append=TRUE,quote=FALSE,row.names=FALSE) Y<-as.matrix(read.table("/home/student/test/V1V3.genera.CHISQHIV.SIG.txt")) colnames(Y)<-c("BACTERIA","HIVPBP","HIVPBA","HIVABP","HIVABA","P.VALUE") write.table(Y, file="/home/student/test/V1V3.GENERA.CHISQ.HIV.SIG.column.txt",sep="\t",append=TRUE,quote=FALSE,row.names=FALSE) > x<-matrix(c(73,68,77,72,68,64,62,62,72,71),2) > x
[,1] [,2] [,3] [,4] [,5]
[1,] 73 77 68 62 72
[2,] 68 72 64 62 71
> chisq.test(x,correct=F)

Pearson's Chi-squared test

data: x
X-squared = 0.1468, df = 4, p-value = 0.9974

No comments:

Post a Comment