在rpy2中运行stlm时出错

时间:2018-08-20 09:23:02

标签: python r rpy2

我正在尝试使用rpy2中R Forecast软件包中的stlm函数。但是,我不断收到以下错误。

traindf = https://vincentarelbundock.github.io/Rdatasets/csv/datasets/UKgas.csv

代码:     将熊猫作为pd导入     从rpy2.robjects.packages导入导入器

ts=robjects.r('ts')
forecast=importr('forecast', lib_loc= '/dp/softwares/rstudio/r_lib/')

from rpy2.robjects import pandas2ri
pandas2ri.activate()


traindf = 'link to dataset is above'

rdata=ts(traindf.value.values,frequency=4)
forecast.stlm(rdata, s_window = "periodic" , robust = True , method = "ets")

输出:

/dp/softwares/anaconda3/lib/python3.6/site-packages/rpy2/rinterface/__init__.py:146: RRuntimeWarning:

Error in if (ncol(x) == 1L) { : missing value where TRUE/FALSE needed


---------------------------------------------------------------------------
RRuntimeError                             Traceback (most recent call last)
<ipython-input-447-07765a4d01cf> in <module>()
      6 # stepwise = False)
      7 # forecast.ets(rdata,model = "ZZA" , opt_crit = "amse")
----> 8 forecast.stlm(rdata, s_window = "periodic" , robust = True , method = >"ets")

/dp/softwares/anaconda3/lib/python3.6/site-packages/rpy2/robjects/functions.py >in __call__(self, *args, **kwargs)
    176                 v = kwargs.pop(k)
    177                 kwargs[r_k] = v
--> 178         return super(SignatureTranslatedFunction, self).__call__(*args, >**kwargs)
    179 
    180 pattern_link = re.compile(r'\\link\{(.+?)\}')>

/dp/softwares/anaconda3/lib/python3.6/site-packages/rpy2/robjects/functions.py >in __call__(self, *args, **kwargs)
    104         for k, v in kwargs.items():
    105             new_kwargs[k] = conversion.py2ri(v)
--> 106         res = super(Function, self).__call__(*new_args, **new_kwargs)
    107         res = conversion.ri2ro(res)
    108         return res

RRuntimeError: Error in if (ncol(x) == 1L) { : missing value where TRUE/FALSE >needed

我已经在Google上寻找类似的问题,并且提到评估缺失值(NA)是一个问题(需要一个数字)。

但是,我不确定如何解决此问题。 感谢您的帮助。

0 个答案:

没有答案