如何解决使用Publish包导出cox回归结果时出错无法将类““ summary.regressionTable””强制转换为data.frame
我正在尝试单变量cox回归并将结果从“发布”包导出到.csv文件,但是我遇到了这些错误
as.data.frame.default(x [[i]],可选= TRUE,stringsAsFactors = stringsAsFactors)中的错误: 无法将类别“ summary.regressionTable”强制转换为data.frame
我尝试了这里提到的另一种方法 (Export coxph summary from R to csv) 但这给了我这个错误
假设以下是我的数据框和使用的代码,请告诉我您的宝贵意见。感谢您的努力。
data<-read.table(text="time status age gender race
15 1 70 f white
70 0 60 m black
212 1 65 m others
10 0 45 m black
20 1 30 f others
14 0 27 f white
36 0 65 m white
20.37097957 0 45 m white
44.01586607 1 30 f white
51.29873743 0 27 f white
8.253579038 1 70 f white
58.49852945 0 60 f white
32.44848147 1 65 m white
57.93159063 0 70 f white
64.62613556 1 60 f black
78.98468361 0 65 m others
15 1 70 f white
70 0 60 m black
212 1 65 m others
10 0 45 m black
20 1 30 f others
14 0 27 f white
36 0 65 m white
86.57105915 0 45 m white
89.1741374 1 30 f white
60.13106619 0 27 f white
26.0941471 1 70 f white
20.95514934 0 60 f white
99.4575019 1 65 m white
86.69263409 0 70 f white
212 1 65 m others
10 0 45 m black
20 1 30 f others
14 0 27 f white
36 0 65 m white
54.2720264 0 45 m white
91.77489557 1 30 f white
93.23043261 0 27 f white
47.9968136 1 70 f white
",header=T)
#################################################################################
library(broom);library(data.table);library(Publish)
library(survival);library(survminer);library(Hmisc);
dput(names(data))
covariates <- c("age","gender","race" )
univ_formulas <- sapply(covariates,function(x) as.formula(paste("Surv(time,status)~",x)))
univ_models <- lapply( univ_formulas,function(x){coxph(x,data = data)})
a<-Publish::publish(univ_models);a
UVA<-as.data.frame(a);write.csv(a,file="UVA.csv")
# Error in as.data.frame.default(x[[i]],optional = TRUE,stringsAsFactors = stringsAsFactors) :
# cannot coerce class ‘"summary.regressionTable"’ to a data.frame
#==================================
## Another approach (https://stackoverflow.com/questions/61482594/export-coxph-summary-from-r-to-csv)
out = tidy(a)
#Error: No tidy method recognized for this list.
class(out);out
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。