rpy2 中的错误 - 没有(非缺失)观察结果
我正在 Ubuntu 1104 上使用 rpy2。我正在遵循 COX 文件。文件中给出的步骤是在 R 中。我必须使用 rpy2 在 python 中执行相同的步骤。 我没有得到任何有关 rpy2 的教程。我设法写了以下内容,
from rpy2.robjects.packages import importr
from rpy2.robjects import IntVector, Formula
import rpy2.robjects as ro
cox = importr("survival")
csv = ro.vectors.DataFrame.from_csvfile('Rossi.txt', header=True, sep=' ')
fmla = Formula('Surv(week, arrest) ~ fin + age + race + wexp + mar + paro + prio')
mod_aalison = cox.coxph (fmla, data=csv)
但出现以下错误,
>>> mod_aalison = cox.coxph (fmla, data=csv)
Error in function (formula, data, weights, subset, na.action, init, control, :
No (non-missing) observations
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/rpy2/robjects/functions.py", line 83, in __call__
return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
File "/usr/lib/python2.7/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, weights, subset, na.action, init, control, :
No (non-missing) observations
我错过了什么吗?我之前没有 R 经验。 我不确定函数 coxph 中的数据是否必须采用数据帧格式。 任何帮助表示赞赏。
这是 Rossi.txt 的链接
I m working with rpy2 on Ubuntu 1104. I m following the COX file. The steps given in file are in R. I have to do same steps in python using rpy2.
I didn't get any tutorial with rpy2. I managed to write following,
from rpy2.robjects.packages import importr
from rpy2.robjects import IntVector, Formula
import rpy2.robjects as ro
cox = importr("survival")
csv = ro.vectors.DataFrame.from_csvfile('Rossi.txt', header=True, sep=' ')
fmla = Formula('Surv(week, arrest) ~ fin + age + race + wexp + mar + paro + prio')
mod_aalison = cox.coxph (fmla, data=csv)
But I'm getting following error,
>>> mod_aalison = cox.coxph (fmla, data=csv)
Error in function (formula, data, weights, subset, na.action, init, control, :
No (non-missing) observations
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/rpy2/robjects/functions.py", line 83, in __call__
return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
File "/usr/lib/python2.7/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, weights, subset, na.action, init, control, :
No (non-missing) observations
Am I missing any thing? I have no prior experience on R.
I'm not sure the if data in function coxph has to be in dataframe format.
Any help is appreciated.
This is link to Rossi.txt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
read.csv
读取数据,并将 sep 设置为单个空格,而文件有两个空格。这使得 R 将其解释为空列的存在,然后空列会与列名称混淆,最终在 coxph 中创建错误。用
read.table
读取数据,应该就可以了。You read the data using
read.csv
with sep set to a single space, while the file has two spaces. This makes R interpret this as an existence of empty columns, which then mess with column names and finally create error incoxph
.Read the data with
read.table
, and it should be ok.