R语言中生存分析的“~1”代表什么意思
最近在研究生存分析,发现R语言中做没有因子(即自变量x)的生存分析时,类似这种语句
surv.all<-survfit(Surv(month,status)~1)
,右边的括号要写~1
才能运行,这是为什么呢,其中的~1
又是什么意思?
解答
先看看R语言官方文档survfit()
方法中对传入参数formula
的解释
A formula object or a
coxph
object. If a formula object is supplied it
must have aSurv
object as the response on the left of the~
operator
and, if desired, terms separated by + operators on the right. One of
the
意思是说如果只有一条生存曲线,~右侧应该是1,如果按照某一个分层变量做多个生存曲线,则~右侧就是分层变量,比如按性别分层做两条曲线就可以是~sex。类似一般的回归模型,~1就是只有Y-intercept,没有自变量X-intercept。