kkholst / mets

Analysis of Multivariate Event Times https://kkholst.github.io/mets/
15 stars 3 forks source link

reshaping of the data in bicomprisk #5

Open jaromilfrossard opened 1 year ago

jaromilfrossard commented 1 year ago

Thanks you for creating the mets package.

I stumble upon a strange behavior when using the bicomprisk() function. I still do not fully understand the theoretical background behind this function, but it seems not a desired behavior.

Here is the problem I saw: For pairs, with both censored time, the time used in the function is the first one to appear in the data frame.

Sincerely,

Jaromil

Here is the code which replicates this behavior

library(mets)
library(dplyr)
library(tidyr)

## RUN the model
out <- bicomprisk(Event(time,status)~strata(zyg)+id(id),data=prt,cause=c(2,2),
                    return.data = T)

## Data in Wide format/ with max and min time
mydz =prt%>%as_tibble()%>%
  filter(zyg=="DZ")%>%
  group_by(id)%>%
  filter(n()==2)%>%
  summarise(
    mintime = min(time),
    maxtime = max(time),
    status_sum = sum(status),
    wmin =which.min(time),
    minstatus = status[which.min(time)],
    maxstatus = status[which.max(time)]
  )

## Analyse which time is kept when both subject of the pair is censored
## when wmin=1, then the first subject of the pairs has the minimum time.
## it always corresponds to cases when the time used is the minimum. 
mydz%>%
  mutate(model_time = dz$time)%>%
  filter(minstatus==0)%>%
  filter(maxstatus==0)%>%
  count(wmin,model_time==mintime)