我正在尝试使用 numpy 数组中的 rpy2 拟合非线性曲线,但由于我不知道如何在 R 端传递“开始”参数而被卡住。我使用 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)