Table 1: Descriptive statistics

Author

Daniel Väisänen

Description

Table 1 descriptive statistics.

Code
library(tidyverse)
library(gtsummary)
library(gt)

data

Code
source(here::here("script", "01_data_source_file.R"))
Code
tbl_1 <- tbl_summary(
  data_cvd |>
    mutate(
      treated = if_else(treated == "HPA", "HPA, overall", treated),
      SSYK = if_else(SSYK == "Military", NA, SSYK),
      SSYK = fct_drop(SSYK, only = "Military"),
      comorbidity = if_else(comorbidity == "=>3", "≥3", comorbidity),
      comorbidity = fct_relevel(comorbidity, "0", "1", "2", "≥3"),
      risk_time_art_unrestricted = risk_time_art_unrestricted / 365.25,
      risk_time_art_10yrs = risk_time_art_10yrs / 365.25
    ),
  statistic = list(
    all_continuous() ~ "{mean} ({sd})",
    all_categorical() ~ "{n} ({p}%)"
  ),
  include = c(
    Age,
    Sex,
    Place_of_origin,
    Civil_status,
    EducationLevel,

    # SSYK,
    SSYK,
    IncomeLevel_CSFVI,
    KommunSize,
    comorbidity,
    cvd_art_before_HPA_flag,
    risk_art_flag_10yrs,
    risk_art_flag_unrestricted,
    risk_time_art_10yrs,
    risk_time_art_unrestricted,

    # Income_Sources_Category,
    # Turnover_Rate_Category,
    # Number_of_employees_Category,
    # Operating_Profit_Margin_Category
  ),
  by = treated, # split table by group., n_tests_within_5_fac
  missing = "ifany", # list missing data if any
  label = list(
    Sex = "Sex",
    Place_of_origin ~ "Place of origin",
    # n_tests_within_5_fac ~ "Number of tests within 5 years",
    cvd_art_before_HPA_flag ~ "CVD (before HPA)",
    risk_art_flag_10yrs ~ "CVD (Within ten years)",
    risk_art_flag_unrestricted ~ "CVD (Unrestricted)",
    risk_time_art_10yrs ~ "Ten year risk time (years)",
    risk_time_art_unrestricted ~ "Unrestricted risk time (years)",
    KommunSize ~ "Municipality",
    Civil_status ~ "Civil status",
    EducationLevel ~ "Education level",
    SSYK ~ "Occupation (since 2001)",
    #SSYK ~ "Occupation",
    comorbidity ~ "Weighted comorbidity index score",
    IncomeLevel_CSFVI ~ "Income (Percentage of median)"
    # Income_Sources_Category ~ "Income sources",
    # Turnover_Rate_Category ~ "Staff turnover",
    # Number_of_employees_Category ~ "Number of employees",
    # Operating_Profit_Margin_Category ~ "Operating profit margin, private sector"
  )
) |>
  bold_labels()
Code
tbl_2 <- tbl_summary(
  data_cvd |>
    filter(treated == "HPA") |>
    mutate(
      n_tests_within_5_fac = factor(
        n_tests_within_5_fac,
        levels = c("HPA, 1 test", "HPA, 2 tests", "HPA, ≥3 tests")
      ),
      SSYK = if_else(SSYK == "Military", NA, SSYK),
      SSYK = fct_drop(SSYK, only = "Military"),
      comorbidity = if_else(comorbidity == "=>3", "≥3", comorbidity),
      comorbidity = fct_relevel(comorbidity, "0", "1", "2", "≥3"),
      risk_time_art_unrestricted = risk_time_art_unrestricted / 365.25,
      risk_time_art_10yrs = risk_time_art_10yrs / 365.25
    ),
  statistic = list(
    all_continuous() ~ "{mean} ({sd})",
    all_categorical() ~ "{n} ({p}%)"
  ),
  include = c(
    Age,
    Sex,
    Place_of_origin,
    Civil_status,
    EducationLevel,

    # SSYK,
    SSYK,
    IncomeLevel_CSFVI,
    KommunSize,
    comorbidity,
    cvd_art_before_HPA_flag,
    risk_art_flag_10yrs,
    risk_art_flag_unrestricted,
    risk_time_art_10yrs,
    risk_time_art_unrestricted,

    # Income_Sources_Category,
    # Turnover_Rate_Category,
    # Number_of_employees_Category,
    # Operating_Profit_Margin_Category
  ),
  by = n_tests_within_5_fac, # split table by group., n_tests_within_5_fac
  missing = "ifany", # list missing data if any
  label = list(
    Sex = "Sex",
    Place_of_origin ~ "Place of origin",
    # n_tests_within_5_fac ~ "Number of tests within 5 years",
    cvd_art_before_HPA_flag ~ "CVD (before HPA)",
    risk_art_flag_10yrs ~ "CVD (Within ten years)",
    risk_art_flag_unrestricted ~ "CVD (Unrestricted)",
    risk_time_art_10yrs ~ "Ten year risk time (years)",
    risk_time_art_unrestricted ~ "Unrestricted risk time (years)",
    KommunSize ~ "Municipality",
    Civil_status ~ "Civil status",
    EducationLevel ~ "Education level",
    SSYK ~ "Occupation (since 2001)",
    #SSYK ~ "Occupation",
    comorbidity ~ "Weighted comorbidity index score",
    IncomeLevel_CSFVI ~ "Income (Percentage of median)"
    # Income_Sources_Category ~ "Income sources",
    # Turnover_Rate_Category ~ "Staff turnover",
    # Number_of_employees_Category ~ "Number of employees",
    # Operating_Profit_Margin_Category ~ "Operating profit margin, private sector"
  )
) |>
  bold_labels()


# merge tables
tbl_merge_ex1 <-
  tbl_merge(
    tbls = list(tbl_1, tbl_2),
    tab_spanner = c(
      "**Main comparison**",
      "**Stratified on number of HPAs within 5-years**"
    )
  ) |>
  as_gt() |>
  tab_options(
    table.font.size = "x-small", # smaller font size
    data_row.padding = px(1), # less padding in data rows
    heading.padding = px(1) # less padding in headings
  )


tbl_merge_ex1
Characteristic
Main comparison
Stratified on number of HPAs within 5-years
Control
N = 1,673,1361
HPA, overall
N = 418,2851
HPA, 1 test
N = 245,9671
HPA, 2 tests
N = 102,3291
HPA, ≥3 tests
N = 69,9891
Age 43 (11) 43 (11) 43 (12) 44 (11) 43 (10)
Sex




    Men 915,856 (55%) 228,953 (55%) 133,065 (54%) 54,483 (53%) 41,405 (59%)
    Women 757,280 (45%) 189,332 (45%) 112,902 (46%) 47,846 (47%) 28,584 (41%)
Place of origin




    Outside Europe 119,357 (7.1%) 15,429 (3.7%) 9,914 (4.0%) 3,566 (3.5%) 1,949 (2.8%)
    Europe 140,276 (8.4%) 26,455 (6.3%) 16,118 (6.6%) 6,458 (6.3%) 3,879 (5.5%)
    Sweden 1,413,370 (84%) 376,385 (90%) 219,924 (89%) 92,300 (90%) 64,161 (92%)
    Unknown 133 16 11 5 0
Civil status




    Partner 770,655 (46%) 201,363 (48%) 115,838 (47%) 50,499 (49%) 35,026 (50%)
    Single 902,481 (54%) 216,922 (52%) 130,129 (53%) 51,830 (51%) 34,963 (50%)
Education level




    Primary 158,955 (9.5%) 38,762 (9.3%) 22,218 (9.1%) 9,938 (9.7%) 6,606 (9.5%)
    Secondary 788,172 (47%) 196,720 (47%) 111,526 (45%) 49,117 (48%) 36,077 (52%)
    Tertiary 717,780 (43%) 181,607 (44%) 111,443 (45%) 43,016 (42%) 27,148 (39%)
    Unknown 8,229 1,196 780 258 158
Occupation (since 2001)




    Managers 92,616 (6.6%) 27,777 (7.3%) 16,361 (7.3%) 6,831 (7.3%) 4,585 (7.6%)
    Science and engineering 60,371 (4.3%) 28,864 (7.6%) 17,440 (7.8%) 6,910 (7.4%) 4,514 (7.4%)
    Health care 44,095 (3.1%) 6,597 (1.7%) 3,914 (1.7%) 1,542 (1.7%) 1,141 (1.9%)
    Education 89,473 (6.4%) 14,235 (3.8%) 9,806 (4.4%) 3,224 (3.5%) 1,205 (2.0%)
    Other professionals 115,713 (8.3%) 36,622 (9.7%) 23,787 (11%) 8,293 (8.9%) 4,542 (7.5%)
    Associate professionals 257,277 (18%) 86,154 (23%) 51,096 (23%) 20,998 (23%) 14,060 (23%)
    Administration and customer service 116,571 (8.3%) 35,794 (9.5%) 21,005 (9.3%) 8,677 (9.3%) 6,112 (10%)
    Manufacturing 61,329 (4.4%) 20,838 (5.5%) 12,293 (5.5%) 4,885 (5.2%) 3,660 (6.0%)
    Mechanical manufacturing 72,451 (5.2%) 33,576 (8.9%) 17,409 (7.7%) 8,670 (9.3%) 7,497 (12%)
    Building 68,878 (4.9%) 19,197 (5.1%) 10,802 (4.8%) 4,741 (5.1%) 3,654 (6.0%)
    Agriculture and forestry 18,261 (1.3%) 2,742 (0.7%) 1,623 (0.7%) 621 (0.7%) 498 (0.8%)
    Service and shop sales 105,214 (7.5%) 13,388 (3.5%) 8,916 (4.0%) 2,953 (3.2%) 1,519 (2.5%)
    Transport 51,210 (3.7%) 7,024 (1.9%) 4,290 (1.9%) 1,658 (1.8%) 1,076 (1.8%)
    Cleaners 24,125 (1.7%) 5,275 (1.4%) 3,030 (1.3%) 1,471 (1.6%) 774 (1.3%)
    Personal care 169,653 (12%) 30,803 (8.1%) 17,159 (7.6%) 9,109 (9.8%) 4,535 (7.5%)
    Other elementary occupations 52,951 (3.8%) 9,673 (2.6%) 5,751 (2.6%) 2,567 (2.8%) 1,355 (2.2%)
    Unknown 272,948 39,726 21,285 9,179 9,262
Income (Percentage of median)




    <60% 242,110 (14%) 11,612 (2.8%) 7,898 (3.2%) 2,482 (2.4%) 1,232 (1.8%)
    60–79% 187,361 (11%) 26,660 (6.4%) 16,271 (6.6%) 6,661 (6.5%) 3,728 (5.3%)
    80–119% 632,737 (38%) 165,260 (40%) 97,500 (40%) 41,652 (41%) 26,108 (37%)
    120–199% 489,023 (29%) 173,695 (42%) 100,528 (41%) 41,883 (41%) 31,284 (45%)
    ≥200% 121,905 (7.3%) 41,058 (9.8%) 23,770 (9.7%) 9,651 (9.4%) 7,637 (11%)
Municipality




    Metropolitan municipalities 547,127 (33%) 115,664 (28%) 69,931 (28%) 26,227 (26%) 19,506 (28%)
    Dense municipalities 742,434 (44%) 204,714 (49%) 121,294 (49%) 50,643 (50%) 32,777 (47%)
    Rural municipalities 381,967 (23%) 97,671 (23%) 54,657 (22%) 25,359 (25%) 17,655 (25%)
    Unknown 1,608 236 85 100 51
Weighted comorbidity index score




    0 1,618,309 (97%) 406,298 (97%) 238,580 (97%) 99,355 (97%) 68,363 (98%)
    1 25,883 (1.5%) 5,563 (1.3%) 3,407 (1.4%) 1,359 (1.3%) 797 (1.1%)
    2 27,036 (1.6%) 6,106 (1.5%) 3,775 (1.5%) 1,541 (1.5%) 790 (1.1%)
    ≥3 1,908 (0.1%) 318 (<0.1%) 205 (<0.1%) 74 (<0.1%) 39 (<0.1%)
CVD (before HPA) 16,308 (1.0%) 3,162 (0.8%) 2,058 (0.8%) 744 (0.7%) 360 (0.5%)
CVD (Within ten years) 31,780 (1.9%) 6,670 (1.6%) 4,085 (1.7%) 1,640 (1.6%) 945 (1.4%)
CVD (Unrestricted) 60,472 (3.6%) 13,228 (3.2%) 7,546 (3.1%) 3,395 (3.3%) 2,287 (3.3%)
Ten year risk time (years) 8.93 (2.01) 8.97 (1.96) 8.74 (2.14) 9.10 (1.82) 9.59 (1.19)
Unrestricted risk time (years) 13.3 (5.8) 13.4 (5.8) 12.6 (5.7) 13.9 (5.7) 15.8 (5.4)
1 Mean (SD); n (%)
Code
gtsave(tbl_merge_ex1, here::here("..", "results", "tables", "table_1.docx"))