Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

r - Calculate readmission rate

I'm trying to calculate both 30-days and 180-days readmission rate for patients that visited the Emergency department(ED) in 2015, but I'm not quite sure how can I do that.

My data frame looks something like this:

Visit # |Patient # | Admission Date | Discharge date
   1       1         2015/01/01        2015/01/02
   2       2         2015/01/01        2015/01/01         
   3       3         2015/01/01        2015/01/02
   4       1         2015/01/09        2015/01/09                                       
   5       2         2015/04/01        2015/04/05
   6       1         2015/05/01        2015/05/01

I was hoping to have two additional columns with a binary variable [0,1] indicating whether the patient was readmitted within 30 days and/or 60 days. In the example above Patient 1 comes to the ED 3 times, 2 in January and once more in May, thus I'd hope to have readmit30 = 1 and readmit180 = 1. Patient 2 comes 2 times, once in January and once in April, thus readmit30 = 0 and readmit60 = 1. Sample solution:

Visit # |Patient #| Admission Date | Discharge date | readmit30 | readmit180
   1       1        2015/01/01        2015/01/02        1          1
   2       2        2015/01/01        2015/01/01        0          1 
   3       3        2015/01/01        2015/01/02        0          0
   4       1        2015/01/09        2015/01/09        1          1                               
   5       2        2015/04/01        2015/04/05        0          1
   6       1        2015/05/01        2015/05/01        1          1

My data set has approximately 2000 visits with approximately 1500 patients.. Any help is appreciated.

Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I actually do this quite a bit: the best method I have found is using data.table. Let's suppose your data is saved as ds, then:

s <- read.table(text = "Visit Patient Admission Discharge
1 1 2015/01/01 2015/01/02
2 2 2015/01/01 2015/01/01         
3 3 2015/01/01 2015/01/02
4 1 2015/01/09 2015/01/09                                       
5 2 2015/04/01 2015/04/05
6 1 2015/05/01 2015/05/01", header = T, sep = "")

s$Admission <- as.POSIXct(s$Admission, format = "%Y/%m/%d")
s$Discharge <- as.POSIXct(s$Discharge, format = "%Y/%m/%d")

ds <- data.table(s)

setkey(ds, Patient, Admission)
ds <- ds[ , Daydiff := as.numeric(difftime(shift(Admission, n = 1L, fill = 999, type = "lead"), Discharge)), 
          by = "Patient"][ ,':='(Readmit30 = ifelse(abs(Daydiff) <= 30, 1, 0), 
                                 Readmit180= ifelse(abs(Daydiff) <= 180, 1, 0),
                                 Daydiff   = NULL)]

This results in

> ds
   Visit Patient  Admission  Discharge      Daydiff Readmit30 Readmit180
1:     1       1 2015-01-01 2015-01-02      7.00000         1          1
2:     4       1 2015-01-09 2015-01-09    111.95833         0          1
3:     6       1 2015-05-01 2015-05-01 -16556.15510         0          0
4:     2       2 2015-01-01 2015-01-01     89.95833         0          1
5:     5       2 2015-04-01 2015-04-05 -16530.15510         0          0
6:     3       3 2015-01-01 2015-01-02 -16437.19677         0          0

Please keep in mind though, this only determines which records have a subsequent 30-day or 180-day readmit, and not which are actually the 30-day or 180-day readmit.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...