From berwin at maths.uwa.edu.au  Mon Nov 17 09:23:03 2008
From: berwin at maths.uwa.edu.au (Berwin A Turlach)
Date: Mon, 17 Nov 2008 16:23:03 +0800
Subject: [Rd] chisq.test with simulate.p.value=TRUE (PR#13292)
In-Reply-To: <20081116000009.8029A2834615@mail.pubhealth.ku.dk>
References: <20081116000009.8029A2834615@mail.pubhealth.ku.dk>
Message-ID: <20081117162303.2f434889@berwin-nus1>

G'day Reginaldo, 

On Sun, 16 Nov 2008 01:00:09 +0100 (CET)
constant at unb.br wrote:

> Full_Name: Reginaldo Constantino
> Version: 2.8.0
> OS: Ubuntu Hardy (32 bit, kernel 2.6.24)
> Submission from: (NULL) (189.61.88.2)
> 
> 
> For many tables, chisq.test with simulate.p.value=TRUE gives a p
> value that is obviously incorrect and inversely proportional to the
> number of replicates:

Why is this Monte-Carlo p-value obviously incorrect?  

In your example, did you look at the observed ChiSquare statistics?
Any idea how likely it is to observe a value that is at least as
extreme as the one observed?

Essentially, you are doing B Monte-Carlo simulations and in none of
these simulations do you obtain a statistic that is at least as extreme
as the one that you have observed.  So your Monte-Carlo p-value ends up
to be 1/(B+1).  

I do not see any problem or bug here.

> > data(HairEyeColor)
> > x <- margin.table(HairEyeColor, c(1, 2))
> > chisq.test(x,simulate.p.value=TRUE,B=2000)
>         Pearson's Chi-squared test with simulated p-value (based on
> 2000 replicates)
> data:  x
> X-squared = 138.2898, df = NA, p-value = 0.0004998
> 
> > chisq.test(x,simulate.p.value=TRUE,B=10000)
> X-squared = 138.2898, df = NA, p-value = 1e-04
> 
> > chisq.test(x,simulate.p.value=TRUE,B=100000)
> X-squared = 138.2898, df = NA, p-value = 1e-05
> 
> > chisq.test(x,simulate.p.value=TRUE,B=1000000)
> X-squared = 138.2898, df = NA, p-value = 1e-06
> ...
> 
> Also tested the same R version under Windows XP and got the same
> results.

Cheers,

	Berwin

=========================== Full address =============================
Berwin A Turlach                            Tel.: +65 6516 4416 (secr)
Dept of Statistics and Applied Probability        +65 6516 6650 (self)
Faculty of Science                          FAX : +65 6872 3919       
National University of Singapore     
6 Science Drive 2, Blk S16, Level 7          e-mail: statba at nus.edu.sg
Singapore 117546                    http://www.stat.nus.edu.sg/~statba



[Rd] chisq.test with simulate.p.value=TRUE (PR#13292)
Berwin A Turlach