rpy2 问题,nls 将 list() 作为参数从 python 传递到 R

发布于 2024-10-29 03:43:45 字数 1544 浏览 1 评论 0原文

我正在尝试使用 numpy 数组中的 rpy2 拟合非线性曲线,但由于我不知道如何在 R 端传递“start”参数而陷入困境。我使用 R 2.12.1 和 python 2.6.6

Error in function (formula, data = parent.frame(), start, control = nls.control(),  : 
parameters without starting value in 'data': responsev, predictorv
Traceback (most recent call last):
File "./employmentsHoro.py", line 279, in <module>
nls.nls2(formula=formula, data=dataf, start=mylist)
File "/usr/lib/python2.6/dist-packages/rpy2/robjects/functions.py", line 83, in __call__
return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
File "/usr/lib/python2.6/dist-packages/rpy2/robjects/functions.py", line 35, in __call__
res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error in function (formula, data = parent.frame(),start, control = nls.control(),  : 
parameters without starting value in 'data': responsev, predictorv

谁能帮我确定如何将 list() 对象传递给 nls 公式?

我的代码的相关部分是这样的:

import rpy2.robjects as robjects
from rpy2.robjects import DataFrame, Formula
import rpy2.robjects.numpy2ri as npr
import numpy as np
from rpy2.robjects.packages import importr
nls = importr('nls2')
stats = importr('stats')

mylist = robjects.r('list(a=700,b=0.8,c=200000)')

dataf = DataFrame({'responsev': professions, 'predictorv': totalEmployment})
starter= DataFrame({'a':700,'b':0.80,'c':200000})
formula = Formula('responsev ~I( a*(predictorv/c)^b )/( 1+( predictorv/c )^b )')
nls.nls2(formula=formula, data=dataf, start=starter)

I am trying to fit a nonlinear curve using rpy2 from numpy array, but are stuck as I do not know how to pass the 'start' argument on the R side. I use R 2.12.1 and python 2.6.6

Error in function (formula, data = parent.frame(), start, control = nls.control(),  : 
parameters without starting value in 'data': responsev, predictorv
Traceback (most recent call last):
File "./employmentsHoro.py", line 279, in <module>
nls.nls2(formula=formula, data=dataf, start=mylist)
File "/usr/lib/python2.6/dist-packages/rpy2/robjects/functions.py", line 83, in __call__
return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
File "/usr/lib/python2.6/dist-packages/rpy2/robjects/functions.py", line 35, in __call__
res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error in function (formula, data = parent.frame(),start, control = nls.control(),  : 
parameters without starting value in 'data': responsev, predictorv

Can anyone help me determine how to pass a list() object to the nls formula?

the relevant part of my code is this:

import rpy2.robjects as robjects
from rpy2.robjects import DataFrame, Formula
import rpy2.robjects.numpy2ri as npr
import numpy as np
from rpy2.robjects.packages import importr
nls = importr('nls2')
stats = importr('stats')

mylist = robjects.r('list(a=700,b=0.8,c=200000)')

dataf = DataFrame({'responsev': professions, 'predictorv': totalEmployment})
starter= DataFrame({'a':700,'b':0.80,'c':200000})
formula = Formula('responsev ~I( a*(predictorv/c)^b )/( 1+( predictorv/c )^b )')
nls.nls2(formula=formula, data=dataf, start=starter)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与往事干杯 2024-11-05 03:43:45

主要错误是这个:

Error in function (formula, data = parent.frame(), start, control = 
nls.control(),  : parameters without starting value in 
    'data': responsev, predictorv

变量专业在哪里声明的?和数据就业?
似乎它们没有起始值,也许你必须改变/转换 R 的东西
明白吗?

The main error is this one:

Error in function (formula, data = parent.frame(), start, control = 
nls.control(),  : parameters without starting value in 
    'data': responsev, predictorv

Where are declared the variable professions? and DataEmployment?
seems they don't have a starting value, maybe you have to change/transform in something that R
understands?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文