Last updated: 2023-03-11

Checks: 6 1

Knit directory: paperscripts/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). 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(20230311) 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.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

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 b7ec3d3. 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:  .DS_Store
    Untracked:  Figs/
    Untracked:  analysis/.DS_Store
    Untracked:  analysis/Fig1.Rmd
    Untracked:  analysis/Fig2.Rmd
    Untracked:  analysis/Fig3.Rmd
    Untracked:  analysis/Fig4.Rmd
    Untracked:  analysis/Fig5.Rmd
    Untracked:  analysis/generation_rawfiles/
    Untracked:  analysis/table1.Rmd
    Untracked:  code/TextXX.R
    Untracked:  code/utils.R
    Untracked:  output/.DS_Store
    Untracked:  output/AUC.csv
    Untracked:  output/PVE_fhs.csv
    Untracked:  output/PVE_ukb.csv
    Untracked:  output/amit_df.rds
    Untracked:  output/fh_full.rds
    Untracked:  output/fh_prs.rds
    Untracked:  output/hazards_fhs.rds
    Untracked:  output/hazards_fhs_EQ.rds
    Untracked:  output/hazards_rate_UKB_amit.rds
    Untracked:  output/hazards_rate_UKB_amit_EQ.rds
    Untracked:  output/hazards_rate_lowerbound_amit.rds
    Untracked:  output/hazards_rate_lowerbound_amit_EQ.rds
    Untracked:  output/hazards_rate_lowerbound_fh.rds
    Untracked:  output/hazards_rate_lowerbound_fh_EQ.rds
    Untracked:  output/hazards_rate_upperbound_amit.rds
    Untracked:  output/hazards_rate_upperbound_amit_EQ.rds
    Untracked:  output/hazards_rate_upperbound_fh.rds
    Untracked:  output/hazards_rate_upperbound_fh_EQ.rds
    Untracked:  output/hr_all.xls
    Untracked:  output/hrindex.csv
    Untracked:  output/hrindex_FHs.csv
    Untracked:  output/hrindex_UKB.csv
    Untracked:  output/output/
    Untracked:  output/proportions_table.csv

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.


AUC overall

source("code/utils.R")

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
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.1     ✔ purrr   0.3.5
✔ tibble  3.1.8     ✔ stringr 1.4.1
✔ tidyr   1.2.1     ✔ forcats 0.5.2
✔ readr   2.1.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
Loading required package: ggpubr


Attaching package: 'survminer'


The following object is masked from 'package:survival':

    myeloma



Attaching package: 'reshape'


The following objects are masked from 'package:tidyr':

    expand, smiths


The following object is masked from 'package:dplyr':

    rename



Attaching package: 'gridExtra'


The following object is masked from 'package:dplyr':

    combine



Attaching package: 'survMisc'


The following object is masked from 'package:ggplot2':

    autoplot



Attaching package: 'rsq'


The following object is masked from 'package:survMisc':

    rsq


Type 'citation("pROC")' for a citation.


Attaching package: 'pROC'


The following object is masked from 'package:survMisc':

    ci


The following objects are masked from 'package:stats':

    cov, smooth, var



Attaching package: 'data.table'


The following object is masked from 'package:reshape':

    melt


The following object is masked from 'package:purrr':

    transpose


The following objects are masked from 'package:dplyr':

    between, first, last



Attaching package: 'plotly'


The following object is masked from 'package:reshape':

    rename


The following object is masked from 'package:ggplot2':

    last_plot


The following object is masked from 'package:stats':

    filter


The following object is masked from 'package:graphics':

    layout
library(ggplot2)

df=readRDS("output/amit_df.rds")

ages=c(40,45,50,55,60,65,70,75)

df$prscat <- cut(df$prs.r, breaks=c(0, 0.20,0.80,1), labels=c("low", "intermediate","high"))
set.seed(456)
aucmat=matrix(NA,nrow=length(ages)-1,ncol=3)
semat=matrix(NA,nrow=length(ages)-1,ncol=3)
for(i in 1:(length(ages)-1))
{
  par(mfrow=c(1,2))
  #which(df$phenos.enrollment>ages[i]&df$phenos.enrollment<ages[i+1])
  d=df[which(df$phenos.enrollment>ages[i]&df$phenos.enrollment<ages[i+1]),]
  indices=sample(nrow(d))
  
  d_train=d[indices[1:(length(indices)/2)],]
  d_test=d[indices[(length(indices)/2+1):length(indices)],]
  model_glm = glm(phenos.has_CAD  ~ prscat, data = d_train, family = "binomial")
  
  test_prob = predict(model_glm, newdata = d_test, type = "response")
  test_roc = roc(d_test$phenos.has_CAD~ test_prob, plot = F,main=paste0("PRS,age",ages[i],"to",ages[i+1]))
  aucmat[i,1]=test_roc$auc
  semat[i,1]=sqrt(var(test_roc))
  
  
  model_glm = glm(phenos.has_CAD  ~ ascvdcat_all, data = d_train, family = "binomial")
  
  test_prob = predict(model_glm, newdata = d_test, type = "response")
  test_roc = roc(d_test$phenos.has_CAD~ test_prob, plot = F,main=paste0("PCE,age",ages[i],"to",ages[i+1]))
  aucmat[i,2]=test_roc$auc
  semat[i,2]=sqrt(var(test_roc))
  
  model_glm = glm(phenos.has_CAD  ~ ascvdcat_all+prscat, data = d_train, family = "binomial")
  
  test_prob = predict(model_glm, newdata = d_test, type = "response")
  test_roc = roc(d_test$phenos.has_CAD~ test_prob, plot = F,main=paste0("PCE+PRS,age",ages[i],"to",ages[i+1]))
  aucmat[i,3]=test_roc$auc
  semat[i,3]=sqrt(var(test_roc))
}
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
Setting levels: control = 0, case = 1
Setting direction: controls < cases
rownames(aucmat)=c("40-45","45-50","50-55","55-60","60-65","65-70","70-75")

m=melt(aucmat,id.vars="Age")
Warning in melt(aucmat, id.vars = "Age"): The melt generic in data.table has
been passed a matrix and will attempt to redirect to the relevant reshape2
method; please note that reshape2 is deprecated, and this redirection is now
deprecated as well. To continue using melt methods from reshape2 while both
libraries are attached, e.g. melt.list, you can prepend the namespace like
reshape2::melt(aucmat). In the next version, this warning will become an error.
m3=melt(semat)
Warning in melt(semat): The melt generic in data.table has been passed a matrix
and will attempt to redirect to the relevant reshape2 method; please note that
reshape2 is deprecated, and this redirection is now deprecated as well. To
continue using melt methods from reshape2 while both libraries are attached,
e.g. melt.list, you can prepend the namespace like reshape2::melt(semat). In the
next version, this warning will become an error.
m[which(m$X2==1),2]="PRS"
m[which(m$X2==2),2]="PCE"
m[which(m$X2==3),2]="PRS+PCE"

names(m)=c("Age","Model","AUC")
m$Model=as.factor(m$Model)
levels(m$Model)[1]="Genomic"
levels(m$Model)[2]="Non Genomic"
levels(m$Model)[3]="Combined"

print(levels(m$Model))
[1] "Genomic"     "Non Genomic" "Combined"   
m$se=m3$value
gplot <- ggplot(m,aes(x = Age,y = AUC,color = Model,ymin=AUC+se,ymax=AUC-se))+geom_point()+geom_line(aes(group=Model,color =Model),size=3)+geom_pointrange()+ylim(0.5,1)+scale_color_manual(values=c("tomato","cornflowerblue","darkorchid4"))+theme_classic(base_size = 25)+theme(axis.text.x = element_text(angle = 90))
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
gplot

#ggsave(gplot,filename = "aucplot.pdf",dpi=300)
ggsave(gplot,filename = "Figs/Fig5/aucplot.tiff",dpi=300,width = 9,height = 7)

msave=m
msave$upper=m$AUC+m$se
msave$lower=m$AUC-m$se
write.table(msave,"output/AUC.csv",sep=",",quote=FALSE,row.names = F)

sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur ... 10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

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

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

other attached packages:
 [1] babynames_1.0.1    gapminder_0.3.0    carData_3.0-5      plotly_4.10.0     
 [5] DT_0.24            gt_0.8.0           RColorBrewer_1.1-3 data.table_1.14.2 
 [9] pROC_1.18.0        rsq_2.5            survMisc_0.5.6     gridExtra_2.3     
[13] ggfortify_0.4.14   reshape_0.8.9      eulerr_6.1.1       survminer_0.4.9   
[17] ggpubr_0.4.0       survival_3.4-0     forcats_0.5.2      stringr_1.4.1     
[21] purrr_0.3.5        readr_2.1.2        tidyr_1.2.1        tibble_3.1.8      
[25] ggplot2_3.4.1      tidyverse_1.3.2    dplyr_1.0.10      

loaded via a namespace (and not attached):
 [1] googledrive_2.0.0   minqa_1.2.4         colorspace_2.0-3   
 [4] ggsignif_0.6.4      ellipsis_0.3.2      rprojroot_2.0.3    
 [7] fs_1.5.2            rstudioapi_0.14     farver_2.1.1       
[10] Deriv_4.1.3         fansi_1.0.3         lubridate_1.8.0    
[13] xml2_1.3.3          splines_4.2.1       cachem_1.0.6       
[16] knitr_1.40          jsonlite_1.8.2      workflowr_1.7.0    
[19] nloptr_2.0.3        broom_1.0.1         km.ci_0.5-6        
[22] dbplyr_2.2.1        compiler_4.2.1      httr_1.4.4         
[25] backports_1.4.1     assertthat_0.2.1    Matrix_1.5-1       
[28] fastmap_1.1.0       lazyeval_0.2.2      gargle_1.2.0       
[31] cli_3.4.1           later_1.3.0         htmltools_0.5.3    
[34] tools_4.2.1         gtable_0.3.1        glue_1.6.2         
[37] reshape2_1.4.4      Rcpp_1.0.9          cellranger_1.1.0   
[40] jquerylib_0.1.4     vctrs_0.5.2         nlme_3.1-159       
[43] xfun_0.33           lme4_1.1-30         rvest_1.0.3        
[46] lifecycle_1.0.3     rstatix_0.7.0       googlesheets4_1.0.1
[49] MASS_7.3-58.1       zoo_1.8-11          scales_1.2.1       
[52] ragg_1.2.3          hms_1.1.2           promises_1.2.0.1   
[55] yaml_2.3.5          KMsurv_0.1-5        sass_0.4.2         
[58] stringi_1.7.8       highr_0.9           boot_1.3-28        
[61] systemfonts_1.0.4   rlang_1.0.6         pkgconfig_2.0.3    
[64] evaluate_0.17       lattice_0.20-45     labeling_0.4.2     
[67] htmlwidgets_1.5.4   tidyselect_1.2.0    plyr_1.8.7         
[70] magrittr_2.0.3      R6_2.5.1            generics_0.1.3     
[73] DBI_1.1.3           pillar_1.8.1        haven_2.5.1        
[76] withr_2.5.0         abind_1.4-5         modelr_0.1.9       
[79] crayon_1.5.2        car_3.1-0           utf8_1.2.2         
[82] tzdb_0.3.0          rmarkdown_2.17      grid_4.2.1         
[85] readxl_1.4.1        git2r_0.30.1        reprex_2.0.2       
[88] digest_0.6.29       xtable_1.8-4        httpuv_1.6.6       
[91] textshaping_0.3.6   munsell_0.5.0       viridisLite_0.4.1  
[94] bslib_0.4.0