stc04003 / reReg

Regression methods for recurrent event data
https://www.sychiou.com/reReg/index.html
21 stars 5 forks source link

Error in joint cox model for when observation does not contain recurrent event. #32

Open bcs4007 opened 5 months ago

bcs4007 commented 5 months ago

Hi, I'm receiving the error message Error in rep(yi, m) : invalid 'times' argument when attempting to fit the joint cox model with both terminal and recurrent events. Specifically, the error seems to occur when an observation does not contain the recurrent event and either ends due to the terminal event or is censored. Is this a limitation of the Huang and Wang model or just a issue in the package?

Example to reproduce the error:

# Main Packages
library(tidyverse)

# Survival Analysis and reReg Packages
library(survival)
library(reReg)

data("simDat")

# Take observation id = 200, change id to 201, and make event column all 0.  Recurrent event doesn't occur for this observation. Otherwise same as observation 200.
df_new_obs <- simDat %>% filter(id == 200) %>% mutate(id = 201, event = 0)

simDat_Test <- simDat %>% bind_rows(df_new_obs)

fit1 <- reReg(Recur(t.stop, id, event, status) ~ x2, data = simDat, model = "cox|cox", B = 0) # Works as expected.
fit2 <- reReg(Recur(t.stop, id, event, status) ~ x2, data = simDat_Test, model = "cox|cox", B = 0) # Error

recur1 <- with(simDat, Recur(t.stop, id, event, status))
recur2 <- with(simDat_Test, Recur(t.stop, id, event, status))

summary(recur1) # Works as expected.
summary(recur2) # Works as expected.

Seems to be an issue with yi and not m in rep().