Description Usage Format Details Source References Examples
Drug-relapse of patients with time-varying covariates. This data set is simulated.
1 |
A data frame with 300 observations on the following 4 variables.
event
a numeric vector
delta
a logical vector
gender
a numeric vector
inter
a numeric vector
This data is simulated under the following pretense. Patient records were obtained for 150 days after they joined a rehabilitation program. The event of interest was drug-relapse and two covariates were recorded. The event
variable describes the observed or censored time; the delta
variable describes whether the time denotes an observed relapse (TRUE
) or a censored time; the gender
variable is a time-independent covariate; and inter
is a time-dependent covariate indicating whether the patient had was (randomly) assigned a second intervention: working 10 hours a week for a nonprofit. Each of these special interventions were assigned after the patients entered the clinic, meaning the intervention covariate changes for those patients who had an intervention before relapse.
Simulated (David M Diez)
Fox J (2002). "Cox Proportional-Hazards Regression for Survival Data. Appendix to An R and S-PLUS Companion to Applied Regression." Comprehensive R Archive Network. http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-cox-regression.pdf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #=====> 10. Cox PH model, time-dependent covariates <=====#
data(relapse)
relapse
attach(relapse)
N <- dim(relapse)[1]
t1 <- rep(0, N+sum(!is.na(inter))) # Initialize start times at 0
t2 <- rep(NA, length(t1)) # The end times for each record
e <- rep(NA, length(t1)) # Was the event censored?
g <- rep(NA, length(t1)) # Gender
PI <- rep(FALSE, length(t1)) # Initialize intervention at FALSE
R <- 1 # Row of new record
for(ii in 1:dim(relapse)[1]){
if(is.na(inter[ii])){ # no intervention, copy survival record
t2[R] <- event[ii]
e[R] <- delta[ii]
g[R] <- gender[ii]
R <- R+1
} else { # intervention, split records
g[R+0:1] <- gender[ii] # gender is same for each time
e[R] <- 0 # no relapse observed pre-intervention
e[R+1] <- delta[ii] # relapse occur post-intervention?
PI[R+1] <- TRUE # Intervention covariate, post-intervention
t2[R] <- inter[ii]-1 # End of pre-intervention
t1[R+1] <- inter[ii]-1 # Start of post-intervention
t2[R+1] <- event[ii] # End of post-intervention
R <- R+2 # Two records added
}
}
mySurv <- Surv(t1, t2, e)
coxphFit <- coxph(mySurv ~ g + PI)
detach(relapse)
|
Loading required package: survival
Loading required package: KMsurv
event delta gender inter
1 150 FALSE 0 84
2 53 TRUE 1 50
3 12 TRUE 1 NA
4 150 FALSE 0 89
5 150 FALSE 1 77
6 135 TRUE 1 7
7 150 FALSE 0 21
8 57 TRUE 1 NA
9 65 TRUE 0 NA
10 92 TRUE 1 6
11 16 TRUE 1 10
12 42 TRUE 0 NA
13 76 TRUE 1 NA
14 123 TRUE 0 15
15 150 FALSE 0 69
16 150 FALSE 1 6
17 120 TRUE 1 61
18 111 TRUE 0 46
19 58 TRUE 0 NA
20 150 FALSE 0 19
21 121 TRUE 1 66
22 150 FALSE 0 18
23 150 FALSE 1 27
24 62 TRUE 0 11
25 150 FALSE 0 41
26 150 FALSE 0 23
27 76 TRUE 0 65
28 2 TRUE 0 NA
29 141 TRUE 1 11
30 150 FALSE 0 8
31 150 FALSE 0 20
32 30 TRUE 0 NA
33 15 TRUE 1 NA
34 103 TRUE 1 40
35 37 TRUE 1 3
36 150 FALSE 1 6
37 30 TRUE 1 12
38 33 TRUE 0 NA
39 150 FALSE 1 85
40 21 TRUE 0 NA
41 150 FALSE 1 87
42 77 TRUE 0 NA
43 63 TRUE 0 NA
44 133 TRUE 0 3
45 66 TRUE 1 53
46 150 FALSE 1 37
47 139 TRUE 1 64
48 75 TRUE 0 NA
49 37 TRUE 1 20
50 19 TRUE 1 NA
51 5 TRUE 0 NA
52 88 TRUE 0 60
53 150 FALSE 1 41
54 150 FALSE 1 88
55 75 TRUE 0 19
56 33 TRUE 1 NA
57 103 TRUE 1 80
58 150 FALSE 1 61
59 150 FALSE 1 7
60 150 FALSE 1 70
61 19 TRUE 1 16
62 57 TRUE 1 21
63 90 TRUE 1 12
64 111 TRUE 0 3
65 30 TRUE 1 NA
66 150 FALSE 0 25
67 150 FALSE 0 14
68 150 FALSE 0 7
69 137 TRUE 0 71
70 150 FALSE 0 5
71 150 FALSE 0 89
72 150 FALSE 0 3
73 150 FALSE 0 52
74 150 FALSE 0 65
75 21 TRUE 0 NA
76 150 FALSE 1 67
77 150 FALSE 0 27
78 150 FALSE 1 100
79 150 FALSE 0 70
80 147 TRUE 1 7
81 33 TRUE 0 12
82 150 FALSE 1 49
83 150 FALSE 0 48
84 150 FALSE 0 28
85 65 TRUE 0 10
86 37 TRUE 1 NA
87 5 TRUE 1 NA
88 99 TRUE 0 55
89 150 FALSE 1 87
90 75 TRUE 0 NA
91 21 TRUE 1 NA
92 97 TRUE 0 93
93 126 TRUE 0 34
94 150 FALSE 1 17
95 38 TRUE 0 23
96 38 TRUE 0 13
97 9 TRUE 0 NA
98 150 FALSE 0 86
99 150 FALSE 0 24
100 27 TRUE 0 NA
101 73 TRUE 0 63
102 39 TRUE 0 NA
103 150 FALSE 1 17
104 68 TRUE 1 5
105 49 TRUE 0 NA
106 28 TRUE 1 NA
107 150 FALSE 1 60
108 1 TRUE 0 NA
109 90 TRUE 0 18
110 150 FALSE 0 81
111 90 TRUE 0 66
112 58 TRUE 1 NA
113 116 TRUE 0 46
114 150 FALSE 1 9
115 150 FALSE 1 37
116 12 TRUE 1 NA
117 28 TRUE 1 NA
118 24 TRUE 0 NA
119 21 TRUE 1 NA
120 150 FALSE 1 80
121 53 TRUE 0 NA
122 150 FALSE 0 2
123 15 TRUE 1 NA
124 66 TRUE 1 NA
125 20 TRUE 0 NA
126 150 FALSE 1 14
127 107 TRUE 1 9
128 79 TRUE 0 58
129 32 TRUE 1 NA
130 76 TRUE 0 8
131 37 TRUE 0 NA
132 51 TRUE 1 NA
133 27 TRUE 0 NA
134 19 TRUE 1 NA
135 60 TRUE 0 11
136 121 TRUE 1 84
137 21 TRUE 1 14
138 39 TRUE 1 NA
139 48 TRUE 0 NA
140 6 TRUE 0 NA
141 150 FALSE 0 66
142 111 TRUE 0 21
143 26 TRUE 1 NA
144 56 TRUE 0 56
145 3 TRUE 0 NA
146 21 TRUE 1 NA
147 150 FALSE 1 98
148 150 FALSE 0 57
149 120 TRUE 0 54
150 9 TRUE 0 NA
151 150 FALSE 0 69
152 150 FALSE 0 75
153 4 TRUE 1 NA
154 150 FALSE 0 15
155 150 FALSE 1 82
156 80 TRUE 0 NA
157 15 TRUE 1 NA
158 67 TRUE 0 NA
159 16 TRUE 0 NA
160 52 TRUE 0 NA
161 150 FALSE 1 95
162 150 FALSE 1 3
163 66 TRUE 0 4
164 150 FALSE 1 50
165 150 FALSE 0 28
166 126 TRUE 1 77
167 28 TRUE 0 NA
168 150 FALSE 1 75
169 50 TRUE 0 6
170 41 TRUE 1 NA
171 60 TRUE 1 16
172 150 FALSE 0 45
173 12 TRUE 0 NA
174 2 TRUE 1 NA
175 18 TRUE 0 NA
176 150 FALSE 1 80
177 56 TRUE 0 55
178 8 TRUE 0 4
179 34 TRUE 1 29
180 74 TRUE 1 NA
181 150 FALSE 1 48
182 88 TRUE 1 77
183 28 TRUE 1 NA
184 15 TRUE 1 NA
185 150 FALSE 0 89
186 1 TRUE 1 NA
187 150 FALSE 0 72
188 20 TRUE 1 NA
189 9 TRUE 0 NA
190 79 TRUE 0 NA
191 102 TRUE 0 30
192 49 TRUE 0 NA
193 20 TRUE 1 NA
194 75 TRUE 0 NA
195 23 TRUE 1 NA
196 150 FALSE 0 22
197 150 FALSE 0 33
198 56 TRUE 0 NA
199 150 FALSE 0 34
200 150 FALSE 0 57
201 9 TRUE 1 NA
202 107 TRUE 1 57
203 89 TRUE 1 35
204 150 FALSE 1 25
205 37 TRUE 0 NA
206 92 TRUE 1 74
207 34 TRUE 0 NA
208 150 FALSE 0 50
209 150 FALSE 0 81
210 150 FALSE 0 69
211 51 TRUE 1 NA
212 61 TRUE 1 11
213 27 TRUE 1 NA
214 150 FALSE 1 42
215 5 TRUE 1 NA
216 150 FALSE 0 60
217 1 TRUE 0 NA
218 58 TRUE 0 53
219 25 TRUE 0 NA
220 40 TRUE 0 NA
221 78 TRUE 0 NA
222 60 TRUE 1 7
223 136 TRUE 0 47
224 2 TRUE 0 NA
225 25 TRUE 1 NA
226 3 TRUE 1 NA
227 128 TRUE 1 4
228 133 TRUE 0 71
229 150 FALSE 1 27
230 108 TRUE 1 90
231 150 FALSE 1 10
232 40 TRUE 0 NA
233 6 TRUE 1 NA
234 62 TRUE 1 15
235 150 FALSE 1 69
236 9 TRUE 0 NA
237 13 TRUE 1 NA
238 150 FALSE 0 28
239 42 TRUE 0 NA
240 48 TRUE 0 NA
241 134 TRUE 1 2
242 28 TRUE 0 NA
243 150 TRUE 1 49
244 35 TRUE 1 NA
245 3 TRUE 1 NA
246 47 TRUE 1 4
247 4 TRUE 0 NA
248 29 TRUE 1 NA
249 22 TRUE 0 NA
250 55 TRUE 0 NA
251 7 TRUE 1 NA
252 39 TRUE 0 37
253 150 FALSE 0 50
254 40 TRUE 0 NA
255 93 TRUE 1 85
256 77 TRUE 0 51
257 18 TRUE 0 NA
258 150 FALSE 0 59
259 1 TRUE 0 NA
260 39 TRUE 1 NA
261 150 FALSE 1 98
262 50 TRUE 0 3
263 150 FALSE 1 75
264 19 TRUE 0 NA
265 31 TRUE 1 NA
266 150 FALSE 1 32
267 145 TRUE 0 28
268 150 FALSE 1 56
269 150 FALSE 1 92
270 150 FALSE 1 12
271 49 TRUE 1 NA
272 150 FALSE 1 59
273 150 FALSE 1 89
274 3 TRUE 0 NA
275 66 TRUE 1 51
276 37 TRUE 0 NA
277 150 FALSE 1 91
278 7 TRUE 0 2
279 41 TRUE 0 NA
280 150 FALSE 0 21
281 26 TRUE 0 14
282 63 TRUE 1 15
283 84 TRUE 1 73
284 150 FALSE 1 60
285 43 TRUE 0 NA
286 150 FALSE 1 76
287 38 TRUE 1 NA
288 53 TRUE 1 10
289 93 TRUE 1 NA
290 3 TRUE 0 NA
291 91 TRUE 0 37
292 25 TRUE 0 NA
293 150 FALSE 1 67
294 14 TRUE 0 5
295 150 FALSE 1 3
296 144 TRUE 0 75
297 150 FALSE 0 10
298 62 TRUE 0 24
299 10 TRUE 0 NA
300 94 TRUE 1 4
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.