[英]Survival package R: survSplit “start time < end time”
I am trying to create a dataframe with cutpoints for piecewise hazard modelling using the survSplit function from survival. 我正在尝试使用生存的survSplit函数来创建带有切点的数据框,以进行分段危害建模。 The data is right-censored, but not left-truncated/censored.
数据是右删截的,但不是左截断/删截的。 The data looks like this
数据看起来像这样
stay event sex marstat agegr health ID 0.101 1 f 0 (75,90] 1 1 0.167 1 f 0 (75,90] 2 2 2.968 0 f 0 [65,75] 2 3
With stay being the time variable, and event being the event indicator 停留是时间变量,事件是事件指示器
Based on previous experience with the survsplit I started with the following code: 基于对survsplit的先前经验,我从以下代码开始:
datasplit <- survSplit(data= data, cut = c(0.25, 0.5, 1, 2,3),
end = "stay", start = "start", episode= "interval")
This did not work because it did not have a formula (but it apparently worked for me back in november, with what I guess was an older version of the survival package?) After a bit of googling of what the formula should be I entered the following 这是行不通的,因为它没有公式(但是显然在11月,它对我有用,我猜那是一个较旧的生存包版本?)在仔细搜索了应该使用的公式后,我进入了以下
datasplit <- survSplit(Surv(stay, event)~.,
data= data, cut = c(0.25, 0.5, 1, 2,3),
end = "stay", start = "start", episode= "interval")
I get the error message: " start time < end time", which is odd seeing as there is no start time. 我收到错误消息:“开始时间<结束时间”,由于没有开始时间,这很奇怪。 Based on a previous answer I saw on Stack overflow, I retried without end = and event = , but the error message did not go away.
根据我在堆栈溢出中看到的先前答案,我在没有end =和event =的情况下重试,但错误消息没有消失。 I am not sure what I can do to remedy it at this point.
我不确定目前该如何解决。
I see that you have already provided a response , but I wanted to discuss a little bit more the topic. 我看到您已经提供了答复,但是我想讨论更多有关该主题的内容。
There are two things to take into account here, sometimes in survival analysis it makes no sense that time happens at 0, so probably you are right that the events at time 0 should be added error to make sense of them. 这里有两点要考虑,有时在生存分析中,时间在0发生没有意义,因此您可能是对的,应该在时间0的事件中添加错误以使其有意义。
longdata <- survival::survSplit(Surv(time2event, os_event ) ~.,
data = d %>%
dplyr::mutate(os_event = ( status == event_type),
time2event = time) ,
cut = tau,
subset = (d %>% dplyr::select(time) %>%
unlist) != 0,
start = "start",
end = "event",
episode = "interval")
I found that the function has also a option called subset that could work to drop the observation at time 0 otherwise, I have read sometimes that observations at time 0 should be dropped, however I make more sense of your solution of adding a small error. 我发现该函数还有一个称为子集的选项,可以用来删除时间0处的观察值,否则,我有时会读到应该删除时间0处的观察值,但是我对添加小错误的解决方案更有意义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.