【发布时间】:2012-07-17 12:21:50
【问题描述】:
我需要将我的数据放入 Beta 分布并检索 alpha 参数。
我一直在用 Python 编写代码,但在 SciPy 中似乎没有任何 beta 拟合函数。要么我在我不太熟悉的 Matlab 中做所有事情,要么在 Python 中使用 R 及其fitdistr 函数。所以我选择了后者。
from rpy2.robjects.packages import importr
MASS = importr('MASS')
然后我在 [0,1) 范围内获取浮点数的 numpy 向量,并将其传递给 fitdistr:
myVector = myVector.tolist()
MASS.fitdistr(myVector,"beta")
太糟糕了,它需要某种其他向量。 rpy 和 rpy2 不是应该为我做所有的转换吗?
Error in function (x, densfun, start, ...) :
'x' must be a non-empty numeric vector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/rpy2/robjects/functions.py", line 82, in __call__
return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/rpy2/robjects/functions.py", line 34, in __call__
res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error in function (x, densfun, start, ...) :
'x' must be a non-empty numeric vector
我需要在这里做什么?
【问题讨论】: