开发者

Error in rpy2- No (non-missing) observations

开发者 https://www.devze.com 2023-03-22 18:09 出处:网络
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 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, weigh开发者_运维百科ts, 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


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 the data with read.table, and it should be ok.

0

精彩评论

暂无评论...
验证码 换一张
取 消