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
On 22 May 2014, at 14:44 , Duncan Murdoch murdoch.dun...@gmail.com wrote:
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
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
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
}
Hello,
Or, if you want to pass a vector of quantiles to pmix,
pmix - function(x, lower.tail = TRUE){
p - sapply(x, function(.x) integrate(dmix, lower = 0, upper =
.x)$value)
if(lower.tail) p else 1 - p
}
Rui Barradas
Em 01-06-2013 11:13, Rui Barradas escreveu:
Hello,
Try
On Jun 1, 2013, at 06:32 , 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)
In words,
Hello,
No, nothing wrong. (I feel silly for not having noticed it.) In fact not
only it's much simpler but it's also more accurate than the use of
accurate with the default rel.tol.
It should be better, however, to use lower.tail = FALSE, since the op
wants p-values.
0.5 * pchisq(x^2, 1,
Thank you very much, Rui and Peter, for you detailed and helpful tips!
It worked like a charm! I would spend more two weeks (or more) to figure
out that by myself.
Cheers!
Tiago
Hello,
No, nothing wrong. (I feel silly for not having noticed it.) In fact not
only it's much simpler but it's
Inline.
Em 01-06-2013 19:41, Rui Barradas escreveu:
Hello,
No, nothing wrong. (I feel silly for not having noticed it.) In fact not
only it's much simpler but it's also more accurate than the use of
accurate with the default rel.tol.
Correction: ...than the use of _integrate()_ with the
9 matches
Mail list logo