Tiago V. Pereira
2013-Jun-01 04:26 UTC
[R] How to compute a P-value for a complex mixture of chi-squared distributions in R
Hello, R users! I am struggling with the following problem: I need to compute a P-value for a mixture of two chi-squared distributions. My P-value is given by: P = 0.5*prob(sqrt(chi2(1)) <= x) + 0.5*prob(sqrt(chi2(2)) <= x) In words, I need to compute the p-value for 50?50 mixture of the square root of a chi-squared random variable with 1 degree of freedom and the square root of a chi-squared with two degrees of freedom. Although I can quickly simulate data, the P-values I am looking for are at the tail of the distribution, that is, alpha levels below 10^-7. Hence, simulation is not efficient. Are you aware of smart approach? All the best, Tiago
Tiago V. Pereira
2013-Jun-01 04:32 UTC
[R] How to compute a P-value for a complex mixture of chi-squared distributions in R
Hello, R users! I am struggling with the following problem: I need to compute a P-value for a mixture of two chi-squared distributions. My P-value is given by: P = 0.5*prob(sqrt(chi2(1)) <= x) + 0.5*prob(sqrt(chi2(2)) <= x) In words, I need to compute the p-value for 50?50 mixture of the square root of a chi-squared random variable with 1 degree of freedom and the square root of a chi-squared with two degrees of freedom. Although I can quickly simulate data, the P-values I am looking for are at the tail of the distribution, that is, alpha levels below 10^-7. Hence, simulation is not efficient. Are you aware of smart approach? All the best, Tiago
Rui Barradas
2013-Jun-01 10:13 UTC
[R] How to compute a P-value for a complex mixture of chi-squared distributions in R
Hello,
Try the following.
dmix <- function(x){
dens <- function(x, df) dchisq(x^2, df = df)*2*x
0.5*dens(x, df = 1) + 0.5*dens(x, df = 2)
}
pmix <- function(x, lower.tail = TRUE){
p <- integrate(dmix, lower = 0, upper = x)
if(lower.tail) p$value else 1 - p$value
}
quant <- 1
pmix(quant, lower.tail = FALSE)
Hope this helps,
Rui Barradas
Em 01-06-2013 05:26, Tiago V. Pereira escreveu:> Hello, R users!
>
> I am struggling with the following problem:
>
> I need to compute a P-value for a mixture of two chi-squared
> distributions. My P-value is given by:
>
> P = 0.5*prob(sqrt(chi2(1)) <= x) + 0.5*prob(sqrt(chi2(2)) <= x)
>
> In words, I need to compute the p-value for 50?50 mixture of the square
> root of a chi-squared random variable with 1 degree of freedom and the
> square root of a chi-squared with two degrees of freedom.
>
> Although I can quickly simulate data, the P-values I am looking for are at
> the tail of the distribution, that is, alpha levels below 10^-7. Hence,
> simulation is not efficient.
>
> Are you aware of smart approach?
>
>
> All the best,
>
> Tiago
>
> ______________________________________________
> 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.
>
Terry Therneau
2013-Jun-03 12:11 UTC
[R] How to compute a P-value for a complex mixture of chi-squared distributions in R
You need to be more explicit about what you are doing.
For this problem:
y = (x1 + x2)/2
where x1 and x2 are chi-square random variables, you want to use the pchisqsum()
routine
found in the survey package. This is not a trivial computation.
For the alternate problem where y is a random choice of either x1 or x2
y = ifelse(z, x1, x2)
z is binomial and x1, x2 are chisq, then the suggestion by Peter Dalgaard is
correct.
Which of these two are you trying to solve?
Terry Therneau
On 06/02/2013 05:00 AM, r-help-request at r-project.org
wrote:> Em 01-06-2013 05:26, Tiago V. Pereira escreveu:
>> > Hello, R users!
>> >
>> > I am struggling with the following problem:
>> >
>> > I need to compute a P-value for a mixture of two chi-squared
>> > distributions. My P-value is given by:
>> >
>> > P = 0.5*prob(sqrt(chi2(1))<= x) + 0.5*prob(sqrt(chi2(2))<=
x)
>> >
>> > In words, I need to compute the p-value for 50?50 mixture of the
square
>> > root of a chi-squared random variable with 1 degree of freedom
and the
>> > square root of a chi-squared with two degrees of freedom.
>> >
>> > Although I can quickly simulate data, the P-values I am looking
for are at
>> > the tail of the distribution, that is, alpha levels below 10^-7.
Hence,
>> > simulation is not efficient.
>> >
>> > Are you aware of smart approach?
>> >
>> >
>> > All the best,
>> >
>> > Tiago
>> >
Duncan Murdoch
2014-May-22 12:44 UTC
[R] How to compute a P-value for a complex mixture of chi-squared distributions in R
On 01/06/2013, 12:26 AM, Tiago V. Pereira wrote:> Hello, R users! > > I am struggling with the following problem: > > I need to compute a P-value for a mixture of two chi-squared > distributions. My P-value is given by: > > P = 0.5*prob(sqrt(chi2(1)) <= x) + 0.5*prob(sqrt(chi2(2)) <= x)Isn't this simply 0.5*pchisq(x^2, df=1) + 0.5*pchisq(x^2, df=2) ? Duncan Murdoch> > In words, I need to compute the p-value for 50?50 mixture of the square > root of a chi-squared random variable with 1 degree of freedom and the > square root of a chi-squared with two degrees of freedom. > > Although I can quickly simulate data, the P-values I am looking for are at > the tail of the distribution, that is, alpha levels below 10^-7. Hence, > simulation is not efficient. > > Are you aware of smart approach? > > > All the best, > > Tiago > > ______________________________________________ > 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. >