Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tmerge #3

Open
IKRAMTUN opened this issue Mar 3, 2024 · 4 comments
Open

tmerge #3

IKRAMTUN opened this issue Mar 3, 2024 · 4 comments

Comments

@IKRAMTUN
Copy link

IKRAMTUN commented Mar 3, 2024

I have a problem merging two data with repetitive measurements.
The merging did not include the second measurment.

library(survival)
data1<- data.frame(
subject = c(1, 2, 3),
time1 = c(3, 2, 2),
time2= c(4, 8, 6),
status = c(1, 0, 1),
First_measu=c(54, 66, 18))

data2<- data.frame(
subject = c(1, 2, 3),
Second_measu=c(66, 73, 82))

###Merge the data to do the coxph

merged_data<-tmerge(data1, data2, id=subject, tstart=time1, tstop=time2)
print(merged_data)

@kmezhoud
Copy link

kmezhoud commented Mar 3, 2024

Hi,
For better help could you give us an example as in tmerge example.

 The pbc data set contains baseline data and follow-up status
# for a set of subjects with primary biliary cirrhosis, while the
# pbcseq data set contains repeated laboratory values for those
# subjects.  
# The first data set contains data on 312 subjects in a clinical trial plus
# 106 that agreed to be followed off protocol, the second data set has data
# only on the trial subjects.
temp <- subset(pbc, id <= 312, select=c(id:sex, stage)) # baseline data
pbc2 <- tmerge(temp, temp, id=id, endpt = event(time, status))
pbc2 <- tmerge(pbc2, pbcseq, id=id, ascites = tdc(day, ascites),
               bili = tdc(day, bili), albumin = tdc(day, albumin),
               protime = tdc(day, protime), alk.phos = tdc(day, alk.phos))

fit <- coxph(Surv(tstart, tstop, endpt==2) ~ protime + log(bili), data=pbc2)

or
excluding tmerge functionalities, if you want to merge the two df you can use dplyr package:

data1<- data.frame(
    id = c(1, 2, 3),
    tstart = c(3, 2, 2),
    tstop= c(4, 8, 6),
    status = c(1, 0, 1),
    measu1=c(54, 66, 18))

data2<- data.frame(
    id = c(1, 2, 3),
    measu2=c(66, 73, 82))

data1 |>
    dplyr::left_join(data2, by= "id")
```
```
  id tstart tstop status measu1 measu2
1  1      3     4      1     54     66
2  2      2     8      0     66     73
3  3      2     6      1     18     82
```

@IKRAMTUN
Copy link
Author

IKRAMTUN commented Mar 3, 2024

Many thanks for the answer, however, it is necessary to use the tmerge to do the Cox proportional hazard ratio regression repeating measurement.
Accordingly, should I put two intervals of time in each data? and if yes how can I merge it? and associated with each measurement?
I was thinking about formatting my data as follows;

id tstart tstop measurment status
1 1 0 3 54 1
2 1 3 4 66 1
3 2 0 2 66 0
4 2 2 8 73 0

BUT, can't figure out how to do it with tmerge again!!
IS

@kmezhoud
Copy link

kmezhoud commented Mar 3, 2024

I think you need to create an event before to merge datasets.
Make a sens to your event

data1<- data.frame(
    id = c(1, 2, 3),
    tstart = c(3, 2, 2),
    tstop= c(4, 8, 6),
    status = c(1, 0, 1),
    measu1=c(54, 66, 18))

data2<- data.frame(
    id = c(1, 2, 3),
    tstart = c(3, 2, 2),
    measu2=c(66, 73, 82))

data2 <- tmerge(data2, data2, id=id, endpt = event(tstart, measu2))

tmerge(data2, data1, id=id, tstop= tdc(endpt, tstop))

Error in tmerge(data2, data1, id = id, tstop = tdc(endpt, tstop)) :
tstart and tstop arguments only apply to the first call

@IKRAMTUN
Copy link
Author

IKRAMTUN commented Mar 3, 2024

In the tmerge function, the tstart and tstop variables can be present in the first dataset only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants