Skip to content
Snippets Groups Projects
Commit e9e400cc authored by Samuel Mondy's avatar Samuel Mondy
Browse files

Deleted Chi_square test.r

parent 4119c92f
No related branches found
No related tags found
1 merge request!7Deleted Chi_square test.r
#########################################
#Perform a chi-squared test
#########################################
#b must be a matrix containing the sums of the occurences of the OTUs for each variable with variables as columns
#you should use the aggregate() function as done afterwards in the script of the function ensemble(a,b,name,OTUnumber)
###chi square test with only 2 variables
chi_sam<-function(b,seuil=0.05)
#########################################
#########################################
{
t<-apply(b,1,sum)
selec<-which(t>0)
b<-b[selec,]
t<-apply(b,2,sum)
selec<-which(t>0)
b<-b[,selec]
y<-chisq.test(b)
print(y)
print(y$expected)
print(y$observed)
print (y$p.value)
if(y$p.value<seuil)
{
if(dim(b)[2]>2)
{
z<-combn(dim(b)[2],2)
for(i in 1:dim(z)[2])
{
r<-b[,c(z[1,i],z[2,i])]
s<-apply(r,1,sum)
selec<-which(s>0)
r<-r[selec,]
x<-chisq.test(r)
#print(paste(colnames(b)[z[1,i]],colnames(b)[z[2,i]],sep=" vs "))
#print(x$expected)
#print(x$observed)
if(x$p.value<(seuil/dim(z)[2]))
{
print(paste(colnames(b)[z[1,i]],colnames(b)[z[2,i]],sep=" vs "))
print(x$p.value)
}
}
print(paste("corrected p-value ",(seuil/dim(z)[2]),sep=""))
}
else
{
print (y$p.value)
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment