I have a composite outcome called primary
that includes death, stroke, myocardial infarction, and recurrence, and its time of occurrence is called primarydays
.
I want to do a landmark analysis and I saw this link but I don't want to exclude any patients. I want to exclude any event before 90 days and consider the nearest time point after that to create a new time-to-event variable. So I need to create primary90
and primarydays90
.
Here are my sample data and code
df<-read.table(text="primary primarydays dth dthdays stroke strokedays mi midays recurrence recurrencedays
0 1 0 1 0 1 0 1 0 1
1 1 0 966 0 966 1 1 0 966
0 2 0 1525 0 2 0 2 0 2
0 2 0 1407 0 2 0 2 0 2
0 2 0 16 0 2 0 2 0 2
1 2 0 689 0 689 1 2 0 689
0 2 0 499 0 2 0 2 0 2
0 2 0 2 0 2 0 2 0 2
0 2 0 38 0 2 0 2 0 2
0 2 0 2 0 2 0 2 0 2
0 2 0 12 0 2 0 2 0 2
0 2 0 534 0 2 0 2 0 2
0 2 0 540 0 2 0 2 0 2
1 3 0 1659 0 1659 1 3 0 1659
1 3 0 1430 1 1430 0 1430 1 3
1 6 0 743 1 6 0 743 1 743
1 6 0 1121 1 6 1 1121 0 1121
1 7 0 833 0 833 1 7 0 833
1 95 1 95 0 36 0 36 0 36
1 95 1 101 1 95 0 101 0 101
1 95 0 753 0 753 1 95 0 753
1 96 0 879 1 96 0 879 0 879
0 96 0 128 0 96 0 96 0 96
0 97 0 1060 0 97 0 97 0 97
0 98 0 98 0 98 0 98 0 98
0 100 0 185 0 100 0 100 0 100
1 101 0 554 0 554 0 101 0 554
1 102 0 565 0 565 1 102 0 565
1 102 0 1331 0 1331 0 1331 1 102
1 102 0 1285 1 102 0 1285 0 1285", sep="\t", header=T)
#I tried to add ">90" in the code but I am sure that it should be modified:
df %>% rowwise() %>% mutate(primary90 = pmax(dth , stroke , mi, recurrence, na.rm=T) >90)->df ;df
df %>% rowwise() %>% mutate(primary90days = pmin(dthdays , strokedays , midays, recurrencedays, na.rm=T)>90 )->df ;df
I can try sas as well but still struggling with the proper code.
Any advice will be greatly appreciated.