简体   繁体   English

使用rpy2进行生存分析时出错

[英]Error running using rpy2 for survival analysis

I'm trying to perform survival analysis with R with rpy2 in ipython. 我正在尝试在ipython中使用rpy2用R执行生存分析。

The following formulation fails: 以下公式失败:

%Rpush df
surv_fit = surv.coxph("Surv(start, end, status) ~ x", data=df)
> RRuntimeError: Error: $ operator is invalid for atomic vectors

But if I do it all using r magic, it works: 但是,如果我全部使用r magic做到这一点,它将起作用:

%Rpush df
%R surv.fit <- coxph(Surv(start, end, status) ~ x, data=df)

Is there an issue with the Surv object? Surv对象有问题吗?

This is because %Rpush is pushing the variable to R. 这是因为%Rpush将变量推入R。

Your first example would then have to be: surv_fit = rpy2.robjects.r(""" surv.coxph(Surv(start, end, status) ~ x, data=df) """) 然后,您的第一个示例将是: surv_fit = rpy2.robjects.r(""" surv.coxph(Surv(start, end, status) ~ x, data=df) """)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM