Additional Features and Common Use Cases
For most use cases, you will just need to specify the AKI definition methodology (i.e. rolling minimum window, historical baseline trumping, or baseline creatinine imputation) and the AKI-column will be returned. There are a slew of other features, some of which are listed below. For a full listing of the features and appropriate use cases, see the Documentation at akiflagger.readthedocs.io.
→ Adding padding to the rolling window
It’s often the case that you want to add some padding to the window to account for variations occurring on the floor (52 hour & 172 hour windows instead, for example). If the amount of padding you would like to add is the same for both the smaller and larger window, simply pass padding='_hours'
filling the blank with the number of hours to add to the windows.
If the pad times are different between windows, the parameters pad1time
and pad2time
allow you to add just this padding to the initial windows of 48 and 172 hours. In fact, if you wanted a window of 36 hours, you could even set pad1time = ‘-12hours’; this is one way in which you could modify the rolling window.
-
Python
# Example 0: Adding 4-hour padding to windows
flagger = AKIFlagger(padding = '4hours')
example0 = flagger.returnAKIpatients(toy)
example0[example0.aki > 0].head(3)
patient_id |
time |
inpatient |
creatinine |
aki |
12732 |
2020-02-24 23:42:42 |
False |
1.61 |
1 |
19845 |
2020-05-12 18:02:54 |
True |
0.76 |
2 |
19845 |
2020-05-14 18:02:54 |
True |
0.89 |
2 |
-
R
# Example 0: Adding 4-hour padding to windows
example0 <- returnAKIpatients(toy, padding = as.difftime(4, units = 'hours'))
head(example0[example0$aki > 0])
|
patient_id |
inpatient |
creatinine |
time |
aki |
1 |
19008 |
False |
2.06 |
2019-11-26 08:37:33 |
1 |
2 |
13264 |
False |
0.75 |
2019-08-11 17:16:57 |
3 |
3 |
13264 |
False |
0.5 |
2019-11-07 05:16:57 |
1 |
4 |
13264 |
False |
0.63 |
2019-11-08 23:16:57 |
2 |
5 |
18752 |
False |
1.18 |
2019-09-13 01:18:00 |
1 |
6 |
10537 |
False |
1.34 |
2019-11-08 07:55:12 |
1 |
→ Working with different column names
-
Python
As an additional example, the patient identifier will often come in as ‘PAT_MRN_ID’ or ‘PAT_ENC_CSN_ID’ (or something of the sort) if it is coming from a typical clinical data warehouse/repository. Accordingly, these should be passed in as options to the flagger.
# Example 1: Working with different column names
dataframe = toy.rename(columns = {'patient_id': 'PAT_MRN_ID', 'creatinine':'CREATININE', 'inpatient': 'INPATIENT', 'time': 'TIME'
'age': 'AGE', 'female': 'SEX'})
flagger = AKIFlagger(patient_id = 'PAT_MRN_ID', inpatient = 'INPATIENT', time = 'TIME', creatinine = 'CREATININE', age = 'AGE', sex = 'SEX')
example1 = flagger.returnAKIpatients(dataframe)
example1.head(3)
|
PAT_MRN_ID |
TIME |
AGE |
SEX |
INPATIENT |
CREATININE |
aki |
0 |
12732 |
2020-02-22 11:42:42 |
64.5 |
True |
False |
1.62 |
0 |
1 |
12732 |
2020-02-23 11:42:42 |
64.5 |
True |
False |
1.52 |
0 |
2 |
12732 |
2020-02-24 23:42:42 |
64.5 |
True |
False |
1.63 |
0 |
-
R
Say we had a dataframe which looked like this:
|
PAT_MRN_ID |
OUTPATIENT |
TIME |
CREATININE |
1 |
12732 |
True |
2019-11-16 05:42:42 |
1.05 |
2 |
12732 |
True |
2019-11-20 05:42:42 |
1.61 |
3 |
12732 |
True |
2020-01-15 05:42:42 |
1.42 |
In order to pass it to the flagger, we need to shape our data in a way that the flagger will understand. This means converting the outpatient columns to inpatient, and specifying the names of the columns as follows
# Example 1: Working with different column names
library(dplyr) # rename function from dplyr library
dataframe$OUTPATIENT <- !dataframe$OUTPATIENT # turn the dataframe into inpatient instead of outpatient by logically inverting it
dataframe <- dataframe %>% rename('patient_id' = 'PAT_MRN_ID', 'inpatient' = 'OUTPATIENT', 'time' = 'TIME', 'creatinine' = 'CREATININE')
head(returnAKIpatients(dataframe), n = 3L)
|
patient_id |
inpatient |
creatinine |
time |
aki |
1 |
19008 |
False |
2.05 |
2019-07-08 14:37:33 |
0 |
2 |
19008 |
False |
1.65 |
2019-07-09 08:37:33 |
0 |
3 |
19008 |
False |
1.58 |
2019-07-29 08:37:33 |
0 |
→ Adding in rolling window minimum creatinines
To add in the baseline creatinine, simply pass the flag add_min_creat = True
to the flagger. This will add in two columns which contain the minimum values in the rolling window, which is an intermediate column generated to calculate AKI; the flag adds in the column which the current creatinine is checked against.
-
Python
# Example 2: Adding in rolling-window minima
flagger = AKIFlagger(add_min_creat = True)
example2 = flagger.returnAKIpatients(toy)
example2.head(3)
patient_id |
time |
inpatient |
creatinine |
min_creat48 |
min_creat168 |
aki |
12732 |
2020-02-22 17:42:42 |
False |
1.05 |
1.05 |
1.05 |
0 |
12732 |
2020-02-26 05:42:42 |
False |
1.26 |
1.26 |
1.05 |
0 |
12732 |
2020-02-29 05:42:42 |
True |
1.06 |
1.06 |
1.05 |
0 |
-
R
# Example 2: Adding in rolling window minima
example2 <- returnAKIpatients(toy, add_min_creat = T)
head(example2)
|
patient_id |
inpatient |
creatinine |
time |
min_creat48 |
min_creat7d |
aki |
1 |
19008 |
False |
2.05 |
2019-07-08 14:37:33 |
2.05 |
2.05 |
0 |
2 |
19008 |
False |
1.65 |
2019-07-09 08:37:33 |
1.65 |
1.65 |
0 |
3 |
19008 |
False |
1.58 |
2019-07-29 08:37:33 |
1.58 |
1.58 |
0 |
4 |
19008 |
False |
1.77 |
2019-08-10 08:37:33 |
1.77 |
1.77 |
0 |
5 |
19008 |
False |
1.47 |
2019-09-25 02:37:33 |
1.47 |
1.47 |
0 |
6 |
19008 |
False |
1.64 |
2019-11-25 14:37:33 |
1.64 |
1.64 |
0 |
→ Adding in baseline creatinine
To add in the baseline creatinine, simply pass the flag add_baseline_creat = True
to the flagger. Note that the baseline creatinine is not defined for outpatient measurements. Baseline creatinine can be thought of as the “resting” creatinine before coming into the hospital, so it doesn’t make much sense to define the baseline creatinine outside of a hospital visit.
-
Python
# Example 3: Adding in baseline creatinine
toy = generate_toy_data(include_demographic_info = True)
flagger = AKIFlagger(HB_trumping = True, eGFR_impute = True, #Specifying both calculation methods
add_baseline_creat = True, # Additional parameter to add in baseline creatinine values
age = 'age', sex = 'female')
example3 = flagger.returnAKIpatients(toy)
example3[~example3.baseline_creat.isnull()].head(3)
patient_id |
time |
age |
female |
inpatient |
creatinine |
baseline_creat |
aki |
12732 |
2020-02-22 11:42:42 |
64.5 |
True |
False |
1.62 |
0.9300765849293292 |
0 |
12732 |
2020-02-25 11:42:42 |
64.5 |
True |
False |
1.63 |
0.9300765849293292 |
0 |
12732 |
2020-02-25 17:42:42 |
64.5 |
True |
False |
1.52 |
0.9300765849293292 |
0 |
-
R
# Example 3: Adding in baseline creatinine
example3 <- returnAKIpatients(toy, add_baseline_creat = T)
head(example3)
|
patient_id |
inpatient |
creatinine |
time |
age |
sex |
baseline_creat |
aki |
1 |
19008 |
False |
1.94 |
2019-12-30 02:37:33 |
52.9 |
True |
0.8806117024042 |
0 |
2 |
19008 |
True |
1.41 |
2020-01-02 02:37:33 |
52.9 |
True |
0.8806117024042 |
1 |
3 |
19008 |
True |
1.2 |
2020-01-02 14:37:33 |
52.9 |
True |
0.8806117024042 |
1 |
4 |
19008 |
True |
1.4 |
2020-01-03 02:37:33 |
52.9 |
True |
0.8806117024042 |
1 |
5 |
19008 |
True |
1.49 |
2020-01-03 14:37:33 |
52.9 |
True |
0.8806117024042 |
1 |
6 |
19008 |
True |
1.71 |
2020-01-03 20:37:33 |
52.9 |
True |
0.8806117024042 |
1 |