0% found this document useful (0 votes)
52 views6 pages

MTE Project: Task 1

The document describes tasks from an MTE project involving analysis of antibiotic and blood culture data. It loads antibiotic and blood culture data, merges the datasets, sorts by relevant fields, and calculates variables like last antibiotic administration date and days since last dose to categorize whether antibiotics were recently administered.

Uploaded by

nishant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views6 pages

MTE Project: Task 1

The document describes tasks from an MTE project involving analysis of antibiotic and blood culture data. It loads antibiotic and blood culture data, merges the datasets, sorts by relevant fields, and calculates variables like last antibiotic administration date and days since last dose to categorize whether antibiotics were recently administered.

Uploaded by

nishant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

MTE Project

Nishant Kumar
21/01/2021
Task 1:-
# Load packages
library(data.table)

## Warning: package ‘data.table’ was built under R version 4.0.3

# Read in the data


antibioticDT <- fread(“antibioticDT.csv”)

# Look at the first 30 rows


antibioticDT[1:30]

## patient_id day_given antibiotic_type route


## 1: 1 2 ciprofloxacin IV
## 2: 1 4 ciprofloxacin IV
## 3: 1 6 ciprofloxacin IV
## 4: 1 7 doxycycline IV
## 5: 1 9 doxycycline IV
## 6: 1 15 penicillin IV
## 7: 1 16 doxycycline IV
## 8: 1 18 ciprofloxacin IV
## 9: 8 1 doxycycline PO
## 10: 8 2 penicillin IV
## 11: 8 3 doxycycline IV
## 12: 8 6 doxycycline PO
## 13: 8 8 penicillin PO
## 14: 8 12 penicillin IV
## 15: 9 8 doxycycline IV
## 16: 9 12 doxycycline PO
## 17: 12 4 doxycycline PO
## 18: 12 9 doxycycline IV
## 19: 16 1 doxycycline IV
## 20: 16 4 amoxicillin IV
## 21: 19 3 doxycycline PO
## 22: 19 5 amoxicillin IV
## 23: 19 6 ciprofloxacin IV
## 24: 19 10 doxycycline IV
## 25: 19 12 penicillin IV
## 26: 23 1 doxycycline IV
## 27: 23 1 penicillin IV
## 28: 23 3 amoxicillin IV
## 29: 23 3 ciprofloxacin IV
## 30: 23 3 doxycycline IV
## patient_id day_given antibiotic_type route

Task 2:-
# Sort the data by id, antibiotic type, day
setorder(antibioticDT, patient_id, antibiotic_type, day_given)
antibioticDT[1:40]

## patient_id day_given antibiotic_type route


## 1: 1 2 ciprofloxacin IV
## 2: 1 4 ciprofloxacin IV
## 3: 1 6 ciprofloxacin IV
## 4: 1 18 ciprofloxacin IV
## 5: 1 7 doxycycline IV
## 6: 1 9 doxycycline IV
## 7: 1 16 doxycycline IV
## 8: 1 15 penicillin IV
## 9: 8 1 doxycycline PO
## 10: 8 3 doxycycline IV
## 11: 8 6 doxycycline PO
## 12: 8 2 penicillin IV
## 13: 8 8 penicillin PO
## 14: 8 12 penicillin IV
## 15: 9 8 doxycycline IV
## 16: 9 12 doxycycline PO
## 17: 12 4 doxycycline PO
## 18: 12 9 doxycycline IV
## 19: 16 4 amoxicillin IV
## 20: 16 1 doxycycline IV
## 21: 19 5 amoxicillin IV
## 22: 19 6 ciprofloxacin IV
## 23: 19 3 doxycycline PO
## 24: 19 10 doxycycline IV
## 25: 19 12 penicillin IV
## 26: 23 3 amoxicillin IV
## 27: 23 8 amoxicillin IV
## 28: 23 10 amoxicillin PO
## 29: 23 3 ciprofloxacin IV
## 30: 23 5 ciprofloxacin PO
## 31: 23 16 ciprofloxacin IV
## 32: 23 1 doxycycline IV
## 33: 23 3 doxycycline IV
## 34: 23 4 doxycycline IV
## 35: 23 5 doxycycline IV
## 36: 23 6 doxycycline IV
## 37: 23 6 doxycycline PO
## 38: 23 9 doxycycline PO
## 39: 23 10 doxycycline IV
## 40: 23 11 doxycycline PO
## patient_id day_given antibiotic_type route

# Use shift to calculate the last day a particular drug was administered
antibioticDT[ , last_administration_day := shift(day_given, 1),
by = .(patient_id, antibiotic_type)]

# Calculate the number of days since the drug was last administered
antibioticDT[ , days_since_last_admin := day_given – last_administration_day]

# Create antibiotic_new with an initial value of one, then reset it to zero as needed
antibioticDT[ , antibiotic_new := 1]
antibioticDT[days_since_last_admin <= 2, antibiotic_new := 0]

Task 3 :-
# Read in blood_cultureDT.csv
blood_cultureDT <- fread(“blood_cultureDT.csv”)

# Print the first 30 rows


blood_cultureDT[1:30]

## patient_id blood_culture_day
## 1: 1 3
## 2: 1 13
## 3: 8 2
## 4: 8 13
## 5: 23 3
## 6: 39 10
## 7: 45 4
## 8: 45 9
## 9: 45 11
## 10: 51 3
## 11: 51 6
## 12: 59 2
## 13: 64 1
## 14: 66 9
## 15: 66 10
## 16: 69 2
## 17: 69 6
## 18: 69 7
## 19: 69 11
## 20: 69 16
## 21: 76 1
## 22: 77 3
## 23: 79 5
## 24: 79 11
## 25: 79 12
## 26: 80 3
## 27: 80 12
## 28: 81 2
## 29: 112 6
## 30: 115 2
## patient_id blood_culture_day

Task 4:-
# Merge antibioticDT with blood_cultureDT
combinedDT <- merge(blood_cultureDT,antibioticDT,all = FALSE,by = ‘patient_id’)

# Sort by patient_id, blood_culture_day, day_given, and antibiotic_type


setorder(combinedDT, patient_id, blood_culture_day, day_given, antibiotic_type)
# Print and examine the first 30 rows
combinedDT[1:30]

## patient_id blood_culture_day day_given antibiotic_type route


## 1: 1 3 2 ciprofloxacin IV
## 2: 1 3 4 ciprofloxacin IV
## 3: 1 3 6 ciprofloxacin IV
## 4: 1 3 7 doxycycline IV
## 5: 1 3 9 doxycycline IV
## 6: 1 3 15 penicillin IV
## 7: 1 3 16 doxycycline IV
## 8: 1 3 18 ciprofloxacin IV
## 9: 1 13 2 ciprofloxacin IV
## 10: 1 13 4 ciprofloxacin IV
## 11: 1 13 6 ciprofloxacin IV
## 12: 1 13 7 doxycycline IV
## 13: 1 13 9 doxycycline IV
## 14: 1 13 15 penicillin IV
## 15: 1 13 16 doxycycline IV
## 16: 1 13 18 ciprofloxacin IV
## 17: 8 2 1 doxycycline PO
## 18: 8 2 2 penicillin IV
## 19: 8 2 3 doxycycline IV
## 20: 8 2 6 doxycycline PO
## 21: 8 2 8 penicillin PO
## 22: 8 2 12 penicillin IV
## 23: 8 13 1 doxycycline PO
## 24: 8 13 2 penicillin IV
## 25: 8 13 3 doxycycline IV
## 26: 8 13 6 doxycycline PO
## 27: 8 13 8 penicillin PO
## 28: 8 13 12 penicillin IV
## 29: 23 3 1 doxycycline IV
## 30: 23 3 1 penicillin IV
## patient_id blood_culture_day day_given antibiotic_type route
## last_administration_day days_since_last_admin antibiotic_new
## 1: NA NA 1
## 2: 2 2 0
## 3: 4 2 0
## 4: NA NA 1
## 5: 7 2 0
## 6: NA NA 1
## 7: 9 7 1
## 8: 6 12 1
## 9: NA NA 1
## 10: 2 2 0
## 11: 4 2 0
## 12: NA NA 1
## 13: 7 2 0
## 14: NA NA 1
## 15: 9 7 1
## 16: 6 12 1
## 17: NA NA 1
## 18: NA NA 1
## 19: 1 2 0
## 20: 3 3 1
## 21: 2 6 1
## 22: 8 4 1
## 23: NA NA 1
## 24: NA NA 1
## 25: 1 2 0
## 26: 3 3 1
## 27: 2 6 1
## 28: 8 4 1
## 29: NA NA 1
## 30: NA NA 1
## last_administration_day days_since_last_admin antibiotic_new

Task 5:-
# Make a new variable called drug_in_bcx_window
combinedDT[ , drug_in_bcx_window :=
as.numeric(day_given - blood_culture_day <= 2 &
day_given - blood_culture_day >= -2)]

Task 6:-
# Create a variable indicating if there was at least one I.V. drug given in the window
combinedDT[ ,
any_iv_in_bcx_window := as.numeric(any(route == 'IV' & drug_in_bcx_window ==
1)),
by = .(patient_id, blood_culture_day)]

# Exclude rows in which the blood_culture_day does not have any I.V. drugs in window
combinedDT <- combinedDT[any_iv_in_bcx_window == 1]

Task 7:-
# Create a new variable called day_of_first_new_abx_in_window
combinedDT[ ,
day_of_first_new_abx_in_window :=
day_given[antibiotic_new == 1 & drug_in_bcx_window == 1][1],
by = .(patient_id, blood_culture_day)]

# Remove rows where the day is before this first qualifying day
combinedDT <- combinedDT[day_given >= day_of_first_new_abx_in_window]

Task 8
# Create a new data.table containing only patient_id, blood_culture_day, and day_given
simplified_data <- combinedDT[ , .(patient_id, blood_culture_day, day_given)]

# Remove duplicate rows


simplified_data <- unique(simplified_data)

Task 9
# Count the antibiotic days within each patient/blood culture day combination
simplified_data[ , num_antibiotic_days := .N, by = .(patient_id, blood_culture_day)]
# Remove blood culture days with less than four rows
simplified_data <- simplified_data[num_antibiotic_days >= 4]

# Select the first four days for each blood culture


first_four_days <- simplified_data[ , .SD[1:4], by = .(patient_id, blood_culture_day)]

Task 10:-
# Make the indicator for consecutive sequence
first_four_days[ , four_in_seq := as.numeric(max(diff(day_given)) < 3), by = .
(patient_id, blood_culture_day)]

Task 11:-
# Select the rows which have four_in_seq equal to 1
suspected_infection <- first_four_days[four_in_seq == 1]

# Retain only the patient_id column


suspected_infection <- suspected_infection[ , .(patient_id)]

# Remove duplicates
suspected_infection <- unique(suspected_infection)

# Make an infection indicator


suspected_infection[ , infection := 1]

Task 12:-
# Read in "all_patients.csv"
all_patientsDT <- fread("all_patients.csv")

# Merge this with the infection flag data


all_patientsDT <- merge(all_patientsDT,suspected_infection,by = "patient_id",
all = TRUE)

# Set any missing values of the infection flag to 0


all_patientsDT[is.na(infection) , infection := 0]

# Calculate the percentage of patients who met the criteria for presumed infection
ans <- all_patientsDT[ , 100*mean(infection == 1)]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy