# Re: [R] Mid-P value for a chi-squared test

From: Ted Harding <Ted.Harding_at_manchester.ac.uk>
Date: Sun, 13 Jun 2010 19:19:49 +0100 (BST)
```>> Can anyone tell me how to calculate a mid-p value for a chi-squared
>> test in R?
```

>
> I cannot see that this has been answered. It has a date from 12 days
> ago but I cannot see a reply in the archives.
>
> So, what is a "mid-p value" and which "chi-square test" are you asking
> about? A simple data setup in R code with expected output would speed
> this discussion along.
>
> David Winsemius, MD

The "mid-p value" is a device for improving the accuracy of a continuous approximation to a distribution which in reality is discrete.

Intuitively, the idea is to treat the discrete probabilities of the discrete distribution as if they were proportions in a histogram. Then imagine fitting a continuous curve (e.g. a chi-squared density) to the histogram. The fit (agreement between the proportion in one histogram bar, and the probability below that portion of the curve which lies in the same range) will be better if the curve goes through the midpoint of the top of the bar.

This leads to the formal definition:

"mid-P" = Prob(X > Xobs) + 0.5*Prob(X = Xobs)

A number of R functions use this idea. Check out what you get by going to http://finzi.psych.upenn.edu/nmz.html and entering "mid-p" into the search box, and see whether any of them match (or come close to) your particular case.

In the case of the chi-squared test, the idea is related to (but not the same as) the "Yates correction for continuity". chisq.test() has an option "correct=TRUE" to force this, but only for 2x2 tables.

Ted.

E-Mail: (Ted Harding) <Ted.Harding_at_manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861
```Date: 13-Jun-10                                       Time: 19:19:44
------------------------------ XFMail ------------------------------

______________________________________________
```
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 13 Jun 2010 - 18:23:52 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 13 Jun 2010 - 20:00:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.