R是Python中带有log.p参数的qchisq?

2024-05-23 21:41:39 发布

您现在位置:Python中文网/ 问答频道 /正文

非统计学家试图用Python复制一些代码。你知道吗

R具有函数qchisq。你知道吗

qchisq(c(0.5, 0.1, 0.99), df=1, lower.tail=F)
# [1] 0.4549364231 2.7055434541 0.0001570879

它可以在Python中复制,如下所示:

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

但是,Rsqchisq也可以有标志log.p,它允许我执行以下操作:

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

我在Python中找不到任何方法来实现这一点。我怎样才能达到同样的效果?你知道吗


Tags: 函数代码fromimportlogpandasdfscipy
1条回答
网友
1楼 · 发布于 2024-05-23 21:41:39

也许在不设置R参数的情况下重新生成log.p的效果是有用的:

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

对于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

看来qchisq(exp(x)) == qchisq(x, log.p = TRUE)。你知道吗

相关问题 更多 >