Last updated: 2024-06-12

Checks: 5 2

Knit directory: dynamicHRpaper/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown is untracked by Git. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20240612) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Using absolute paths to the files within your workflowr project makes it difficult for you and others to run your code on a different machine. Change the absolute path(s) below to the suggested relative path(s) to make your code more reproducible.

absolute relative
~/dynamicHRpaper/ .

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 9d06964. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Untracked files:
    Untracked:  Figs/
    Untracked:  analysis/.DS_Store
    Untracked:  analysis/Fig1.Rmd
    Untracked:  analysis/Fig1_pcesd.Rmd
    Untracked:  analysis/Fig1b.Rmd
    Untracked:  analysis/Fig2.Rmd
    Untracked:  analysis/Figure3.Rmd
    Untracked:  analysis/Figure4.Rmd
    Untracked:  analysis/GenerationofRawFiles/
    Untracked:  analysis/NRI.Rmd
    Untracked:  analysis/Sex_analyses.Rmd
    Untracked:  analysis/SuppASCVD.Rmd
    Untracked:  analysis/Supplemental_CI.Rmd
    Untracked:  analysis/density.Rmd
    Untracked:  analysis/newtables.Rmd
    Untracked:  analysis/zph.Rmd
    Untracked:  code/utils.R
    Untracked:  data/amit_df.rds
    Untracked:  data/amit_df_with_pc_correction.rds
    Untracked:  data/baseline_withPCS.rds
    Untracked:  data/fh_full.rds
    Untracked:  data/fh_prs.rds
    Untracked:  data/fhs_prs_with_pc_corrrection.rds
    Untracked:  data/followupdates.rds
    Untracked:  data/genotype_data_nodup.eigenvec
    Untracked:  output/amit_df_with_pc_correction.rds
    Untracked:  output/fhs_prs_with_pc_corrrection
    Untracked:  output/fhs_prs_with_pc_corrrection.rds
    Untracked:  output/h1hs_withPC.rds
    Untracked:  output/hall_withPC.rds
    Untracked:  output/hallpce.rds
    Untracked:  output/hazards_fh_EQ_withPC_corrections.rds
    Untracked:  output/hazards_fh_EQ_withPC_corrections_sex0.rds
    Untracked:  output/hazards_fh_EQ_withPC_corrections_sex1.rds
    Untracked:  output/hazards_rate_UKB_amit_EQ_withPCcorrection.rds
    Untracked:  output/hazards_rate_lowerbound_amit_EQ_withPCcorrection.rds
    Untracked:  output/hazards_rate_lowerbound_fh_EQ_withPC_corrections.rds
    Untracked:  output/hazards_rate_lowerbound_fh_EQ_withPC_corrections_sex0.rds
    Untracked:  output/hazards_rate_lowerbound_fh_EQ_withPC_corrections_sex1.rds
    Untracked:  output/hazards_rate_upperbound_amit_EQ_withPCcorrection.rds
    Untracked:  output/hazards_rate_upperbound_fh_EQ_withPC_corrections.rds
    Untracked:  output/hazards_rate_upperbound_fh_EQ_withPC_corrections_sex0.rds
    Untracked:  output/hazards_rate_upperbound_fh_EQ_withPC_corrections_sex1.rds
    Untracked:  output/hrindex_fhs_eq_with_pc.csv
    Untracked:  output/hrindex_ukb_eq.csv
    Untracked:  output/r2_withPC.rds
    Untracked:  output/r2fhs_withPC.rds
    Untracked:  output/r2index_fhs_eq_with_pc.csv
    Untracked:  output/r2index_ukb_eq.csv
    Untracked:  output/r2pce.rds

Unstaged changes:
    Modified:   .DS_Store
    Modified:   analysis/about.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


generate FHS hazard mat

setwd("~/dynamicHRpaper/")

data_female=readRDS("output/hazards_fh_EQ_withPC_corrections_sex0.rds")
data_female$age=c(18:57)
data_male=readRDS("output/hazards_fh_EQ_withPC_corrections_sex1.rds")
data_male$age=c(18:57)
# Melt the data for ggplot2
data_male_melted <- melt(data_male, id.vars = "age")
Warning: The melt generic in data.table has been passed a data.frame and will
attempt to redirect to the relevant reshape2 method; please note that reshape2
is superseded and is no longer actively developed, and this redirection is now
deprecated. To continue using melt methods from reshape2 while both libraries
are attached, e.g. melt.list, you can prepend the namespace, i.e.
reshape2::melt(data_male). In the next version, this warning will become an
error.
data_female_melted <- melt(data_female, id.vars = "age")
Warning: The melt generic in data.table has been passed a data.frame and will
attempt to redirect to the relevant reshape2 method; please note that reshape2
is superseded and is no longer actively developed, and this redirection is now
deprecated. To continue using melt methods from reshape2 while both libraries
are attached, e.g. melt.list, you can prepend the namespace, i.e.
reshape2::melt(data_female). In the next version, this warning will become an
error.
# Add a column to differentiate male and female data
data_male_melted$sex <- "Male"
data_female_melted$sex <- "Female"


# Combine the data
data_combined <- rbind(data_male_melted, data_female_melted)
hr=data_combined[grep(data_combined$variable,pattern="HR"),]
hr=hr[hr$variable%in%c("prs.HR","ldl.HR","smoke.HR","age.HR","sbp.HR","hdl.HR"),]
# Plot the data
ggplot(hr, aes(x = age, y = value, color = sex, shape = sex,fill=sex)) +
  geom_smooth() +
  facet_wrap(~ variable, scales = "free_y") +
  labs(
    title = "Hazard Ratios by Variable and Sex",
    x = "Age",
    y = "Hazard Ratio"
  ) +
  theme_classic()
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'

d2=readRDS("data/followupdates.rds")
d2 <- d2 %>%
  rowwise() %>%
  mutate(follow_up_days = max(c_across(starts_with("DATE")), na.rm = TRUE),
         follow_up_years = follow_up_days / 365,
         end_age = AGEENROLL + follow_up_years) %>%
  ungroup()

# Plot the follow-up period by sex
ggplot(d2[d2$AGEENROLL>18&d2$follow_up_years>10,], aes(x = AGEENROLL, y = end_age,col=as.factor(SEX))) +
  geom_point() +
  labs(
    title = "Follow-up Period by Sex",
    x = "Sex",
    y = "Follow-up Period (years)"
  ) +scale_color_manual(values = c("1" = "blue", "2" = "red"), labels = c("1" = "Male", "2" = "Female")) +
  theme_classic()+labs(x="Age of Enrollment",y="End Followup",col="Sex")+geom_vline(xintercept = 51, linetype = "dashed", color = "black", size = 0.7) 
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
This warning is displayed once every 8 hours.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
generated.


sessionInfo()
R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.5

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] babynames_1.0.1    gapminder_1.0.0    carData_3.0-5      plotly_4.10.4     
 [5] DT_0.33            gt_0.10.1          RColorBrewer_1.1-3 data.table_1.15.4 
 [9] pROC_1.18.5        rsq_2.6            survMisc_0.5.6     gridExtra_2.3     
[13] ggfortify_0.4.17   reshape_0.8.9      eulerr_7.0.2       survminer_0.4.9   
[17] ggpubr_0.6.0       survival_3.5-8     lubridate_1.9.3    forcats_1.0.0     
[21] stringr_1.5.1      purrr_1.0.2        readr_2.1.5        tidyr_1.3.1       
[25] tibble_3.2.1       ggplot2_3.5.1      tidyverse_2.0.0    dplyr_1.1.4       

loaded via a namespace (and not attached):
 [1] rlang_1.1.4       magrittr_2.0.3    git2r_0.33.0      deming_1.4       
 [5] compiler_4.4.0    mgcv_1.9-1        vctrs_0.6.5       reshape2_1.4.4   
 [9] crayon_1.5.2      pkgconfig_2.0.3   fastmap_1.2.0     backports_1.5.0  
[13] labeling_0.4.3    KMsurv_0.1-5      utf8_1.2.4        promises_1.3.0   
[17] rmarkdown_2.26    tzdb_0.4.0        nloptr_2.0.3      xfun_0.44        
[21] cachem_1.1.0      jsonlite_1.8.8    highr_0.10        later_1.3.2      
[25] Deriv_4.1.3       broom_1.0.6       R6_2.5.1          bslib_0.7.0      
[29] stringi_1.8.4     car_3.1-2         boot_1.3-30       jquerylib_0.1.4  
[33] Rcpp_1.0.12       knitr_1.46        zoo_1.8-12        httpuv_1.6.15    
[37] Matrix_1.7-0      splines_4.4.0     timechange_0.3.0  tidyselect_1.2.1 
[41] rstudioapi_0.16.0 abind_1.4-5       yaml_2.3.8        lattice_0.22-6   
[45] plyr_1.8.9        withr_3.0.0       evaluate_0.23     xml2_1.3.6       
[49] pillar_1.9.0      generics_0.1.3    rprojroot_2.0.4   hms_1.1.3        
[53] munsell_0.5.1     scales_1.3.0      minqa_1.2.7       xtable_1.8-4     
[57] glue_1.7.0        lazyeval_0.2.2    tools_4.4.0       lme4_1.1-35.3    
[61] ggsignif_0.6.4    fs_1.6.4          grid_4.4.0        colorspace_2.1-0 
[65] nlme_3.1-164      cli_3.6.2         km.ci_0.5-6       workflowr_1.7.1  
[69] fansi_1.0.6       viridisLite_0.4.2 gtable_0.3.5      rstatix_0.7.2    
[73] sass_0.4.9        digest_0.6.35     farver_2.1.2      htmlwidgets_1.6.4
[77] htmltools_0.5.8.1 lifecycle_1.0.4   httr_1.4.7        MASS_7.3-60.2