简体   繁体   中英

Error running using rpy2 for survival analysis

I'm trying to perform survival analysis with R with rpy2 in ipython.

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:

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

Is there an issue with the Surv object?

This is because %Rpush is pushing the variable to R.

Your first example would then have to be: surv_fit = rpy2.robjects.r(""" surv.coxph(Surv(start, end, status) ~ x, data=df) """)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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