Re: [R] exact goodness-of-fit test

From: Spencer Graves <spencer.graves_at_pdf.com>
Date: Sun 07 Aug 2005 - 12:31:41 EST

          I don't know of an existing R function to do this. However, it should not be too hard, especially if I had only one with the numbers you gave. I'd compute the observed chi-square, then construct a series of 4 nested "for" loops to generate all 5969040 = 22!/(15! 0! 3! 4!) possible outcomes that sum to 22, compute the chi-square for each, and count how many have a chi-square at least as extreme as what you observed. If I wanted a general algorithm, that would take more work.

          If you'd like more help than this, PLEASE do read the posting guide! "http://www.R-project.org/posting-guide.html", show us your code and where you got stuck.

          spencer graves

Christine Adrion wrote:

> Hello,
>
> I have a question concerning the R-function chisq.test.
>
> For example, I have some count data which can be categorized as follows
> class1: 15 observations
> class2: 0 observations
> class3: 3 observations
> class4: 4 observations
>
> I would like to test the hypothesis whether the population probabilities are all equal (=> Test for discrete uniform distribution)
> If you have a small sample size and therefore a sparse (1xr)-table, then assumptions for chisquare-goodness-of-fit test are violated (the numbers expected are less than 5 in more than 75% of the entries.)
>
> ####### R-Program: Chisquare-Test :#########
>
> mydata <- c(15,0,3,4)
> chisq.test(mydata, correct=TRUE, rescale.p = TRUE, simulate.p.value = TRUE, B = 2000)
>
>
> As you cannot ignore the small sample size, I use 'simulate.p.value' is 'TRUE' and therefore the p-value is computed by Monte Carlo simulation with 'B' replicates.
> But is it also the possible to use an EXACT version of a chisquare goodness-of-fit test without a Monte-Carlo-simulation? How can I calculate this in R?
>
>
>
> Any hint would be appreciated,
> Regards,
> Christine Adrion
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

-- 
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA

spencer.graves@pdf.com
www.pdf.com <http://www.pdf.com>
Tel:  408-938-4420
Fax: 408-280-7915

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sun Aug 07 12:37:37 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:07:50 EST