Reputation: 31978
Non-statistician here trying to replicate some code in Python.
R has the function qchisq
.
qchisq(c(0.5, 0.1, 0.99), df=1, lower.tail=F)
# [1] 0.4549364231 2.7055434541 0.0001570879
It can be replicated in Python like so:
from scipy.special import chdtri
import pandas as pd
chdtri(1, pd.Series([0.5, 0.1, 0.99]))
# Out[57]:
# 0 0.454936
# 1 2.705543
# 2 0.000157
However, Rs qchisq
can also has the flag log.p
, which allows me to do:
qchisq(-c(0.5, 0.1, 0.99) * log(10), df=1, lower.tail=F, log.p=T)
# [1] 1.00448472 0.06796154 2.66885996
I cannot find any way to do this in Python. How do I achieve the same thing?
Upvotes: 3
Views: 206
Reputation: 3176
Perhaps it's useful to try to remake the effect of log.p
without setting the argument in R:
qchisq(.5, 1, lower.tail = FALSE)
# 0.4549364
qchisq(-.5, 1, lower.tail = FALSE, log.p = TRUE)
# 0.265258
qchisq(exp(-.5), 1, lower.tail = FALSE)
# 0.265258
Which gives for the part with log(10)
:
qchisq(exp(-c(0.5, 0.1, 0.99)*log(10)), df=1, lower.tail=F)
# [1] 1.00448472 0.06796154 2.66885996
So it seems qchisq(exp(x)) == qchisq(x, log.p = TRUE)
.
Upvotes: 3