[R] Survival data with time dependent covariate
BrittD
britt_dijkstra at hotmail.com
Wed May 9 10:46:07 CEST 2012
http://r.789695.n4.nabble.com/file/n4619765/survival_file.png
Hi everyone,
This is what my data looks like, I haven't included the covariates, the
example would get too large.
uid id date feverstart
dumfever
130 75 346465 2011-04-11 <NA> 0
131 75 360287 2011-04-18 <NA> 0
132 75 373195 2011-04-25 <NA> 0
133 75 388540 2011-05-02 <NA> 0
134 76 4369 2010-11-02 2010-10-19 1
135 76 19789 2010-11-09 <NA> 0
136 76 33347 2010-11-16 <NA> 0
137 76 48872 2010-11-23 <NA> 0
138 76 62967 2010-11-30 <NA> 0
139 76 77395 2010-12-07 <NA> 0
140 76 92703 2010-12-14 <NA> 0
141 76 106219 2010-12-21 <NA> 0
142 76 119836 2010-12-28 <NA> 0
143 76 134060 2011-01-04 <NA> 0
144 76 151495 2011-01-13 2011-01-10 1
145 76 166549 2011-01-20 <NA> 0
146 76 182783 2011-01-27 <NA> 0
147 76 196972 2011-02-03 <NA> 0
148 76 213502 2011-02-10 <NA> 0
149 76 230432 2011-02-17 <NA> 0
150 76 245159 2011-02-24 <NA> 0
The uid variable is a number for a person.
The id variable is a number corresponding to a specific measurement on an
indivudual.
The date is the date of the measurement.
Feverstart is the day the fever of a person started and dumfever is a
dummy-variable which tells use whether the person had a fever or not.
I need to build a dateset with a start and a stop variable for each day and
a variable that tells me whether the person got a fever that day, like this:
start stop fever
2011-04-11 2011-04-12 0
2011-04-12 2011-04-13 0
I already started to write a piece of code for this:
survival = as.numeric(NULL, NULL, 3)
for(i in 1:nrow(data2010)) {
start = data$date[i]; #first date
stop = data$date[i] + 86400; #first date plus 1 day (day is in seconds)
sick = if(is.na(data[i, 7])) { 0 } else if (stop == data[i,7]){ 1 } else 0;
#if startfever is NA or date is not the same as
#mentioned sick = 0, if date matches startfever
#then sick = 1
if(stop == data$date[i+1]) { # if the stop matches the next date in
the data, go to the next line.
start = data$date[i+1] } else if {
start = stop }
}
My problem is, that if this loop is at the last measurement of a person, so
the last id of the uid, to get it to the first measurement of the next uid.
Maybe this whole way of programming is around the bush, than please tell me.
Greetings,
Britt
--
View this message in context: http://r.789695.n4.nabble.com/Survival-data-with-time-dependent-covariate-tp4619765.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list