Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

non-central chi-square probability and non-centrality parameter

Tags:

r

How can I get the value of the non-centrality parameter that gives a probability of exactly 0.9 for different critical values and degrees of freedom?

For example, with the significance level = 0.05 and 1 degree of freedom (critical value = 3.84), the ncp must be equal to 10.50742 in order to get a probability of 0.9:

1 - pchisq(3.841459, 1, 10.50742)
[1] 0.9
like image 864
vitor Avatar asked Aug 23 '13 03:08

vitor


1 Answers

Rearrange terms in: 1 - pchisq(3.841459, 1, 10.50742) = 0.9 and wrap abs around the result to construct a minimization function:

 optim( 1, function(x) abs(pchisq(3.841459, 1, x)  - 0.1) )
#-------
$par
[1] 10.50742

$value
[1] 1.740301e-08

$counts
function gradient 
      56       NA 

$convergence
[1] 0

$message
NULL

To do a sensitivity analysis, you can serially alter the values of the other parameters:

for( crit.val in seq(2.5, 3.5, by=0.1)) {
         print( optim( 1, 
                function(x) abs(pchisq(crit.val, 1, x)  - 0.1), 
                method="Brent" , lower=0, upper=20)$par)}
[1] 8.194852
[1] 8.375145
[1] 8.553901
[1] 8.731204
[1] 8.907135
[1] 9.081764
[1] 9.255156
[1] 9.427372
[1] 9.598467
[1] 9.768491
[1] 9.937492
like image 84
IRTFM Avatar answered Nov 14 '22 22:11

IRTFM