我试图将Stata模型移植到Python,并在Stata的centile
和Python的pandas.DataFrame.describe
之间找到一些差距:
我不知道他们是如何根据官方文件(http://www.stata.com/help.cgi?centile,http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.describe.html)来计算的。但当我在R中尝试相同的数据集时:
> quantile(d[, c('V1')], c(0.01, 0.99), type=5)
1% 99%
-0.1650828 0.1652275
> quantile(d[, c('V1')], c(0.01, 0.99), type=6)
1% 99%
-0.165701 0.168318
使用参数type=6
,结果似乎与Stata相同。分位数(https://stat.ethz.ch/R-manual/R-devel/library/stats/html/quantile.html)的API文档指示以下内容:
我找不到任何具有相同实现的现有Python库。在
如果您想要与R的分位数相同的结果,请使用
numpy.percentile
:多亏了罗伯托·费勒!我编写了一个基于http://www.stata.com/manuals13/rcentile.pdf的Python函数,它产生的结果与Stata相同:
相关问题 更多 >
编程相关推荐