library(readr) patients <-read_csv("/Users/baritebedasso/Desktop/HINF 5531 Course Project Data Files/patients.csv", na ="NULL")
Rows: 500000 Columns: 15
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (12): first_name, middle_initial, last_name, gender, race, religion, ma...
dbl (2): patient_id, zip
date (1): birth_date
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
library(readr)disease_types <-read_csv("/Users/baritebedasso/Desktop/HINF 5531 Course Project Data Files/disease_types.csv", na ="NULL")
Rows: 9175 Columns: 3
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): icd9cm, name
dbl (1): disease_id
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
library(readr)diseases <-read_csv("/Users/baritebedasso/Desktop/HINF 5531 Course Project Data Files/diseases.csv", na ="NULL")
Rows: 9687836 Columns: 3
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (2): encounter_id, disease_id
dttm (1): date
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
medications <-read_csv("/Users/baritebedasso/Desktop/HINF 5531 Course Project Data Files/medications.csv", na ="NULL")
Rows: 2704000 Columns: 9
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): dose_units, rate_units
dbl (6): medications_id, encounter_id, medication_id, patient_id, dose, rate
dttm (1): date
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
medication_types <-read_csv("/Users/baritebedasso/Desktop/HINF 5531 Course Project Data Files/medication_types.csv", na ="NULL")
Rows: 2330 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (6): medication_name, class, strength, strength_units, form, route
dbl (1): medication_id
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
providers <-read_csv("/Users/baritebedasso/Desktop/HINF 5531 Course Project Data Files/providers.csv", na ="NULL")
Rows: 6097 Columns: 6
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (5): first_name, middle_initial, last_name, gender, status
dbl (1): provider_id
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
departments <-read_csv("/Users/baritebedasso/Desktop/HINF 5531 Course Project Data Files/departments.csv", na ="NULL")
Rows: 74 Columns: 2
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (1): department_name
dbl (1): department_id
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
encounters <-read_csv("/Users/baritebedasso/Desktop/HINF 5531 Course Project Data Files/encounters.csv", na ="NULL")
Rows: 8673082 Columns: 13
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (11): encounter_id, patient_id, department_id, provider_id, age, bp_sys...
dttm (2): admit_date, discharge_date
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
B) Data Summary:
num_patients <-nrow(patients)print(num_patients)
[1] 500000
Counts
a. 500,000 patients
b. 8,673,082 encountter
c. 2330 medication types
d. 2,704,000 medications
e. 9,175 disease types
f. 9,687,836 diseases
g. 74 departments
h. 6,097 providers
i.
library(knitr)library(reshape2)library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
# A tibble: 20 × 4
# Groups: gender [2]
gender race mean_bmi n
<chr> <chr> <dbl> <int>
1 F AFRICAN AMERICAN 40.0 141709
2 F ASIAN 28.6 80674
3 F CAUCASIAN 62.6 4034298
4 F DECLINED 26.8 19686
5 F HISPANIC 108. 82642
6 F MULTIRACIAL 21.6 9122
7 F NATIVE AMERICAN 88.0 18394
8 F OTHER 29.5 71745
9 F PACIFIC ISLANDER 26.2 438
10 F UNKNOWN 32.5 457225
11 M AFRICAN AMERICAN 52.3 120917
12 M ASIAN 25.8 46086
13 M CAUCASIAN 454. 2989968
14 M DECLINED 26.1 17970
15 M HISPANIC 54.6 64843
16 M MULTIRACIAL 28.6 8587
17 M NATIVE AMERICAN 70.4 9764
18 M OTHER 30.9 65407
19 M PACIFIC ISLANDER 25.3 752
20 M UNKNOWN 35.9 432855
gender department_name mean_los
Length:131 Length:131 Min. : 2.000
Class :character Class :character 1st Qu.: 4.863
Mode :character Mode :character Median : 6.952
Mean : 14.145
3rd Qu.: 9.483
Max. :367.000
kable(head(gender_dept_los_summary), n=10)
gender
department_name
mean_los
F
ALLERGY AND IMMUNOLOGY
5.333333
F
ANESTHESIOLOGY
7.428571
F
AUDIOLOGY
8.000000
F
BEHAVIORAL HEALTH
9.428730
F
BURN UNIT
16.237654
F
CANCER CENTER
5.315790
D) Data Visualization
library(ggplot2)hist(encounters$age, main="Histogram of Patient Age(y) at Time of Encounter", xlab="Age", ylab="Frequency", breaks =20)
2.
library(ggplot2)encounter_counts <-select(encounters, patient_id,encounter_id)encounter_counts <- encounter_counts %>%count(encounter_id, name ="Encounter_Count")ggplot(data = encounter_counts, aes(x = encounter_id)) +geom_histogram(binwidth =50) +labs(title ="Histogram of Number of Encounters", x ="Number of Encounters", y ="Count")
library(ggplot2)hist_plot <-ggplot(data = patient_enc, aes(x = age, y =log(BMI), color = gender)) +geom_point() +labs(title ="Scatterplot of BMI by Age", x ="Age", y ="log(BMI)") +scale_color_manual(values =c("skyblue", "pink"), labels =c("Male", "Female"))print(hist_plot)
Warning: Removed 8134993 rows containing missing values or values outside the scale
range (`geom_point()`).
Scale for colour is already present.
Adding another scale for colour, which will replace the existing scale.
panel
Warning: Removed 8134993 rows containing missing values or values outside the scale
range (`geom_point()`).
Removed 8134993 rows containing missing values or values outside the scale
range (`geom_point()`).
E) Missing Values
Missing data in key variables like height, weight, systolic and diastolic blood pressure can significantly impact analyses and lead to biased results. Missing height and weight data can prevents accurate calculation of body mass index (BMI), a crucial measure of body composition and health risk assessment. It will create bias analysis related to obesity, overweight prevalence, and associations between BMI and other health outcomes. Missing blood pressure data impairs assessment of hypertension prevalence and cardiovascular disease risk. It limits analyses examining relationships between blood pressure and other factors like age, BMI, etc. It can also affect the identification of individuals requiring hypertension treatment and management.
F) Data validation
The encounters dataset may contain unreasonable values in certain variables like age, blood pressure (both systolic and diastolic), BMI, and temperature. Such extreme values could signal data errors, inconsistencies, or anomalies. Employing data validation techniques is crucial for identifying and addressing outliers or incorrect entries. Depending on the severity and nature of these values, they might be treated as missing data or marked for further scrutiny. Additionally, it’s essential to scrutinize duplicated data, where multiple entries share identical patient identifiers and relevant variables. These duplicates could stem from data entry errors, system glitches, or other issues and must be carefully examined and resolved to ensure data integrity and prevent biases in analysis.
Part 2
Validating ages:
This script calculates the percentage accuracy of age information in the patient_enc dataset. It first creates a new variable expected_age, which computes the age of each patient based on the difference between their admission date (admit_date) and birth date (birth_date). Then, it creates another variable accurate_age that evaluates whether the calculated age matches the provided age in the dataset. Finally, it calculates the percentage of accurate age information by dividing the count of accurate ages by the total number of rows in the dataset (nrow(patient_enc)) and multiplying by 100. The calculated percentage of accurate encounter-specific ages in the dataset is approximately 0.0784%., indicating a very low accuracy rate.
Anonymity and de-identification. To de-identify data, personally identifiable information (PII) like names, addresses, and social security numbers should be entirely removed. Birth dates can be generalized by categorizing them into broader age ranges or retaining only the birth year. Geographic data, like precise addresses or zip codes, can either be generalized to larger regions or removed altogether. Variables indirectly identifying individuals, such as unique identifiers or specific medical conditions, should be carefully evaluated and potentially anonymized or generalized. Techniques like data masking, which involves replacing specific values with consistent pseudonyms or assigning random identifiers, can safeguard sensitive information. The extent of de-identification should be determined considering the context, relevant regulations, and the necessity to balance data utility with privacy protection.