diff --git a/Chi_square_test b/Chi_square_test
new file mode 100644
index 0000000000000000000000000000000000000000..6a865e5c43990d2a1c42c54ed0019a507edea867
--- /dev/null
+++ b/Chi_square_test
@@ -0,0 +1,55 @@
+#########################################
+#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)
+    }
+  }
+}