# ---- Packages ----library(dplyr)library(readxl)library(gtsummary)library(gt)# ---- Read data ----hpv_data <- readxl::read_xlsx("C:/Users/VUSI/Downloads/hpv_data.xlsx")# ---- Clean: only replace empty strings in character columns ----hpv_data <- hpv_data %>%mutate(across(where(is.character), ~na_if(.x, "")))# ---- Fix common typo and set factors ----hpv_data <- hpv_data %>%mutate(HPV_Type_of_Infection =recode(HPV_Type_of_Infection, "Mulitple"="Multiple"),HPV_Type_of_Infection =factor(HPV_Type_of_Infection, levels =c("Single", "Multiple")),HPV_type_status =factor( HPV_type_status,levels =c("Low-risk HPV", "High-risk HPV", "Both low-risk and high-risk") ) )# ---- Identify HPV type columns ----hpv_cols <- hpv_data %>%select(matches("^HPV(16|18|26|31|33|35|39|45|51|52|53|56|58|59|66|68|69|73|82|6|11|40|42|43|44|54|61|70)$")) %>%names()# ---- Ensure HPV columns are ordered categorical (Low < Intermediate < High) ----hpv_data <- hpv_data %>%mutate(across(all_of(hpv_cols), ~as.character(.x)),across(all_of(hpv_cols), ~factor(.x, levels =c("Low","Intermediate","High"), ordered =TRUE)) )# ========= Choose which TWO HPV statuses to present and merge =========status_left <-"High-risk HPV"status_right <-"Low-risk HPV"# (Change the strings above if you prefer another pair, e.g., "Both low-risk and high-risk")# ---- Build LEFT table (e.g., High-risk HPV) ----hpv_left <- hpv_data %>%filter(HPV_type_status == status_left) %>%select(HPV_Type_of_Infection, all_of(hpv_cols)) %>%tbl_summary(by = HPV_Type_of_Infection,statistic =all_categorical() ~"{n} ({p}%)",missing_text ="Missing" ) %>%add_overall() %>%modify_header(label ~"**HPV Type**") %>%bold_labels()# ---- Build RIGHT table (e.g., Low-risk HPV) ----hpv_right <- hpv_data %>%filter(HPV_type_status == status_right) %>%select(HPV_Type_of_Infection, all_of(hpv_cols)) %>%tbl_summary(by = HPV_Type_of_Infection,statistic =all_categorical() ~"{n} ({p}%)",missing_text ="Missing" ) %>%add_overall() %>%modify_header(label ~"**HPV Type**") %>%bold_labels()# ---- MERGE the two tables side-by-side ----hpv_merged <-tbl_merge(tbls =list(hpv_left, hpv_right),tab_spanner =c(paste0("**", status_left, "**"),paste0("**", status_right, "**")))# ---- Add caption and render with gt styling ----hpv_gt <- hpv_merged %>%modify_caption("**HPV Infection Distribution by Type of Infection (Merged by HPV Status)**") %>%as_gt() %>% gt::tab_options(table.font.size ="small",heading.align ="center" ) %>% gt::tab_style(style =cell_text(weight ="bold", color ="darkblue"),locations =cells_title(groups ="title") )hpv_gt
HPV Infection Distribution by Type of Infection (Merged by HPV Status)
HPV Type
High-risk HPV
Low-risk HPV
Overall
N = 211
Single
N = 151
Multiple
N = 61
Overall
N = 81
Single
N = 81
Multiple
N = 01
HPV16
Low
2 (50%)
0 (0%)
2 (67%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
2 (50%)
1 (100%)
1 (33%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (0%)
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
17
14
3
8
8
0
HPV18
Low
3 (75%)
2 (67%)
1 (100%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
1 (25%)
1 (33%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (0%)
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
17
12
5
8
8
0
HPV26
Low
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
21
15
6
8
8
0
HPV31
Low
1 (100%)
1 (100%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
20
14
6
8
8
0
HPV33
Low
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
21
15
6
8
8
0
HPV35
Low
2 (67%)
0 (0%)
2 (100%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
1 (33%)
1 (100%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (0%)
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
18
14
4
8
8
0
HPV39
Low
1 (100%)
1 (100%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
20
14
6
8
8
0
HPV45
Low
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
21
15
6
8
8
0
HPV51
Low
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
High
1 (100%)
1 (100%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
20
14
6
8
8
0
HPV52
Low
1 (50%)
1 (100%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
1 (50%)
0 (0%)
1 (100%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (0%)
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
19
14
5
8
8
0
HPV53
Low
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
21
15
6
8
8
0
HPV56
Low
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
1 (100%)
1 (100%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
20
14
6
8
8
0
HPV58
Low
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
21
15
6
8
8
0
HPV59
Low
0 (0%)
0 (NA%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
1 (100%)
0 (NA%)
1 (100%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (0%)
0 (NA%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
20
15
5
8
8
0
HPV66
Low
1 (100%)
0 (NA%)
1 (100%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
0 (0%)
0 (NA%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (0%)
0 (NA%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
20
15
5
8
8
0
HPV68
Low
3 (100%)
3 (100%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
18
12
6
8
8
0
HPV69
Low
0 (0%)
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
1 (50%)
1 (100%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
High
1 (50%)
0 (0%)
1 (100%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
19
14
5
8
8
0
HPV73
Low
0 (0%)
0 (NA%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
1 (100%)
0 (NA%)
1 (100%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (0%)
0 (NA%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
20
15
5
8
8
0
HPV82
Low
2 (100%)
1 (100%)
1 (100%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
0 (0%)
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (0%)
0 (0%)
0 (0%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
19
14
5
8
8
0
HPV6
Low
0 (NA%)
0 (NA%)
0 (NA%)
0 (0%)
0 (0%)
0 (NA%)
Intermediate
0 (NA%)
0 (NA%)
0 (NA%)
1 (50%)
1 (50%)
0 (NA%)
High
0 (NA%)
0 (NA%)
0 (NA%)
1 (50%)
1 (50%)
0 (NA%)
Missing
21
15
6
6
6
0
HPV11
Low
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
21
15
6
8
8
0
HPV40
Low
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
21
15
6
8
8
0
HPV42
Low
0 (NA%)
0 (NA%)
0 (NA%)
1 (50%)
1 (50%)
0 (NA%)
Intermediate
0 (NA%)
0 (NA%)
0 (NA%)
1 (50%)
1 (50%)
0 (NA%)
High
0 (NA%)
0 (NA%)
0 (NA%)
0 (0%)
0 (0%)
0 (NA%)
Missing
21
15
6
6
6
0
HPV43
Low
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
21
15
6
8
8
0
HPV44
Low
0 (NA%)
0 (NA%)
0 (NA%)
0 (0%)
0 (0%)
0 (NA%)
Intermediate
0 (NA%)
0 (NA%)
0 (NA%)
2 (100%)
2 (100%)
0 (NA%)
High
0 (NA%)
0 (NA%)
0 (NA%)
0 (0%)
0 (0%)
0 (NA%)
Missing
21
15
6
6
6
0
HPV54
Low
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Intermediate
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
High
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
0 (NA%)
Missing
21
15
6
8
8
0
HPV61
Low
0 (NA%)
0 (NA%)
0 (NA%)
1 (100%)
1 (100%)
0 (NA%)
Intermediate
0 (NA%)
0 (NA%)
0 (NA%)
0 (0%)
0 (0%)
0 (NA%)
High
0 (NA%)
0 (NA%)
0 (NA%)
0 (0%)
0 (0%)
0 (NA%)
Missing
21
15
6
7
7
0
HPV70
Low
0 (NA%)
0 (NA%)
0 (NA%)
1 (100%)
1 (100%)
0 (NA%)
Intermediate
0 (NA%)
0 (NA%)
0 (NA%)
0 (0%)
0 (0%)
0 (NA%)
High
0 (NA%)
0 (NA%)
0 (NA%)
0 (0%)
0 (0%)
0 (NA%)
Missing
21
15
6
7
7
0
1 n (%)
1. Probability of HPV DNA positivity vs CD4 count (logistic regression smooth):
This plot shows the modeled probability of HPV DNA positivity across the spectrum of CD4 counts. The fitted blue line indicates that the likelihood of HPV positivity is highest at lower CD4 counts and steadily decreases as CD4 count rises, reflecting immune recovery. The shaded gray region represents the 95% confidence interval around the predicted probabilities, showing uncertainty increases at the extremes. Overall, the plot demonstrates an inverse relationship: women with lower CD4 counts have a higher probability of being HPV DNA positive, while those with higher CD4 counts are less likely to test positive.
2. CD4 count distribution by HPV DNA status (violin and boxplots):
This violin plot compares the distribution of CD4 counts between HPV DNA–negative and HPV DNA–positive groups. The HPV-negative group displays a wider spread of CD4 counts, with many individuals reaching higher counts (>1000 cells/µL). In contrast, the HPV-positive group shows a tighter distribution, with most values clustered at lower CD4 counts (generally <500 cells/µL). The overlaid boxplots confirm this difference: the median CD4 count in the HPV-negative group is higher than in the HPV-positive group. This indicates that HPV positivity is more common among individuals with suppressed immune status (lower CD4 counts).
3. HPV DNA prevalence by CD4 count category (proportions with 95% CI):
This prevalence plot summarizes HPV positivity across ordered CD4 count categories. The prevalence of HPV DNA is highest in the lowest CD4 stratum (0–200 cells/µL) and decreases progressively across higher categories, reaching the lowest levels in the 501–1000 group. The confidence intervals are wider in the extreme categories (0–200 and >1000), reflecting smaller sample sizes and greater uncertainty in those groups. The overall pattern reinforces the trend observed in the logistic regression: HPV DNA positivity is more prevalent in individuals with lower CD4 counts, supporting the conclusion that immunosuppression increases the risk of HPV persistence or acquisition.