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

David Winsemius dwinsemius at comcast.net
Sun Jun 13 21:47:59 CEST 2010


On Jun 13, 2010, at 2:19 PM, (Ted Harding) wrote:

> On 13-Jun-10 17:12:45, David Winsemius wrote:
>> On Jun 1, 2010, at 4:17 AM, Wilson, Andrew wrote:
>>
>>> 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)

Looking at Agresti and Gottard's piece, cited by one of the R  
functions, midPci {PropCIs} from a match to your suggested search  
strategy below, they say the lower mid-p CI would be defined as  
solving equation:

Pr_0L (X > x) + 1/2 x Pr_0L (X = x) = a/2.

Is that mathematically equivalent ( perhaps the NP "dual" to a p-value  
version) to what you offered? And is the upper CI then defined as  
solution to :

Pr_0U (X < x) + 1/2 x Pr_0U (X = x) = 1-a/2    ,,, ?

> 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.
>

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list