1
$\begingroup$

I am using a marginal structural modeling approach to adjust for time-dependent confounders, looking at the risk of developing disease. I have used tmerge in R to account for the time-dependent variables, then created weights with ipwtm that are fed into a Cox model to calculate hazard ratios. However, I have noticed that when I also use survsplit to cut my data into pre-specified intervals, I get different overall hazard ratios. Everything is the same except for the time split.

I understand that you could have time-dependent coefficients, but why would the overall hazard ratio be affected by how finely split the data is? Perhaps I have overlooked something.

The first rows of my data look something like this:

structure(list(id = c(1L, 2L, 3L, 3L, 4L, 4L, 5L, 6L, 7L, 8L, 
8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 
10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 
13L, 13L, 13L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 
17L, 18L, 18L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 
20L, 21L, 21L, 21L, 21L, 22L, 23L, 23L, 23L, 24L, 25L, 26L, 26L, 
27L, 28L, 28L, 29L, 30L, 31L, 31L, 31L, 32L, 32L, 32L, 33L, 33L, 
34L, 34L, 34L, 34L, 35L, 35L, 36L, 36L, 36L, 37L, 37L, 37L, 37L, 
37L, 37L, 37L, 37L, 37L, 38L, 38L, 39L, 39L, 39L, 39L, 39L, 40L, 
40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 41L, 42L, 42L, 43L, 43L, 
43L, 43L, 44L, 44L, 45L, 45L, 46L, 46L, 46L, 46L, 46L, 46L, 46L, 
46L, 46L, 47L, 48L, 48L, 49L, 50L, 50L, 50L, 50L, 51L, 52L, 53L, 
54L, 54L, 54L, 54L, 55L, 55L, 55L, 55L, 55L, 56L, 56L, 57L, 58L, 
59L, 59L, 59L, 60L, 60L, 61L, 61L, 61L, 61L, 62L, 63L, 63L, 63L, 
64L, 64L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 66L, 66L, 
66L, 66L, 67L, 67L, 68L, 68L, 69L, 69L, 70L, 70L, 71L, 71L, 71L, 
72L, 72L, 73L, 74L, 74L, 74L, 74L, 74L, 74L, 74L, 74L, 75L, 76L, 
76L, 76L, 77L, 77L, 77L, 78L, 79L, 80L, 80L, 80L, 80L, 80L, 81L, 
81L, 81L, 82L, 83L, 83L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 
84L, 84L, 84L, 84L, 85L, 85L, 85L, 85L, 86L, 86L, 86L, 86L, 86L, 
86L, 86L, 87L, 88L, 89L, 90L, 90L, 90L, 91L, 91L, 91L, 92L, 93L, 
94L, 95L, 95L, 96L, 97L, 97L, 97L, 97L, 97L, 97L, 97L, 97L, 97L, 
97L, 97L, 97L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 
99L, 99L, 99L, 99L, 99L, 100L, 101L, 101L, 101L, 101L, 101L, 
101L, 101L, 101L, 101L, 102L, 103L, 103L, 103L, 103L, 103L, 104L, 
105L, 105L, 106L, 106L, 106L, 106L, 106L, 106L, 106L, 106L, 106L, 
106L, 106L, 107L, 108L, 109L, 110L, 110L, 110L, 110L, 110L, 111L, 
111L, 112L, 112L, 113L, 113L, 113L, 114L, 115L, 116L, 116L, 117L, 
117L, 117L, 117L, 117L, 117L, 117L, 117L, 117L, 118L, 118L, 119L, 
120L, 121L, 121L, 121L, 121L, 121L, 121L, 121L, 121L, 122L, 123L, 
123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 124L, 125L, 
125L, 126L, 126L, 127L, 127L, 127L, 128L, 129L, 129L, 129L, 129L, 
129L, 130L, 130L, 130L, 130L, 130L, 130L, 130L, 131L, 131L, 131L, 
131L, 131L, 132L, 133L, 133L, 133L, 133L, 133L, 134L, 134L, 135L, 
135L, 136L, 136L, 136L, 136L, 136L, 136L, 136L, 136L, 136L, 137L, 
137L, 138L, 138L, 139L, 140L, 140L, 140L, 140L, 141L, 141L, 141L, 
141L, 141L, 141L, 141L, 142L, 142L, 142L, 142L, 143L, 144L, 144L, 
144L, 144L, 144L, 144L, 144L, 144L, 144L, 144L, 145L, 145L, 145L, 
145L, 145L, 145L, 145L, 146L, 147L, 147L, 147L, 147L, 147L, 147L, 
147L, 147L, 147L, 147L, 147L, 147L, 147L, 147L, 148L, 149L, 150L, 
150L, 150L), age = c(40L, 51L, 61L, 61L, 59L, 59L, 63L, 64L, 
57L, 61L, 61L, 61L, 61L, 61L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 
40L, 40L, 40L, 40L, 40L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 52L, 
52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 
52L, 52L, 52L, 46L, 46L, 46L, 46L, 95L, 95L, 51L, 51L, 51L, 51L, 
51L, 51L, 61L, 61L, 47L, 55L, 55L, 51L, 51L, 67L, 67L, 67L, 67L, 
67L, 67L, 67L, 67L, 67L, 57L, 57L, 57L, 57L, 74L, 72L, 72L, 72L, 
47L, 40L, 54L, 54L, 58L, 78L, 78L, 87L, 83L, 76L, 76L, 76L, 55L, 
55L, 55L, 60L, 60L, 84L, 84L, 84L, 84L, 53L, 53L, 54L, 54L, 54L, 
68L, 68L, 68L, 68L, 68L, 68L, 68L, 68L, 68L, 66L, 66L, 79L, 79L, 
79L, 79L, 79L, 71L, 71L, 71L, 71L, 71L, 71L, 71L, 71L, 71L, 55L, 
72L, 72L, 73L, 73L, 73L, 73L, 50L, 50L, 50L, 50L, 62L, 62L, 62L, 
62L, 62L, 62L, 62L, 62L, 62L, 65L, 65L, 65L, 48L, 59L, 59L, 59L, 
59L, 60L, 60L, 54L, 47L, 47L, 47L, 47L, 69L, 69L, 69L, 69L, 69L, 
48L, 48L, 44L, 77L, 55L, 55L, 55L, 53L, 53L, 47L, 47L, 47L, 47L, 
40L, 67L, 67L, 67L, 47L, 47L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 
62L, 62L, 55L, 55L, 55L, 55L, 72L, 72L, 83L, 83L, 68L, 68L, 43L, 
43L, 53L, 53L, 53L, 53L, 53L, 65L, 58L, 58L, 58L, 58L, 58L, 58L, 
58L, 58L, 58L, 55L, 55L, 55L, 64L, 64L, 64L, 68L, 50L, 52L, 52L, 
52L, 52L, 52L, 72L, 72L, 72L, 50L, 84L, 84L, 58L, 58L, 58L, 58L, 
58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 70L, 70L, 70L, 70L, 62L, 
62L, 62L, 62L, 62L, 62L, 62L, 66L, 42L, 61L, 58L, 58L, 58L, 83L, 
83L, 83L, 50L, 83L, 77L, 53L, 53L, 69L, 54L, 54L, 54L, 54L, 54L, 
54L, 54L, 54L, 54L, 54L, 54L, 54L, 63L, 63L, 63L, 63L, 63L, 63L, 
63L, 63L, 63L, 63L, 57L, 57L, 57L, 57L, 57L, 63L, 57L, 57L, 57L, 
57L, 57L, 57L, 57L, 57L, 57L, 52L, 66L, 66L, 66L, 66L, 66L, 51L, 
64L, 64L, 67L, 67L, 67L, 67L, 67L, 67L, 67L, 67L, 67L, 67L, 67L, 
61L, 53L, 84L, 67L, 67L, 67L, 67L, 67L, 57L, 57L, 63L, 63L, 42L, 
42L, 42L, 55L, 64L, 53L, 53L, 66L, 66L, 66L, 66L, 66L, 66L, 66L, 
66L, 66L, 47L, 47L, 61L, 42L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 
59L, 62L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 43L, 
48L, 48L, 54L, 54L, 49L, 49L, 49L, 46L, 53L, 53L, 53L, 53L, 53L, 
54L, 54L, 54L, 54L, 54L, 54L, 54L, 77L, 77L, 77L, 77L, 77L, 43L, 
56L, 56L, 56L, 56L, 56L, 54L, 54L, 44L, 44L, 60L, 60L, 60L, 60L, 
60L, 60L, 60L, 60L, 60L, 65L, 65L, 50L, 50L,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0), tstart = c(0, 0, 0, 10.75, 0, 154.75, 0, 0, 0, 0, 23.75, 
397.75, 745.75, 1024.75, 0, 1070.75, 1651.75, 2352.75, 2384.75, 
2570.75, 3284.75, 0, 336.75, 714.75, 1112.75, 1478.75, 0, 57.75, 
1713.75, 2232.75, 2263.75, 3534.75, 3901.75, 0, 174.75, 249.75, 
335.75, 356.75, 568.75, 603.75, 1047.75, 1279.75, 2791.75, 2812.75, 
2897.75, 3003.75, 3022.75, 3025.75, 3262.75, 3332.75, 0, 36.75, 
903.75, 1700.75, 0, 214.75, 0, 25.75, 39.75, 93.75, 98.75, 141.75, 
0, 2211.75, 0, 0, 891.75, 0, 764.75, 0, 349.75, 736.75, 1114.75, 
1483.75, 1841.75, 2191.75, 2545.75, 3287.75, 0, 433.75, 1079.75, 
1266.75, 0, 0, 24.75, 373.75, 0, 0, 0, 2889.75, 0, 0, 886.75, 
0, 0, 0, 89.75, 223.75, 0, 312.75, 2078.75, 0, 214.75, 0, 398.75, 
1013.75, 2092.75, 0, 447.75, 0, 826.75, 1373.75, 0, 332.75, 829.75, 
1199.75, 1483.75, 1888.75, 2294.75, 2943.75, 3383.75, 0, 291.75, 
0, 70.75, 181.75, 412.75, 586.75, 0, 58.75, 545.75, 944.75, 1217.75, 
1405.75, 2672.75, 3003.75, 3435.75, 0, 0, 205.75, 0, 25.75, 438.75, 
882.75, 0, 3192.75, 0, 965.75, 0, 234.75, 443.75, 752.75, 1104.75, 
1194.75, 1314.75, 1529.75, 2367.75, 0, 0, 384.75, 0, 0, 2519.75, 
3096.75, 3654.75, 0, 0, 0, 0, 378.75, 1275.75, 3050.75, 0, 860.75, 
2246.75, 3058.75, 3247.75, 0, 441.75, 0, 0, 0, 340.75, 1438.75, 
0, 906.75, 0, 467.75, 1063.75, 1665.75, 0, 0, 322.75, 1548.75, 
0, 1090.75, 0, 467.75, 1201.75, 1559.75, 1588.75, 1970.75, 2341.75, 
3139.75, 3511.75, 0, 351.75, 706.75, 1170.75, 0, 455.75, 0, 496.75, 
0, 1650.75, 0, 33.75, 0, 1328.75, 1984.75, 0, 2172.75, 0, 0, 
11.75, 411.75, 768.75, 1283.75, 2355.75, 2845.75, 3363.75, 0, 
0, 57.75, 110.75, 0, 461.75, 1447.75, 0, 0, 0, 628.75, 1306.75, 
1332.75, 1395.75, 0, 13.75, 2090.75, 0, 0, 306.75, 0, 0.75, 411.75, 
839.75, 1260.75, 1499.75, 1877.75, 2504.75, 2857.75, 3065.75, 
3233.75, 3901.75, 0, 135.75, 1543.75, 1817.75, 0, 630.75, 1582.75, 
1748.75, 1903.75, 2525.75, 3304.75, 0, 0, 0, 0, 825.75, 1411.75, 
0, 318.75, 453.75, 0, 0, 0, 0, 880.75, 0, 0, 726.75, 1094.75, 
1454.75, 1822.75, 1947.75, 2187.75, 2297.75, 2550.75, 2913.75, 
3300.75, 3679.75, 0, 400.75, 717.75, 1080.75, 1452.75, 1965.75, 
2200.75, 2543.75, 2913.75, 3882.75, 0, 245.75, 1259.75, 1574.75, 
2120.75, 0, 0, 500.75, 1124.75, 1850.75, 2481.75, 2803.75, 3226.75, 
3534.75, 3918.75, 0, 0, 557.75, 2924.75, 3260.75, 3933.75, 0, 
0, 228.75, 0, 67.75, 440.75, 710.75, 1151.75, 1459.75, 1837.75, 
2271.75, 2281.75, 2538.75, 2918.75, 0, 0, 0, 0, 216.75, 865.75, 
2250.75, 2705.75, 0, 3277.75, 0, 1727.75, 0, 376.75, 1343.75, 
0, 0, 0, 800.75, 0, 19.75, 208.75, 362.75, 609.75, 775.75, 867.75, 
970.75, 1016.75, 0, 2709.75, 0, 0, 0, 684.75, 1184.75, 1363.75, 
1698.75, 1832.75, 2323.75, 3448.75, 0, 0, 677.75, 1399.75, 1778.75, 
2125.75, 2141.75, 2161.75, 2510.75, 3127.75, 3554.75, 0, 0, 3008.75, 
0, 271.75, 0, 1087.75, 2339.75, 0, 0, 348.75, 726.75, 1341.75, 
1874.75, 0, 1795.75, 1845.75, 1908.75, 1920.75, 1958.75, 2726.75, 
0, 1657.75, 2684.75, 2854.75, 3015.75, 0, 0, 1457.75, 2606.75, 
2619.75, 2836.75, 0, 3670.75, 0, 99.75, 0, 125.75, 834.75, 1056.75, 
1803.75, 2211.75, 2457.75, 2848.75, 3199.75, 0, 271.75, 0, 394.75, 
0, 0, 476.75, 551.75, 692.75, 0, 142.75, 822.75, 1150.75, 1334.75, 
1682.75, 2112.75, 0, 128.75, 182.75, 452.75, 0, 0, 148.75, 592.75, 
1132.75, 1302.75, 1393.75, 1679.75, 2056.75, 2561.75, 2609.75, 
0, 314.75, 1062.75, 1323.75, 2208.75, 2442.75, 2797.75, 0, 0, 
39.75, 439.75, 737.75, 1137.75, 1459.75, 1839.75, 2021.75, 2166.75, 
2364.75, 2714.75, 3077.75, 3370.75, 3665.75, 0, 0, 0, 398.75, 
572.75), tstop = c(2551.75, 1481.75, 10.75, 2244.75, 154.75, 
2966.75, 2055.75, 3131.75, 1254.75, 23.75, 397.75, 745.75, 1024.75, 
3643.75, 1070.75, 1651.75, 2352.75, 2384.75, 2570.75, 3284.75, 
4051.75, 336.75, 714.75, 1112.75, 1478.75, 2036.75, 57.75, 1713.75, 
2232.75, 2263.75, 3534.75, 3901.75, 4290.75, 174.75, 249.75, 
335.75, 356.75, 568.75, 603.75, 1047.75, 1279.75, 2791.75, 2812.75, 
2897.75, 3003.75, 3022.75, 3025.75, 3262.75, 3332.75, 3743.75, 
36.75, 903.75, 1700.75, 2785.75, 214.75, 1473.75, 25.75, 39.75, 
93.75, 98.75, 141.75, 151.75, 2211.75, 2296.75, 3271.75, 891.75, 
1344.75, 764.75, 3029.75, 349.75, 736.75, 1114.75, 1483.75, 1841.75, 
2191.75, 2545.75, 3287.75, 4254.75, 433.75, 1079.75, 1266.75, 
2393.75, 3126.75, 24.75, 373.75, 383.75, 3994.75, 398.75, 2889.75, 
3736.75, 3925.75, 886.75, 933.75, 1923.75, 164.75, 89.75, 223.75, 
533.75, 312.75, 2078.75, 4211.75, 214.75, 3909.75, 398.75, 1013.75, 
2092.75, 2876.75, 447.75, 3986.75, 826.75, 1373.75, 3961.75, 
332.75, 829.75, 1199.75, 1483.75, 1888.75, 2294.75, 2943.75, 
3383.75, 4063.75, 291.75, 4350.75, 70.75, 181.75, 412.75, 586.75, 
637.75, 58.75, 545.75, 944.75, 1217.75, 1405.75, 2672.75, 3003.75, 
3435.75, 4101.75, 4317.75, 205.75, 1388.75, 25.75, 438.75, 882.75, 
4373.75, 3192.75, 3813.75, 965.75, 3917.75, 234.75, 443.75, 752.75, 
1104.75, 1194.75, 1314.75, 1529.75, 2367.75, 2447.75, 2259.75, 
384.75, 2672.75, 4065.75, 2519.75, 3096.75, 3654.75, 4318.75, 
4231.75, 895.75, 3902.75, 378.75, 1275.75, 3050.75, 4122.75, 
860.75, 2246.75, 3058.75, 3247.75, 4045.75, 441.75, 2588.75, 
3778.75, 1004.75, 340.75, 1438.75, 3308.75, 906.75, 1549.75, 
467.75, 1063.75, 1665.75, 2082.75, 955.75, 322.75, 1548.75, 4038.75, 
1090.75, 2103.75, 467.75, 1201.75, 1559.75, 1588.75, 1970.75, 
2341.75, 3139.75, 3511.75, 3539.75, 351.75, 706.75, 1170.75, 
1734.75, 455.75, 2049.75, 496.75, 539.75, 1650.75, 3722.75, 33.75, 
1083.75, 1328.75, 1984.75, 2858.75, 2172.75, 2603.75, 2690.75, 
11.75, 411.75, 768.75, 1283.75, 2355.75, 2845.75, 3363.75, 3769.75, 
3588.75, 57.75, 110.75, 2070.75, 461.75, 1447.75, 4273.75, 632.75, 
4364.75, 628.75, 1306.75, 1332.75, 1395.75, 2509.75, 13.75, 2090.75, 
4128.75, 720.75, 306.75, 837.75, 0.75, 411.75, 839.75, 1260.75, 
1499.75, 1877.75, 2504.75, 2857.75, 3065.75, 3233.75, 3901.75, 
4367.75, 135.75, 1543.75, 1817.75, 2319.75, 630.75, 1582.75, 
1748.75, 1903.75, 2525.75, 3304.75, 4030.75, 3495.75, 496.75, 
807.75, 825.75, 1411.75, 3511.75, 318.75, 453.75, 595.75, 503.75, 
2070.75, 2377.75, 880.75, 3524.75, 1592.75, 726.75, 1094.75, 
1454.75, 1822.75, 1947.75, 2187.75, 2297.75, 2550.75, 2913.75, 
3300.75, 3679.75, 4342.75, 400.75, 717.75, 1080.75, 1452.75, 
1965.75, 2200.75, 2543.75, 2913.75, 3882.75, 4272.75, 245.75, 
1259.75, 1574.75, 2120.75, 3875.75, 3377.75, 500.75, 1124.75, 
1850.75, 2481.75, 2803.75, 3226.75, 3534.75, 3918.75, 4364.75, 
1745.75, 557.75, 2924.75, 3260.75, 3933.75, 4338.75, 2238.75, 
228.75, 863.75, 67.75, 440.75, 710.75, 1151.75, 1459.75, 1837.75, 
2271.75, 2281.75, 2538.75, 2918.75, 3853.75, 2931.75, 3943.75, 
2910.75, 216.75, 865.75, 2250.75, 2705.75, 3504.75, 3277.75, 
3992.75, 1727.75, 3166.75, 376.75, 1343.75, 2834.75, 1725.75, 
2271.75, 800.75, 1724.75, 19.75, 208.75, 362.75, 609.75, 775.75, 
867.75, 970.75, 1016.75, 1030.75, 2709.75, 3267.75, 3245.75, 
3525.75, 684.75, 1184.75, 1363.75, 1698.75, 1832.75, 2323.75, 
3448.75, 3981.75, 2669.75, 677.75, 1399.75, 1778.75, 2125.75, 
2141.75, 2161.75, 2510.75, 3127.75, 3554.75, 4128.75, 3387.75, 
3008.75, 3740.75, 271.75, 1762.75, 1087.75, 2339.75, 3016.75, 
772.75, 348.75, 726.75, 1341.75, 1874.75, 4281.75, 1795.75, 1845.75, 
1908.75, 1920.75, 1958.75, 2726.75, 3132.75, 1657.75, 2684.75, 
2854.75, 3015.75, 4048.75, 2657.75, 1457.75, 2606.75, 2619.75, 
2836.75, 3327.75, 3670.75, 4077.75, 99.75, 2330.75, 125.75, 834.75, 
1056.75, 1803.75, 2211.75, 2457.75, 2848.75, 3199.75, 3603.75, 
271.75, 4352.75, 394.75, 1528.75, 2872.75, 476.75, 551.75, 692.75, 
698.75, 142.75, 822.75, 1150.75, 1334.75, 1682.75, 2112.75, 3047.75, 
128.75, 182.75, 452.75, 2255.75, 2166.75, 148.75, 592.75, 1132.75, 
1302.75, 1393.75, 1679.75, 2056.75, 2561.75, 2609.75, 3022.75, 
314.75, 1062.75, 1323.75, 2208.75, 2442.75, 2797.75, 4099.75, 
2586.75, 39.75, 439.75, 737.75, 1137.75, 1459.75, 1839.75, 2021.75, 
2166.75, 2364.75, 2714.75, 3077.75, 3370.75, 3665.75, 4132.75, 
1848.75, 2183.75, 398.75, 572.75, 1113.75)), row.names = c(NA, 
-500L), class = "data.frame")

Using the following code I get different results:

temp <- ipwtm(
  exposure = exp,
  id = id,
  family = "survival",
  #link = "logit",
  numerator = ~ age,
  denominator = ~ age + log10(tdc) + cumtdc,
  tstart = tstart,
  timevar = tstop,
  type = "first",
  trunc = 0.01,
  data = as.data.frame(data)) 

model.coxph <- coxph(Surv(tstart, tstop, event) ~ exp +
          age + cluster(id),
        weights = temp$weights.trunc, robust = TRUE, data = data, id = id)

data_split <- survSplit(Surv(tstart, tstop, event == 1) ~ .,
                                                 data = data,
                                                 cut = seq(0, 24*182.625, by = 182.625), # split every 6 months
                                                 episode = "e",
                                                 event = "event")

temp <- ipwtm(
  exposure = exp,
  id = id,
  family = "survival",
  #link = "logit",
  numerator = ~ age,
  denominator = ~ age + log10(tdc) + cumtdc,
  tstart = tstart,
  timevar = tstop,
  type = "first",
  trunc = 0.01,
  data = as.data.frame(data_split))

model.coxph <- coxph(Surv(tstart, tstop, event) ~ exp +
                       age + cluster(id),
                     weights = temp$weights.trunc, robust = TRUE, data = data_split, id = id)
$\endgroup$
3
  • $\begingroup$ This might be due to a violation of the proportional hazards assumption, with inherently time-varying Cox coefficients. Or there might be a problem with modeling continuous predictors; improper specification of the functional forms of their associations with outcome could lead to such a problem. Please edit the question to show a reproducible example, as otherwise it will be hard to give clear advice. $\endgroup$
    – EdM
    Commented Jan 4 at 18:24
  • $\begingroup$ Thanks for the reply! I don't see any violations of the PH assumption in my model. I have provided a snippet of my data in the original question. However, as you notice, I was unable to create a completely reproducible example as it would require many more rows of data. $\endgroup$
    – Rich R
    Commented Jan 4 at 21:06
  • $\begingroup$ @EdM I added some more rows of data to the question to make it reproducible. Not sure if I should add further rows. $\endgroup$
    – Rich R
    Commented Jan 5 at 15:15

2 Answers 2

1
$\begingroup$

The weights calculated by ipwtm() (from the ipw package) are completely different in the two situations. Examine length(unique(temp$weights.trunc)) for the two situations.

You have 150 unique id values in your sample data. For the un-split sample data frame (500 rows) there are only 8 unique values of weights.trunc. For the data frame produced by survSplit() (2700 rows) there are 635 unique values. Thus it's not surprising that the Cox models based on those two data frames are different.

I think that the problem might come from the way that you are using ipwtm(). Software-specific questions are off-topic here, but a couple of things are noteworthy and might be related to statistical analysis issues (I'm not very familiar with that function).

First, the manual says "Since a switch in exposure level can occur at the start of follow-up, tstart should be negative for the first interval (with timevar=0) within each patient." That's not the case in your sample data (although it might be in your full data).

Second, the manual says "With type='first', weights are estimated up to the first switch from the lowest exposure value (typically 0 or the first factor level) to any other value. After this switch, weights will then be constant." (Emphasis added.) The split data frame will thus have more weights calculated for an individual up to that exposure-switch time, as each individual has more associated data rows.

This type of analysis can be very tricky; I'm not expert at it. Make sure that this approach is accomplishing what you want it to. If you don't have locally available expertise, consider asking another question on this site about the best way to proceed.

$\endgroup$
4
  • $\begingroup$ Thanks for the great answer! I think you are on to something with the unique values for the weights. I looked into the examples you referred to and if you use the haartdat, the estimated weights are different for each time point where the CD4 count changes. This makes sense. However, in my case, the weights do not change when my time-dependent covariates change values. The only difference I could find in my data (as you mentioned) is the non-negative tstart. I created the long-form data using tmerge. Do you know how I could set it to start at a negative number? Thanks again! $\endgroup$
    – Rich R
    Commented Jan 8 at 16:09
  • $\begingroup$ @RichR for the non-negative tstart I suppose that you could just add one line for each id having tstart = -1, tstop = 0. I'm not convinced that will solve your problem, however, as I think that only matters for individuals who start with a switch in exposure at time = 0. Beyond that, I'm afraid that I'm not expert enough in this type of time-dependent weighting to provide much help. $\endgroup$
    – EdM
    Commented Jan 8 at 16:25
  • $\begingroup$ Thanks! I realized that the correct way to do it is to split the dataset for each time point to calculate weights for all individuals at these time points. In example 2 in the documentation for the ipwtm function this is described. $\endgroup$
    – Rich R
    Commented Jan 9 at 14:54
  • $\begingroup$ @RichR it might help others who come to this page if you could expand the above comment into another answer, perhaps illustrating with the code from the documentation. Answers stand out nicely on a page; comments are easy to overlook and can be deleted. $\endgroup$
    – EdM
    Commented Jan 9 at 14:56
2
$\begingroup$

After having more thoroughly read the documentation for the ipwtm function, the idea is to calculate weights for all individuals at all time points with events or changes in variables in the data set. One way to build such a dataset is with the example code provided in Example 2 in the documentation for the ipwtm function (https://rdrr.io/cran/ipw/man/ipwtm.html). However, I also found the following paper by Grafféo et al. that describes this issue in detail. In the supporting information, the function "processing data" can be found, which achieves the correct time split mentioned in the ipwtm documentation. https://pubmed.ncbi.nlm.nih.gov/29280181/

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.