[BioC] chi squared test

James W. MacDonald jmacdon at med.umich.edu
Wed Jun 10 22:51:17 CEST 2009


Hi Hai-Ri,

Hai-Ri Li wrote:
> Hi everyone,
> 
> When I tried to use chisq.test or fisher.test in bioconductor, I always got
> higher p-value than that with other sources.

Both of these functions come as part of base R; they are not part of 
Bioconductor, so your question should be sent to r-help at r-project.org.

> 
> For example, I have two observed values 15 and 5 and two expected values 10
> and 10.
> 
> Using other sources such as Excel from Microsoft, I got p-value 0.025.
> 
> However, in bioconductor,
> 
> *chisq*.*test*(x=matrix(c(15,5,10,10),nc=2),correct=FALSE)
> 
> or
> 
>  *chisq*.*test*(x=matrix(c(15,10,5,10),nc=2),correct=FALSE)
> 
> p-value always is 0.1025.
> 
> Did I do something wrong?

Yes. Excel expects you to give it the observed _and_ expected values. R 
will calculate the expectation for you, so when you give those data to 
R, the assumption (as is explained in the help page for chisq.test) is 
that you are giving it a two-by-two table of observed counts.

 > z <- chisq.test(matrix(c(15,10,5,10), nc=2), correct=F)
 > z$expected
      [,1] [,2]
[1,] 12.5  7.5
[2,] 12.5  7.5

So if you put

15  5
10  10

In e.g. A1:B2 of an Excel spreadsheet and

12.5 7.5
12.5 7.5

in A3:B4 and then do =chitest(A1:B2,A3:B4)

you will get 0.10247, just like in R.

Best,

Jim


> 
> Please tell me why there is big difference in p-value. How can I get low
> p-value in bioconductor?
> 
> Thanks,
> 
> Hai-Ri
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor

-- 
James W. MacDonald, M.S.
Biostatistician
Douglas Lab
University of Michigan
Department of Human Genetics
5912 Buhl
1241 E. Catherine St.
Ann Arbor MI 48109-5618
734-615-7826



More information about the Bioconductor mailing list