gpt4 book ai didi

用于 Beta 发行版的 R fitdistr : which starting parameters?

转载 作者:行者123 更新时间:2023-12-01 05:58:21 24 4
gpt4 key购买 nike

我需要将数据拟合到 Beta 分布并检索 alpha 参数。我正在尝试使用 python (rpy2) 中的 R,我的代码如下所示:

from rpy2 import *
from rpy2.robjects.packages import importr
MASS = importr('MASS') #myVector is a Numpy array with values between 0 and 1
MASS.fitdistr(myVector,"beta")

但我收到此错误:

Error in function (x, densfun, start, ...)  : 
'start' must be a named list
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, ...) :
'start' must be a named list

我似乎找不到任何带有详细示例的 R 好的文档,所以我只找到了 this :

start A named list giving the parameters to be optimized with initial values. This can be omitted for some of the named distributions (see Details). ... Additional parameters, either for densfun or for optim. In particular, it can be used to specify bounds via lower or upper or both. If arguments of densfun (or the density function corresponding to a character-string specification) are included they will be held fixed.

我真的不知道:

  • 将什么作为起始参数以及这将如何影响我的估计
  • 在 Python 中使用什么语法,因为 start=list(shape1=0.5, shape2=0.5) 不起作用

有什么提示吗?

最佳答案

好吧,经过一番挖掘,我找到了解决方案:

from rpy2.robjects import DataFrame
starter= DataFrame({'shape1':0.5,'shape2':0.5})
x = MASS.fitdistr(myValues, "beta", start=starter))

关于用于 Beta 发行版的 R fitdistr : which starting parameters?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11544660/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com