[R] How to compute the P-value for a mixture of chi^2 distri

(Ted Harding) ted.harding at wlandres.net
Sun Jun 12 10:37:49 CEST 2011


On 12-Jun-11 01:36:00, Thomas Lumley wrote:
> On Sun, Jun 12, 2011 at 12:44 PM, Tiago Pereira
> <tiago.pereira at mbe.bio.br> wrote:
> 
>> The test I am working on has an asymptotic 0.5*chi2(1)+0.5*chi2(2)
>> distribution, where numbers inside parenthesis stand for the
>> degrees of freedom. Is is possible to compute quickly in R
>> the cumulative distribution of that distribution?
> 
> There appear to be pchibar() functions in both the ibdreg and ic.infer
> packages that should do want you want.  Simulation is also fairly
> efficient.
> 
>     -thomas
> 
> -- 
> Thomas Lumley
> Professor of Biostatistics
> University of Auckland

Is there anything wrong with the following argument:

In Tiago's notation, let X have the mixed chi2 distribution:

  X ~ chi2(1) with probability p
  X ~ chi2(2) with probability q = (1-p)

Then the cumulative distribution of X is

  Prob(X <= x) = p*Prob(chi2(1) <= x) + q*prob(chi2(2) <= x)

so the CDF is p*pchisq(x,1) + (1-p)*pchisq(x,2)

Inverting this to find the value of x for a given value P
of Prob(X <= x) = P is another matter, but should be reliably
solvable by using R's uniroot() function, with lower and
upper endpoints taken from whichever of qchisq(P,1), qchisq(P,2)
is smallest, and whichever is largest.

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at wlandres.net>
Fax-to-email: +44 (0)870 094 0861
Date: 12-Jun-11                                       Time: 09:37:46
------------------------------ XFMail ------------------------------



More information about the R-help mailing list