生存分析
##########################################################
##第四题生存分析 先做一个预实验再做作业
library(survival)
library(dplyr)
library(survminer)
lung <- as_tibble(lung)
lung
##创建生存分析的对象存活时间~死没死 S大写
surv_obsevation<-Surv(lung$time,lung$status)
##拟合 关于什么的生存对象
fit<-survfit(surv_obsevation~lung$sex,data=lung)
fit
##款车整体拟合状况 summary(fit) 或者summary(fit)$table
summary(fit)$table
##作图Survminer包的ggsurvplot()函数
library(survminer)
ggsurvplot(fit,
pval = TRUE, conf.int = TRUE,
risk.table = TRUE, # Add risk table
risk.table.col = "strata", # Change risk table color by groups
linetype = "strata", # Change line type by groups
surv.median.line = "hv", # Specify median survival
ggtheme = theme_bw(), # Change ggplot2 theme
palette = c("#E7B800", "#2E9FDF")
)
##检验 >0.05 没差异
surv_diff <- survdiff(Surv(time, status) ~ sex, data = lung)
surv_diff
###第四题 开始
data_4<-read.table("final4/SurvivalData.txt",sep = "\t",header = T)
attach(data_4)
##创建生存分析的对象存活时间~死没死 S大写
surv_obsevation<-Surv(time,status)
##拟合 关于什么的生存对象
fit<-survfit(surv_obsevation~sex,data=data_4)
fit
##款车整体拟合状况 summary(fit) 或者summary(fit)$table
summary(fit)$table
##作图Survminer包的ggsurvplot()函数
library(survminer)
ggsurvplot(fit,
pval = TRUE, conf.int = TRUE,
risk.table = TRUE, # Add risk table
risk.table.col = "strata", # Change risk table color by groups
linetype = "strata", # Change line type by groups
surv.median.line = "hv", # Specify median survival
ggtheme = theme_bw(), # Change ggplot2 theme
palette = c("#E7B800", "#2E9FDF")
)
##检验 >0.05 没差异
surv_diff <- survdiff(Surv(time, status) ~ sex, data = lung)
surv_diff