Monday, August 9, 2010

Chi square:: SMKP

Source data is from LUNG project


V1V3.GENERA.CHISQ.SMK<-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.GENERA.CHISQ.SMK[8,col]=="Y")
{
if(as.numeric(V1V3.GENERA.CHISQ.SMK[row,col])!=0)
a=a+1
if(as.numeric(V1V3.GENERA.CHISQ.SMK[row,col])==0)
b=b+1
}
}
k=k+a
l=l+b

for( col in 2:41)
{
if(V1V3.GENERA.CHISQ.SMK[8,col]=="N")
{
if(as.numeric(V1V3.GENERA.CHISQ.SMK[row,col])!=0)
c=c+1
if(as.numeric(V1V3.GENERA.CHISQ.SMK[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.GENERA.CHISQ.SMK[row,1],a,b,c,d,hh, file="/home/student/test/V1V3.genera.CHISQSMK.txt", fill=TRUE,sep="\t",
append=TRUE)

if(hh<=0.05)
{
cat(V1V3.GENERA.CHISQ.SMK[row,1],a,b,c,d,hh, file="/home/student/test/V1V3.genera.CHISQ.SMK.SIG.txt", fill=TRUE,sep="\t",
append=TRUE)
}


}

X<-as.matrix(read.table("/home/student/test/V1V3.genera.CHISQSMK.txt"))
colnames(X)<-c("BACTERIA","SMKPBP","SMKPBA","SMKABP","SMKABA","P.VALUE")
write.table(X, file="/home/student/test/V1V3.genera.CHISQSMKcolumn.txt",sep="\t",append=TRUE,quote=FALSE,row.names=FALSE)

Y<-as.matrix(read.table("/home/student/test/V1V3.genera.CHISQ.SMK.SIG.txt"))
colnames(Y)<-c("BACTERIA","SMKPBP","SMKPBA","SMKABP","SMKABA","P.VALUE")
write.table(Y, file="/home/student/test/V1V3.GENERA.CHISQ.SMK.SIG.column.txt",sep="\t",append=TRUE,quote=FALSE,row.names=FALSE)

No comments:

Post a Comment