rpy2- No(不丢失)观察中的错误。

时间:2021-03-06 22:52:22

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,

我在Ubuntu 1104上与rpy2合作。我在跟踪考克斯文件。文件中给出的步骤在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)

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.

我漏掉什么了吗?我没有以前的经验,我不确定是否函数coxph中的数据必须以dataframe格式。任何帮助都是感激。

This is link to Rossi.txt

这是链接到Rossi.txt。

1 个解决方案

#1


2  

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 in coxph.

您可以使用read读取数据。带有sep的csv设置为一个空格,而文件有两个空格。这使得R将其解释为空列的存在,然后将列名称弄乱,最后在coxph中创建错误。

Read the data with read.table, and it should be ok.

读取数据并读取。桌子,应该没问题。

#1


2  

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 in coxph.

您可以使用read读取数据。带有sep的csv设置为一个空格,而文件有两个空格。这使得R将其解释为空列的存在,然后将列名称弄乱,最后在coxph中创建错误。

Read the data with read.table, and it should be ok.

读取数据并读取。桌子,应该没问题。