Giới thiệu

Bài tiểu luận sử dụng bộ dữ liệu Diabetes Health Indicators (nguồn: Kaggle). Dữ liệu gồm các chỉ số nhân khẩu học và sức khoẻ như tuổi, BMI, huyết áp, đường huyết, HbA1c, thói quen hút thuốc, hoạt động thể chất, v.v.

Mục tiêu:

Mô tả tổng quan dữ liệu

Chuẩn hoá dữ liệu

Phân tích theo điều kiện, phân tổ và trực quan hoá kết quả

Đưa ra nhận xét ban đầu #TỔNG QUAN BỘ DỮ LIỆU

install.packages("DT", repos = "https://cloud.r-project.org")
## Installing package into 'C:/Users/maica/AppData/Local/R/win-library/4.4'
## (as 'lib' is unspecified)
## package 'DT' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\maica\AppData\Local\Temp\RtmpiOib5p\downloaded_packages
install.packages("readxl", repos = "https://cloud.r-project.org")
## Installing package into 'C:/Users/maica/AppData/Local/R/win-library/4.4'
## (as 'lib' is unspecified)
## package 'readxl' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\maica\AppData\Local\Temp\RtmpiOib5p\downloaded_packages
library(DT)
## Warning: package 'DT' was built under R version 4.4.3
library(readxl)
## Warning: package 'readxl' was built under R version 4.4.3
d <- read_excel("C:/Users/maica/Downloads/DU LIEU.xlsx")
datatable(d)
## Warning in instance$preRenderHook(instance): It seems your data is too big for
## client-side DataTables. You may consider server-side processing:
## https://rstudio.github.io/DT/server.html

0.1 Danh sach các biến

names(d)
##  [1] "age"                                "gender"                            
##  [3] "ethnicity"                          "education_level"                   
##  [5] "income_level"                       "employment_status"                 
##  [7] "smoking_status"                     "alcohol_consumption_per_week"      
##  [9] "physical_activity_minutes_per_week" "diet_score"                        
## [11] "sleep_hours_per_day"                "screen_time_hours_per_day"         
## [13] "family_history_diabetes"            "hypertension_history"              
## [15] "cardiovascular_history"             "bmi"                               
## [17] "waist_to_hip_ratio"                 "systolic_bp"                       
## [19] "diastolic_bp"                       "heart_rate"                        
## [21] "cholesterol_total"                  "hdl_cholesterol"                   
## [23] "ldl_cholesterol"                    "triglycerides"                     
## [25] "glucose_fasting"                    "glucose_postprandial"              
## [27] "insulin_level"                      "hba1c"                             
## [29] "diabetes_risk_score"                "diabetes_stage"                    
## [31] "diagnosed_diabetes"

1 Tạo vector tên biến

m <- c("Diabetes_binary", "HighBP", "HighChol", "BMI", "Smoker", "Stroke",
       "HeartDiseaseorAttack", "PhysActivity", "Fruits", "Veggies",
       "HvyAlcoholConsump", "GenHlth", "MentHlth", "PhysHlth",
       "DiffWalk", "Sex", "Age", "Education", "Income")

Mô tả đặc trung của dữ liệu

# Mô tả các đặc trưng của dữ liệu
variable <- c("age", "gender", "ethnicity", "education_level", "income_level",
              "employment_status", "smoking_status", "alcohol_consumption_per_week",
              "physical_activity_minutes_per_week", "diet_score", "sleep_hours_per_day",
              "screen_time_hours_per_day", "family_history_diabetes", "hypertension_history",
              "cardiovascular_history", "bmi", "waist_to_hip_ratio", "systolic_bp",
              "diastolic_bp", "heart_rate", "cholesterol_total", "hdl_cholesterol",
              "ldl_cholesterol", "triglycerides", "glucose_fasting", "glucose_postprandial",
              "insulin_level", "hba1c", "diabetes_risk_score", "diabetes_stage",
              "diagnosed_diabetes")

description <- c(
  "Tuổi của người tham gia khảo sát (tính bằng năm).",
  "Giới tính của người tham gia (Male/Female/Other).",
  "Dân tộc hoặc nhóm chủng tộc (Asian, White, Hispanic, Black...).",
  "Trình độ học vấn cao nhất đạt được (Highschool, Graduate, Postgraduate...).",
  "Mức thu nhập của cá nhân (Low, Lower-Middle, Middle, Upper-Middle, High).",
  "Tình trạng việc làm (Employed, Unemployed, Retired, Student...).",
  "Tình trạng hút thuốc (Never, Former, Current).",
  "Số lần uống rượu/bia trung bình mỗi tuần.",
  "Tổng số phút hoạt động thể chất mỗi tuần.",
  "Điểm đánh giá chế độ ăn uống lành mạnh (càng cao càng tốt).",
  "Số giờ ngủ trung bình mỗi ngày.",
  "Thời gian trung bình nhìn màn hình mỗi ngày (giờ/ngày).",
  "Tiền sử gia đình có người mắc tiểu đường (1: Có, 0: Không).",
  "Có tiền sử cao huyết áp hay không (1: Có, 0: Không).",
  "Có tiền sử bệnh tim mạch hay không (1: Có, 0: Không).",
  "Chỉ số khối cơ thể (BMI).",
  "Tỷ lệ vòng eo/vòng hông.",
  "Huyết áp tâm thu (mmHg).",
  "Huyết áp tâm trương (mmHg).",
  "Nhịp tim (lần/phút).",
  "Tổng lượng cholesterol (mg/dL).",
  "Cholesterol tốt (HDL) (mg/dL).",
  "Cholesterol xấu (LDL) (mg/dL).",
  "Triglycerides trong máu (mg/dL).",
  "Đường huyết khi đói (mg/dL).",
  "Đường huyết sau ăn (mg/dL).",
  "Mức insulin (µU/mL).",
  "Chỉ số HbA1c (%).",
  "Điểm nguy cơ mắc tiểu đường.",
  "Giai đoạn bệnh tiểu đường (No Diabetes, Prediabetes, Type 1, Type 2).",
  "Trạng thái chẩn đoán: 1 = Có bệnh, 0 = Không."
)

variable_description <- data.frame(Ten_bien = variable, Mo_ta_chi_tiet = description)

# Hiển thị bảng
knitr::kable(variable_description, align = "l", caption = "Mô tả các đặc trưng của dữ liệu")
Mô tả các đặc trưng của dữ liệu
Ten_bien Mo_ta_chi_tiet
age Tuổi của người tham gia khảo sát (tính bằng năm).
gender Giới tính của người tham gia (Male/Female/Other).
ethnicity Dân tộc hoặc nhóm chủng tộc (Asian, White, Hispanic, Black…).
education_level Trình độ học vấn cao nhất đạt được (Highschool, Graduate, Postgraduate…).
income_level Mức thu nhập của cá nhân (Low, Lower-Middle, Middle, Upper-Middle, High).
employment_status Tình trạng việc làm (Employed, Unemployed, Retired, Student…).
smoking_status Tình trạng hút thuốc (Never, Former, Current).
alcohol_consumption_per_week Số lần uống rượu/bia trung bình mỗi tuần.
physical_activity_minutes_per_week Tổng số phút hoạt động thể chất mỗi tuần.
diet_score Điểm đánh giá chế độ ăn uống lành mạnh (càng cao càng tốt).
sleep_hours_per_day Số giờ ngủ trung bình mỗi ngày.
screen_time_hours_per_day Thời gian trung bình nhìn màn hình mỗi ngày (giờ/ngày).
family_history_diabetes Tiền sử gia đình có người mắc tiểu đường (1: Có, 0: Không).
hypertension_history Có tiền sử cao huyết áp hay không (1: Có, 0: Không).
cardiovascular_history Có tiền sử bệnh tim mạch hay không (1: Có, 0: Không).
bmi Chỉ số khối cơ thể (BMI).
waist_to_hip_ratio Tỷ lệ vòng eo/vòng hông.
systolic_bp Huyết áp tâm thu (mmHg).
diastolic_bp Huyết áp tâm trương (mmHg).
heart_rate Nhịp tim (lần/phút).
cholesterol_total Tổng lượng cholesterol (mg/dL).
hdl_cholesterol Cholesterol tốt (HDL) (mg/dL).
ldl_cholesterol Cholesterol xấu (LDL) (mg/dL).
triglycerides Triglycerides trong máu (mg/dL).
glucose_fasting Đường huyết khi đói (mg/dL).
glucose_postprandial Đường huyết sau ăn (mg/dL).
insulin_level Mức insulin (µU/mL).
hba1c Chỉ số HbA1c (%).
diabetes_risk_score Điểm nguy cơ mắc tiểu đường.
diabetes_stage Giai đoạn bệnh tiểu đường (No Diabetes, Prediabetes, Type 1, Type 2).
diagnosed_diabetes Trạng thái chẩn đoán: 1 = Có bệnh, 0 = Không.

1.1 Số quan sát và số biến

dim(d)
## [1] 100000     31

1.2 Kiểm tra cấu trúc tổng quát

str(d)
## tibble [100,000 × 31] (S3: tbl_df/tbl/data.frame)
##  $ age                               : num [1:100000] 58 48 60 74 46 46 75 62 42 59 ...
##  $ gender                            : chr [1:100000] "Male" "Female" "Male" "Female" ...
##  $ ethnicity                         : chr [1:100000] "Asian" "White" "Hispanic" "Black" ...
##  $ education_level                   : chr [1:100000] "Highschool" "Highschool" "Highschool" "Highschool" ...
##  $ income_level                      : chr [1:100000] "Lower-Middle" "Middle" "Middle" "Low" ...
##  $ employment_status                 : chr [1:100000] "Employed" "Employed" "Unemployed" "Retired" ...
##  $ smoking_status                    : chr [1:100000] "Never" "Former" "Never" "Never" ...
##  $ alcohol_consumption_per_week      : num [1:100000] 0 1 1 0 1 2 0 1 1 3 ...
##  $ physical_activity_minutes_per_week: num [1:100000] 215 143 57 49 109 124 53 75 114 86 ...
##  $ diet_score                        : num [1:100000] 5.7 6.7 6.4 3.4 7.2 9 9.2 4.1 6.7 8.2 ...
##  $ sleep_hours_per_day               : num [1:100000] 7.9 6.5 10 6.6 7.4 6.2 7.8 9 8.5 5.3 ...
##  $ screen_time_hours_per_day         : num [1:100000] 7.9 8.7 8.1 5.2 5 5.4 8 12.9 8.5 7.4 ...
##  $ family_history_diabetes           : num [1:100000] 0 0 1 0 0 0 0 0 0 0 ...
##  $ hypertension_history              : num [1:100000] 0 0 0 0 0 0 1 1 0 0 ...
##  $ cardiovascular_history            : num [1:100000] 0 0 0 0 0 0 0 1 1 0 ...
##  $ bmi                               : num [1:100000] 30.5 23.1 22.2 26.8 21.2 26.1 25.1 23.9 24.7 26.7 ...
##  $ waist_to_hip_ratio                : num [1:100000] 0.89 0.8 0.81 0.88 0.78 0.85 0.88 0.86 0.84 0.81 ...
##  $ systolic_bp                       : num [1:100000] 134 129 115 120 92 95 129 128 103 124 ...
##  $ diastolic_bp                      : num [1:100000] 78 76 73 93 67 81 77 83 71 81 ...
##  $ heart_rate                        : num [1:100000] 68 67 74 68 67 57 81 76 72 70 ...
##  $ cholesterol_total                 : num [1:100000] 239 116 213 171 210 218 238 241 187 188 ...
##  $ hdl_cholesterol                   : num [1:100000] 41 55 66 50 52 61 46 49 33 52 ...
##  $ ldl_cholesterol                   : num [1:100000] 160 50 99 79 125 119 161 159 132 103 ...
##  $ triglycerides                     : num [1:100000] 145 30 36 140 160 179 155 120 98 104 ...
##  $ glucose_fasting                   : num [1:100000] 136 93 118 139 137 100 101 110 116 76 ...
##  $ glucose_postprandial              : num [1:100000] 236 150 195 253 184 133 100 189 172 109 ...
##  $ insulin_level                     : num [1:100000] 6.36 2 5.07 5.28 12.74 ...
##  $ hba1c                             : num [1:100000] 8.18 5.63 7.51 9.03 7.2 6.03 5.24 7.04 6.9 4.99 ...
##  $ diabetes_risk_score               : num [1:100000] 29.6 23 44.7 38.2 23.5 23.5 36.1 34.2 26.7 30 ...
##  $ diabetes_stage                    : chr [1:100000] "Type 2" "No Diabetes" "Type 2" "Type 2" ...
##  $ diagnosed_diabetes                : num [1:100000] 1 0 1 1 1 0 0 1 1 0 ...

1.3 Thống kê cơ bản

summary(d)
##       age           gender           ethnicity         education_level   
##  Min.   :18.00   Length:100000      Length:100000      Length:100000     
##  1st Qu.:39.00   Class :character   Class :character   Class :character  
##  Median :50.00   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :50.12                                                           
##  3rd Qu.:61.00                                                           
##  Max.   :90.00                                                           
##  income_level       employment_status  smoking_status    
##  Length:100000      Length:100000      Length:100000     
##  Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character  
##                                                          
##                                                          
##                                                          
##  alcohol_consumption_per_week physical_activity_minutes_per_week
##  Min.   : 0.000               Min.   :  0.0                     
##  1st Qu.: 1.000               1st Qu.: 57.0                     
##  Median : 2.000               Median :100.0                     
##  Mean   : 2.004               Mean   :118.9                     
##  3rd Qu.: 3.000               3rd Qu.:160.0                     
##  Max.   :10.000               Max.   :833.0                     
##    diet_score     sleep_hours_per_day screen_time_hours_per_day
##  Min.   : 0.000   Min.   : 3.000      Min.   : 0.500           
##  1st Qu.: 4.800   1st Qu.: 6.300      1st Qu.: 4.300           
##  Median : 6.000   Median : 7.000      Median : 6.000           
##  Mean   : 5.995   Mean   : 6.998      Mean   : 5.996           
##  3rd Qu.: 7.200   3rd Qu.: 7.700      3rd Qu.: 7.700           
##  Max.   :10.000   Max.   :10.000      Max.   :16.800           
##  family_history_diabetes hypertension_history cardiovascular_history
##  Min.   :0.0000          Min.   :0.0000       Min.   :0.0000        
##  1st Qu.:0.0000          1st Qu.:0.0000       1st Qu.:0.0000        
##  Median :0.0000          Median :0.0000       Median :0.0000        
##  Mean   :0.2194          Mean   :0.2508       Mean   :0.0792        
##  3rd Qu.:0.0000          3rd Qu.:1.0000       3rd Qu.:0.0000        
##  Max.   :1.0000          Max.   :1.0000       Max.   :1.0000        
##       bmi        waist_to_hip_ratio  systolic_bp     diastolic_bp   
##  Min.   :15.00   Min.   :0.6700     Min.   : 90.0   Min.   : 50.00  
##  1st Qu.:23.20   1st Qu.:0.8200     1st Qu.:106.0   1st Qu.: 70.00  
##  Median :25.60   Median :0.8600     Median :116.0   Median : 75.00  
##  Mean   :25.61   Mean   :0.8561     Mean   :115.8   Mean   : 75.23  
##  3rd Qu.:28.00   3rd Qu.:0.8900     3rd Qu.:125.0   3rd Qu.: 81.00  
##  Max.   :39.20   Max.   :1.0600     Max.   :179.0   Max.   :110.00  
##    heart_rate     cholesterol_total hdl_cholesterol ldl_cholesterol
##  Min.   : 40.00   Min.   :100       Min.   :20.00   Min.   : 50    
##  1st Qu.: 64.00   1st Qu.:164       1st Qu.:47.00   1st Qu.: 78    
##  Median : 70.00   Median :186       Median :54.00   Median :102    
##  Mean   : 69.63   Mean   :186       Mean   :54.04   Mean   :103    
##  3rd Qu.: 75.00   3rd Qu.:208       3rd Qu.:61.00   3rd Qu.:126    
##  Max.   :105.00   Max.   :318       Max.   :98.00   Max.   :263    
##  triglycerides   glucose_fasting glucose_postprandial insulin_level   
##  Min.   : 30.0   Min.   : 60.0   Min.   : 70          Min.   : 2.000  
##  1st Qu.: 91.0   1st Qu.:102.0   1st Qu.:139          1st Qu.: 5.090  
##  Median :121.0   Median :111.0   Median :160          Median : 8.790  
##  Mean   :121.5   Mean   :111.1   Mean   :160          Mean   : 9.061  
##  3rd Qu.:151.0   3rd Qu.:120.0   3rd Qu.:181          3rd Qu.:12.450  
##  Max.   :344.0   Max.   :172.0   Max.   :287          Max.   :32.220  
##      hba1c       diabetes_risk_score diabetes_stage     diagnosed_diabetes
##  Min.   :4.000   Min.   : 2.70       Length:100000      Min.   :0.0       
##  1st Qu.:5.970   1st Qu.:23.80       Class :character   1st Qu.:0.0       
##  Median :6.520   Median :29.00       Mode  :character   Median :1.0       
##  Mean   :6.521   Mean   :30.22                          Mean   :0.6       
##  3rd Qu.:7.070   3rd Qu.:35.60                          3rd Qu.:1.0       
##  Max.   :9.800   Max.   :67.20                          Max.   :1.0

1.4 Một vài dòng đầu và dòng cuối

library(knitr)
## Warning: package 'knitr' was built under R version 4.4.3
library(kableExtra)
## Warning: package 'kableExtra' was built under R version 4.4.3
head(d, 6) %>%
  kbl(caption = "6 dòng đầu tiên của bộ dữ liệu Diabetes Health Indicators Dataset",
      align = "c") %>%
  kable_paper("hover", full_width = FALSE)
6 dòng đầu tiên của bộ dữ liệu Diabetes Health Indicators Dataset
age gender ethnicity education_level income_level employment_status smoking_status alcohol_consumption_per_week physical_activity_minutes_per_week diet_score sleep_hours_per_day screen_time_hours_per_day family_history_diabetes hypertension_history cardiovascular_history bmi waist_to_hip_ratio systolic_bp diastolic_bp heart_rate cholesterol_total hdl_cholesterol ldl_cholesterol triglycerides glucose_fasting glucose_postprandial insulin_level hba1c diabetes_risk_score diabetes_stage diagnosed_diabetes
58 Male Asian Highschool Lower-Middle Employed Never 0 215 5.7 7.9 7.9 0 0 0 30.5 0.89 134 78 68 239 41 160 145 136 236 6.36 8.18 29.6 Type 2 1
48 Female White Highschool Middle Employed Former 1 143 6.7 6.5 8.7 0 0 0 23.1 0.80 129 76 67 116 55 50 30 93 150 2.00 5.63 23.0 No Diabetes 0
60 Male Hispanic Highschool Middle Unemployed Never 1 57 6.4 10.0 8.1 1 0 0 22.2 0.81 115 73 74 213 66 99 36 118 195 5.07 7.51 44.7 Type 2 1
74 Female Black Highschool Low Retired Never 0 49 3.4 6.6 5.2 0 0 0 26.8 0.88 120 93 68 171 50 79 140 139 253 5.28 9.03 38.2 Type 2 1
46 Male White Graduate Middle Retired Never 1 109 7.2 7.4 5.0 0 0 0 21.2 0.78 92 67 67 210 52 125 160 137 184 12.74 7.20 23.5 Type 2 1
46 Female White Highschool Upper-Middle Employed Never 2 124 9.0 6.2 5.4 0 0 0 26.1 0.85 95 81 57 218 61 119 179 100 133 8.77 6.03 23.5 Pre-Diabetes 0
library(knitr)
library(kableExtra)

tail(d, 6) %>%
  kbl(caption = "6 dòng cuối của bộ dữ liệu Diabetes Health Indicators Dataset",
      align = "c") %>%
  kable_paper("hover", full_width = FALSE)
6 dòng cuối của bộ dữ liệu Diabetes Health Indicators Dataset
age gender ethnicity education_level income_level employment_status smoking_status alcohol_consumption_per_week physical_activity_minutes_per_week diet_score sleep_hours_per_day screen_time_hours_per_day family_history_diabetes hypertension_history cardiovascular_history bmi waist_to_hip_ratio systolic_bp diastolic_bp heart_rate cholesterol_total hdl_cholesterol ldl_cholesterol triglycerides glucose_fasting glucose_postprandial insulin_level hba1c diabetes_risk_score diabetes_stage diagnosed_diabetes
71 Female Hispanic Graduate Lower-Middle Employed Never 1 82 6.3 6.9 4.8 0 1 0 20.5 0.85 132 75 60 141 48 57 30 115 180 3.79 7.01 30.7 Type 2 1
46 Male Other Graduate Upper-Middle Unemployed Former 1 136 8.3 6.4 4.5 0 0 0 29.8 0.93 126 74 63 227 45 150 116 113 109 14.58 5.55 26.0 Pre-Diabetes 0
41 Female White Graduate Middle Employed Never 3 76 8.8 6.8 4.8 0 0 0 26.5 0.86 130 76 57 207 55 123 146 96 146 9.02 5.97 24.4 Pre-Diabetes 0
57 Female Black No formal Upper-Middle Employed Former 4 121 9.9 5.0 6.1 0 0 1 25.6 0.83 107 87 69 189 50 111 184 93 132 2.57 5.21 27.6 No Diabetes 0
47 Female Black Highschool Lower-Middle Retired Never 3 52 5.9 6.7 0.5 0 1 0 26.8 0.89 115 77 58 173 68 91 116 106 117 9.81 5.53 26.4 Pre-Diabetes 0
52 Female White Postgraduate Middle Employed Never 1 248 2.7 5.4 5.5 0 0 0 30.3 1.00 109 77 55 238 31 183 87 91 142 15.93 5.73 27.9 Pre-Diabetes 0

1.5 Kiểm tra NA

sum(is.na(d))
## [1] 0
any(is.na(d))
## [1] FALSE

Vậy bộ dữ liệu không có giá trị thiếu và đã loại bỏ giá trị trùng lặp

1.6 Kiểm tra số lượng bản ghi trùng lặp và loại bỏ trùng lặp

sum(duplicated(d))
## [1] 0

1.7 Chuẩn hóa dữ liệu

# --- Chuẩn hoá dữ liệu số ---
num_cols <- c(
  "age", "physical_activity_minutes_per_week", "diet_score", "bmi", 
  "systolic_bp", "diastolic_bp", "cholesterol_total", "hdl_cholesterol",
  "ldl_cholesterol", "triglycerides", "glucose_fasting", "glucose_postprandial",
  "insulin_level", "hba1c", "diabetes_risk_score"
)
d[num_cols] <- lapply(d[num_cols], function(x) as.numeric(as.character(x)))

2 Chuẩn hoá dữ liệu văn bản

char_cols <- c(
  "gender", "ethnicity", "education_level", "income_level", "employment_status",
  "smoking_status", "diabetes_stage"
)
d[char_cols] <- lapply(d[char_cols], function(x) trimws(as.character(x)))

3 Làm sạch tên cột

colnames(d) <- make.names(trimws(colnames(d)), unique = TRUE)

4 Kiểm tra kết quả

str(d)
## tibble [100,000 × 31] (S3: tbl_df/tbl/data.frame)
##  $ age                               : num [1:100000] 58 48 60 74 46 46 75 62 42 59 ...
##  $ gender                            : chr [1:100000] "Male" "Female" "Male" "Female" ...
##  $ ethnicity                         : chr [1:100000] "Asian" "White" "Hispanic" "Black" ...
##  $ education_level                   : chr [1:100000] "Highschool" "Highschool" "Highschool" "Highschool" ...
##  $ income_level                      : chr [1:100000] "Lower-Middle" "Middle" "Middle" "Low" ...
##  $ employment_status                 : chr [1:100000] "Employed" "Employed" "Unemployed" "Retired" ...
##  $ smoking_status                    : chr [1:100000] "Never" "Former" "Never" "Never" ...
##  $ alcohol_consumption_per_week      : num [1:100000] 0 1 1 0 1 2 0 1 1 3 ...
##  $ physical_activity_minutes_per_week: num [1:100000] 215 143 57 49 109 124 53 75 114 86 ...
##  $ diet_score                        : num [1:100000] 5.7 6.7 6.4 3.4 7.2 9 9.2 4.1 6.7 8.2 ...
##  $ sleep_hours_per_day               : num [1:100000] 7.9 6.5 10 6.6 7.4 6.2 7.8 9 8.5 5.3 ...
##  $ screen_time_hours_per_day         : num [1:100000] 7.9 8.7 8.1 5.2 5 5.4 8 12.9 8.5 7.4 ...
##  $ family_history_diabetes           : num [1:100000] 0 0 1 0 0 0 0 0 0 0 ...
##  $ hypertension_history              : num [1:100000] 0 0 0 0 0 0 1 1 0 0 ...
##  $ cardiovascular_history            : num [1:100000] 0 0 0 0 0 0 0 1 1 0 ...
##  $ bmi                               : num [1:100000] 30.5 23.1 22.2 26.8 21.2 26.1 25.1 23.9 24.7 26.7 ...
##  $ waist_to_hip_ratio                : num [1:100000] 0.89 0.8 0.81 0.88 0.78 0.85 0.88 0.86 0.84 0.81 ...
##  $ systolic_bp                       : num [1:100000] 134 129 115 120 92 95 129 128 103 124 ...
##  $ diastolic_bp                      : num [1:100000] 78 76 73 93 67 81 77 83 71 81 ...
##  $ heart_rate                        : num [1:100000] 68 67 74 68 67 57 81 76 72 70 ...
##  $ cholesterol_total                 : num [1:100000] 239 116 213 171 210 218 238 241 187 188 ...
##  $ hdl_cholesterol                   : num [1:100000] 41 55 66 50 52 61 46 49 33 52 ...
##  $ ldl_cholesterol                   : num [1:100000] 160 50 99 79 125 119 161 159 132 103 ...
##  $ triglycerides                     : num [1:100000] 145 30 36 140 160 179 155 120 98 104 ...
##  $ glucose_fasting                   : num [1:100000] 136 93 118 139 137 100 101 110 116 76 ...
##  $ glucose_postprandial              : num [1:100000] 236 150 195 253 184 133 100 189 172 109 ...
##  $ insulin_level                     : num [1:100000] 6.36 2 5.07 5.28 12.74 ...
##  $ hba1c                             : num [1:100000] 8.18 5.63 7.51 9.03 7.2 6.03 5.24 7.04 6.9 4.99 ...
##  $ diabetes_risk_score               : num [1:100000] 29.6 23 44.7 38.2 23.5 23.5 36.1 34.2 26.7 30 ...
##  $ diabetes_stage                    : chr [1:100000] "Type 2" "No Diabetes" "Type 2" "Type 2" ...
##  $ diagnosed_diabetes                : num [1:100000] 1 0 1 1 1 0 0 1 1 0 ...
DT::datatable(
  head(d, 10),  # hiển thị 10 dòng đầu tiên của dữ liệu 'd'
  options = list(
    pageLength = 10,   # số dòng mỗi trang
    autoWidth = TRUE   # tự động căn độ rộng cột
  ),
  rownames = FALSE,     # ẩn cột số thứ tự mặc định
  caption = htmltools::tags$caption(
    style = 'caption-side: top; text-align: left;',
    '📊 Bảng hiển thị tương tác 10 dòng đầu sau chuẩn hoá'
  )
)

5 Lọc bệnh nhân đã được chẩn đoán tiểu đường

d1 <- d %>% filter(diagnosed_diabetes == 1)

# Hiển thị 5 dòng đầu tiên
DT::datatable(head(d1, 5), 
              options = list(pageLength = 5, autoWidth = TRUE),
              rownames = FALSE,
              caption = htmltools::tags$caption(
                style = 'caption-side: top; text-align: left;',
                '📋 Bảng 1.9.1: Bệnh nhân được chẩn đoán tiểu đường'))

6 Lọc bệnh nhân tiểu đường loại 2 và có glucose_fasting > 126

d2_and <- d %>%
  filter(diabetes_stage == "Type 2", glucose_fasting > 126)

# Hiển thị một số cột liên quan
DT::datatable(
  head(d2_and[, c("age", "gender", "glucose_fasting", "hba1c", "diabetes_stage")], 5),
  options = list(pageLength = 5, autoWidth = TRUE),
  rownames = FALSE,
  caption = htmltools::tags$caption(
    style = 'caption-side: top; text-align: left;',
    '📋 Bảng 1.9.2: Bệnh nhân tiểu đường loại 2 có đường huyết lúc đói > 126 mg/dL'
  )
)

7 Kết luận

Kết luận

Dữ liệu đã được kiểm tra NA, trùng lặp và chuẩn hoá.

Có sự khác biệt rõ ràng về BMI giữa nhóm mắc và không mắc tiểu đường.

Có thể mở rộng phân tích hồi quy logistic dự báo nguy cơ tiểu đường từ BMI, huyết áp, HbA1c…