Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R's qchisq in Python with the log.p argument?

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?

like image 991
The Unfun Cat Avatar asked Jan 31 '26 21:01

The Unfun Cat


1 Answers

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).

like image 166
Vandenman Avatar answered Feb 02 '26 10:02

Vandenman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!