# Load libraries
library(tidyverse)
## Warning: package 'ggplot2' was built under R version 4.5.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.1     ✔ tibble    3.3.0
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.2.0     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggridges)

# Load the dataset
MET <- read.csv("/Users/maxineharlemon/DrMax_Biology/Using_R_for_biostatistics_Datasets/METABRIC_RNA_Mutation.csv")

# Inspect column names to confirm variables

colnames(MET)
##   [1] "patient_id"                     "age_at_diagnosis"              
##   [3] "type_of_breast_surgery"         "cancer_type"                   
##   [5] "cancer_type_detailed"           "cellularity"                   
##   [7] "chemotherapy"                   "pam50_._claudin.low_subtype"   
##   [9] "cohort"                         "er_status_measured_by_ihc"     
##  [11] "er_status"                      "neoplasm_histologic_grade"     
##  [13] "her2_status_measured_by_snp6"   "her2_status"                   
##  [15] "tumor_other_histologic_subtype" "hormone_therapy"               
##  [17] "inferred_menopausal_state"      "integrative_cluster"           
##  [19] "primary_tumor_laterality"       "lymph_nodes_examined_positive" 
##  [21] "mutation_count"                 "nottingham_prognostic_index"   
##  [23] "oncotree_code"                  "overall_survival_months"       
##  [25] "overall_survival"               "pr_status"                     
##  [27] "radio_therapy"                  "X3.gene_classifier_subtype"    
##  [29] "tumor_size"                     "tumor_stage"                   
##  [31] "death_from_cancer"              "brca1"                         
##  [33] "brca2"                          "palb2"                         
##  [35] "pten"                           "tp53"                          
##  [37] "atm"                            "cdh1"                          
##  [39] "chek2"                          "nbn"                           
##  [41] "nf1"                            "stk11"                         
##  [43] "bard1"                          "mlh1"                          
##  [45] "msh2"                           "msh6"                          
##  [47] "pms2"                           "epcam"                         
##  [49] "rad51c"                         "rad51d"                        
##  [51] "rad50"                          "rb1"                           
##  [53] "rbl1"                           "rbl2"                          
##  [55] "ccna1"                          "ccnb1"                         
##  [57] "cdk1"                           "ccne1"                         
##  [59] "cdk2"                           "cdc25a"                        
##  [61] "ccnd1"                          "cdk4"                          
##  [63] "cdk6"                           "ccnd2"                         
##  [65] "cdkn2a"                         "cdkn2b"                        
##  [67] "myc"                            "cdkn1a"                        
##  [69] "cdkn1b"                         "e2f1"                          
##  [71] "e2f2"                           "e2f3"                          
##  [73] "e2f4"                           "e2f5"                          
##  [75] "e2f6"                           "e2f7"                          
##  [77] "e2f8"                           "src"                           
##  [79] "jak1"                           "jak2"                          
##  [81] "stat1"                          "stat2"                         
##  [83] "stat3"                          "stat5a"                        
##  [85] "stat5b"                         "mdm2"                          
##  [87] "tp53bp1"                        "adam10"                        
##  [89] "adam17"                         "aph1a"                         
##  [91] "aph1b"                          "arrdc1"                        
##  [93] "cir1"                           "ctbp1"                         
##  [95] "ctbp2"                          "cul1"                          
##  [97] "dll1"                           "dll3"                          
##  [99] "dll4"                           "dtx1"                          
## [101] "dtx2"                           "dtx3"                          
## [103] "dtx4"                           "ep300"                         
## [105] "fbxw7"                          "hdac1"                         
## [107] "hdac2"                          "hes1"                          
## [109] "hes5"                           "heyl"                          
## [111] "itch"                           "jag1"                          
## [113] "jag2"                           "kdm5a"                         
## [115] "lfng"                           "maml1"                         
## [117] "maml2"                          "maml3"                         
## [119] "ncor2"                          "ncstn"                         
## [121] "notch1"                         "notch2"                        
## [123] "notch3"                         "nrarp"                         
## [125] "numb"                           "numbl"                         
## [127] "psen1"                          "psen2"                         
## [129] "psenen"                         "rbpj"                          
## [131] "rbpjl"                          "rfng"                          
## [133] "snw1"                           "spen"                          
## [135] "hes2"                           "hes4"                          
## [137] "hes7"                           "hey1"                          
## [139] "hey2"                           "acvr1"                         
## [141] "acvr1b"                         "acvr1c"                        
## [143] "acvr2a"                         "acvr2b"                        
## [145] "acvrl1"                         "akt1"                          
## [147] "akt1s1"                         "akt2"                          
## [149] "apaf1"                          "arl11"                         
## [151] "atr"                            "aurka"                         
## [153] "bad"                            "bcl2"                          
## [155] "bcl2l1"                         "bmp10"                         
## [157] "bmp15"                          "bmp2"                          
## [159] "bmp3"                           "bmp4"                          
## [161] "bmp5"                           "bmp6"                          
## [163] "bmp7"                           "bmpr1a"                        
## [165] "bmpr1b"                         "bmpr2"                         
## [167] "braf"                           "casp10"                        
## [169] "casp3"                          "casp6"                         
## [171] "casp7"                          "casp8"                         
## [173] "casp9"                          "chek1"                         
## [175] "csf1"                           "csf1r"                         
## [177] "cxcl8"                          "cxcr1"                         
## [179] "cxcr2"                          "dab2"                          
## [181] "diras3"                         "dlec1"                         
## [183] "dph1"                           "egfr"                          
## [185] "eif4e"                          "eif4ebp1"                      
## [187] "eif5a2"                         "erbb2"                         
## [189] "erbb3"                          "erbb4"                         
## [191] "fas"                            "fgf1"                          
## [193] "fgfr1"                          "folr1"                         
## [195] "folr2"                          "folr3"                         
## [197] "foxo1"                          "foxo3"                         
## [199] "gdf11"                          "gdf2"                          
## [201] "gsk3b"                          "hif1a"                         
## [203] "hla.g"                          "hras"                          
## [205] "igf1"                           "igf1r"                         
## [207] "inha"                           "inhba"                         
## [209] "inhbc"                          "itgav"                         
## [211] "itgb3"                          "izumo1r"                       
## [213] "kdr"                            "kit"                           
## [215] "kras"                           "map2k1"                        
## [217] "map2k2"                         "map2k3"                        
## [219] "map2k4"                         "map2k5"                        
## [221] "map3k1"                         "map3k3"                        
## [223] "map3k4"                         "map3k5"                        
## [225] "mapk1"                          "mapk12"                        
## [227] "mapk14"                         "mapk3"                         
## [229] "mapk4"                          "mapk6"                         
## [231] "mapk7"                          "mapk8"                         
## [233] "mapk9"                          "mdc1"                          
## [235] "mlst8"                          "mmp1"                          
## [237] "mmp10"                          "mmp11"                         
## [239] "mmp12"                          "mmp13"                         
## [241] "mmp14"                          "mmp15"                         
## [243] "mmp16"                          "mmp17"                         
## [245] "mmp19"                          "mmp2"                          
## [247] "mmp21"                          "mmp23b"                        
## [249] "mmp24"                          "mmp25"                         
## [251] "mmp26"                          "mmp27"                         
## [253] "mmp28"                          "mmp3"                          
## [255] "mmp7"                           "mmp9"                          
## [257] "mtor"                           "nfkb1"                         
## [259] "nfkb2"                          "opcml"                         
## [261] "pdgfa"                          "pdgfb"                         
## [263] "pdgfra"                         "pdgfrb"                        
## [265] "pdpk1"                          "peg3"                          
## [267] "pik3ca"                         "pik3r1"                        
## [269] "pik3r2"                         "plagl1"                        
## [271] "ptk2"                           "rab25"                         
## [273] "rad51"                          "raf1"                          
## [275] "rassf1"                         "rheb"                          
## [277] "rictor"                         "rps6"                          
## [279] "rps6ka1"                        "rps6ka2"                       
## [281] "rps6kb1"                        "rps6kb2"                       
## [283] "rptor"                          "slc19a1"                       
## [285] "smad1"                          "smad2"                         
## [287] "smad3"                          "smad4"                         
## [289] "smad5"                          "smad6"                         
## [291] "smad7"                          "smad9"                         
## [293] "sptbn1"                         "terc"                          
## [295] "tert"                           "tgfb1"                         
## [297] "tgfb2"                          "tgfb3"                         
## [299] "tgfbr1"                         "tgfbr2"                        
## [301] "tgfbr3"                         "tsc1"                          
## [303] "tsc2"                           "vegfa"                         
## [305] "vegfb"                          "wfdc2"                         
## [307] "wwox"                           "zfyve9"                        
## [309] "arid1a"                         "arid1b"                        
## [311] "cbfb"                           "gata3"                         
## [313] "kmt2c"                          "kmt2d"                         
## [315] "myh9"                           "ncor1"                         
## [317] "pde4dip"                        "ptprd"                         
## [319] "ros1"                           "runx1"                         
## [321] "tbx3"                           "abcb1"                         
## [323] "abcb11"                         "abcc1"                         
## [325] "abcc10"                         "bbc3"                          
## [327] "bmf"                            "cyp2c8"                        
## [329] "cyp3a4"                         "fgf2"                          
## [331] "fn1"                            "map2"                          
## [333] "map4"                           "mapt"                          
## [335] "nr1i2"                          "slco1b3"                       
## [337] "tubb1"                          "tubb4a"                        
## [339] "tubb4b"                         "twist1"                        
## [341] "adgra2"                         "afdn"                          
## [343] "aff2"                           "agmo"                          
## [345] "agtr2"                          "ahnak"                         
## [347] "ahnak2"                         "akap9"                         
## [349] "alk"                            "apc"                           
## [351] "arid2"                          "arid5b"                        
## [353] "asxl1"                          "asxl2"                         
## [355] "bap1"                           "bcas3"                         
## [357] "birc6"                          "cacna2d3"                      
## [359] "ccnd3"                          "chd1"                          
## [361] "clk3"                           "clrn2"                         
## [363] "col12a1"                        "col22a1"                       
## [365] "col6a3"                         "ctcf"                          
## [367] "ctnna1"                         "ctnna3"                        
## [369] "dnah11"                         "dnah2"                         
## [371] "dnah5"                          "dtwd2"                         
## [373] "fam20c"                         "fanca"                         
## [375] "fancd2"                         "flt3"                          
## [377] "foxp1"                          "frmd3"                         
## [379] "gh1"                            "gldc"                          
## [381] "gpr32"                          "gps2"                          
## [383] "hdac9"                          "herc2"                         
## [385] "hist1h2bc"                      "kdm3a"                         
## [387] "kdm6a"                          "klrg1"                         
## [389] "l1cam"                          "lama2"                         
## [391] "lamb3"                          "large1"                        
## [393] "ldlrap1"                        "lifr"                          
## [395] "lipi"                           "magea8"                        
## [397] "map3k10"                        "map3k13"                       
## [399] "men1"                           "mtap"                          
## [401] "muc16"                          "myo1a"                         
## [403] "myo3a"                          "ncoa3"                         
## [405] "nek1"                           "nf2"                           
## [407] "npnt"                           "nr2f1"                         
## [409] "nr3c1"                          "nras"                          
## [411] "nrg3"                           "nt5e"                          
## [413] "or6a2"                          "palld"                         
## [415] "pbrm1"                          "ppp2cb"                        
## [417] "ppp2r2a"                        "prkacg"                        
## [419] "prkce"                          "prkcq"                         
## [421] "prkcz"                          "prkg1"                         
## [423] "prps2"                          "prr16"                         
## [425] "ptpn22"                         "ptprm"                         
## [427] "rasgef1b"                       "rpgr"                          
## [429] "ryr2"                           "sbno1"                         
## [431] "setd1a"                         "setd2"                         
## [433] "setdb1"                         "sf3b1"                         
## [435] "sgcd"                           "shank2"                        
## [437] "siah1"                          "sik1"                          
## [439] "sik2"                           "smarcb1"                       
## [441] "smarcc1"                        "smarcc2"                       
## [443] "smarcd1"                        "spaca1"                        
## [445] "stab2"                          "stmn2"                         
## [447] "syne1"                          "taf1"                          
## [449] "taf4b"                          "tbl1xr1"                       
## [451] "tg"                             "thada"                         
## [453] "thsd7a"                         "ttyh1"                         
## [455] "ubr5"                           "ush2a"                         
## [457] "usp9x"                          "utrn"                          
## [459] "zfp36l1"                        "ackr3"                         
## [461] "akr1c1"                         "akr1c2"                        
## [463] "akr1c3"                         "akr1c4"                        
## [465] "akt3"                           "ar"                            
## [467] "bche"                           "cdk8"                          
## [469] "cdkn2c"                         "cyb5a"                         
## [471] "cyp11a1"                        "cyp11b2"                       
## [473] "cyp17a1"                        "cyp19a1"                       
## [475] "cyp21a2"                        "cyp3a43"                       
## [477] "cyp3a5"                         "cyp3a7"                        
## [479] "ddc"                            "hes6"                          
## [481] "hsd17b1"                        "hsd17b10"                      
## [483] "hsd17b11"                       "hsd17b12"                      
## [485] "hsd17b13"                       "hsd17b14"                      
## [487] "hsd17b2"                        "hsd17b3"                       
## [489] "hsd17b4"                        "hsd17b6"                       
## [491] "hsd17b7"                        "hsd17b8"                       
## [493] "hsd3b1"                         "hsd3b2"                        
## [495] "hsd3b7"                         "mecom"                         
## [497] "met"                            "ncoa2"                         
## [499] "nrip1"                          "pik3r3"                        
## [501] "prkci"                          "prkd1"                         
## [503] "ran"                            "rdh5"                          
## [505] "sdc4"                           "serpini1"                      
## [507] "shbg"                           "slc29a1"                       
## [509] "sox9"                           "spry2"                         
## [511] "srd5a1"                         "srd5a2"                        
## [513] "srd5a3"                         "st7"                           
## [515] "star"                           "tnk2"                          
## [517] "tulp4"                          "ugt2b15"                       
## [519] "ugt2b17"                        "ugt2b7"                        
## [521] "pik3ca_mut"                     "tp53_mut"                      
## [523] "muc16_mut"                      "ahnak2_mut"                    
## [525] "kmt2c_mut"                      "syne1_mut"                     
## [527] "gata3_mut"                      "map3k1_mut"                    
## [529] "ahnak_mut"                      "dnah11_mut"                    
## [531] "cdh1_mut"                       "dnah2_mut"                     
## [533] "kmt2d_mut"                      "ush2a_mut"                     
## [535] "ryr2_mut"                       "dnah5_mut"                     
## [537] "herc2_mut"                      "pde4dip_mut"                   
## [539] "akap9_mut"                      "tg_mut"                        
## [541] "birc6_mut"                      "utrn_mut"                      
## [543] "tbx3_mut"                       "col6a3_mut"                    
## [545] "arid1a_mut"                     "lama2_mut"                     
## [547] "notch1_mut"                     "cbfb_mut"                      
## [549] "ncor2_mut"                      "col12a1_mut"                   
## [551] "col22a1_mut"                    "pten_mut"                      
## [553] "akt1_mut"                       "atr_mut"                       
## [555] "thada_mut"                      "ncor1_mut"                     
## [557] "stab2_mut"                      "myh9_mut"                      
## [559] "runx1_mut"                      "nf1_mut"                       
## [561] "map2k4_mut"                     "ros1_mut"                      
## [563] "lamb3_mut"                      "arid1b_mut"                    
## [565] "erbb2_mut"                      "sf3b1_mut"                     
## [567] "shank2_mut"                     "ep300_mut"                     
## [569] "ptprd_mut"                      "usp9x_mut"                     
## [571] "setd2_mut"                      "setd1a_mut"                    
## [573] "thsd7a_mut"                     "afdn_mut"                      
## [575] "erbb3_mut"                      "rb1_mut"                       
## [577] "myo1a_mut"                      "alk_mut"                       
## [579] "fanca_mut"                      "adgra2_mut"                    
## [581] "ubr5_mut"                       "pik3r1_mut"                    
## [583] "myo3a_mut"                      "asxl2_mut"                     
## [585] "apc_mut"                        "ctcf_mut"                      
## [587] "asxl1_mut"                      "fancd2_mut"                    
## [589] "taf1_mut"                       "kdm6a_mut"                     
## [591] "ctnna3_mut"                     "brca1_mut"                     
## [593] "ptprm_mut"                      "foxo3_mut"                     
## [595] "usp28_mut"                      "gldc_mut"                      
## [597] "brca2_mut"                      "cacna2d3_mut"                  
## [599] "arid2_mut"                      "aff2_mut"                      
## [601] "lifr_mut"                       "sbno1_mut"                     
## [603] "kdm3a_mut"                      "ncoa3_mut"                     
## [605] "bap1_mut"                       "l1cam_mut"                     
## [607] "pbrm1_mut"                      "chd1_mut"                      
## [609] "jak1_mut"                       "setdb1_mut"                    
## [611] "fam20c_mut"                     "arid5b_mut"                    
## [613] "egfr_mut"                       "map3k10_mut"                   
## [615] "smarcc2_mut"                    "erbb4_mut"                     
## [617] "npnt_mut"                       "nek1_mut"                      
## [619] "agmo_mut"                       "zfp36l1_mut"                   
## [621] "smad4_mut"                      "sik1_mut"                      
## [623] "casp8_mut"                      "prkcq_mut"                     
## [625] "smarcc1_mut"                    "palld_mut"                     
## [627] "dcaf4l2_mut"                    "bcas3_mut"                     
## [629] "cdkn1b_mut"                     "gps2_mut"                      
## [631] "men1_mut"                       "stk11_mut"                     
## [633] "sik2_mut"                       "ptpn22_mut"                    
## [635] "brip1_mut"                      "flt3_mut"                      
## [637] "nrg3_mut"                       "fbxw7_mut"                     
## [639] "ttyh1_mut"                      "taf4b_mut"                     
## [641] "or6a2_mut"                      "map3k13_mut"                   
## [643] "hdac9_mut"                      "prkacg_mut"                    
## [645] "rpgr_mut"                       "large1_mut"                    
## [647] "foxp1_mut"                      "clk3_mut"                      
## [649] "prkcz_mut"                      "lipi_mut"                      
## [651] "ppp2r2a_mut"                    "prkce_mut"                     
## [653] "gh1_mut"                        "gpr32_mut"                     
## [655] "kras_mut"                       "nf2_mut"                       
## [657] "chek2_mut"                      "ldlrap1_mut"                   
## [659] "clrn2_mut"                      "acvrl1_mut"                    
## [661] "agtr2_mut"                      "cdkn2a_mut"                    
## [663] "ctnna1_mut"                     "magea8_mut"                    
## [665] "prr16_mut"                      "dtwd2_mut"                     
## [667] "akt2_mut"                       "braf_mut"                      
## [669] "foxo1_mut"                      "nt5e_mut"                      
## [671] "ccnd3_mut"                      "nr3c1_mut"                     
## [673] "prkg1_mut"                      "tbl1xr1_mut"                   
## [675] "frmd3_mut"                      "smad2_mut"                     
## [677] "sgcd_mut"                       "spaca1_mut"                    
## [679] "rasgef1b_mut"                   "hist1h2bc_mut"                 
## [681] "nr2f1_mut"                      "klrg1_mut"                     
## [683] "mbl2_mut"                       "mtap_mut"                      
## [685] "ppp2cb_mut"                     "smarcd1_mut"                   
## [687] "nras_mut"                       "ndfip1_mut"                    
## [689] "hras_mut"                       "prps2_mut"                     
## [691] "smarcb1_mut"                    "stmn2_mut"                     
## [693] "siah1_mut"
# Convert categorical variables to factors
MET$cellularity <- as.factor(MET$cellularity)
MET$mutation_status <- as.factor(MET$brca1_mut)

#Ridge Plot
ggplot(MET, aes(x = brca1, y = factor(cellularity), fill = factor(cellularity))) +
  geom_density_ridges(alpha = 0.7, color = "white") +
  labs(
    title = "Distribution of BRCA1 Expression by Tumor Cellularity",
    x = "BRCA1 Expression",
    y = "Cellularity"
  ) +
  theme_ridges() +
  theme(
    legend.position = "none",
    plot.title = element_text(hjust = 0.5, face = "bold")
  )
## Picking joint bandwidth of 0.281

#Faceted Ridge plot
ggplot(MET, aes(x = brca1, y = cellularity, fill = cellularity)) +
  geom_density_ridges(alpha = 0.7, color = "white") +
  stat_summary(fun = median, geom = "point", color = "black", size = 2) +
  facet_wrap(~ mutation_status) +
  labs(
    title = "Distribution of BRCA1 Expression by Cellularity and Mutation Status",
    x = "BRCA1 Expression",
    y = "Tumor Cellularity"
  ) +
  theme_ridges() +
  theme(plot.title = element_text(hjust = 0.5, face = "bold"))
## Picking joint bandwidth of 0.282
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of NaN
## Picking joint bandwidth of 0.503
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf
## Warning in FUN(X[[i]], ...): no non-missing arguments to max; returning -Inf

#one way anova
library(tidyverse)
library(effectsize)
## Warning: package 'effectsize' was built under R version 4.5.2
library(ggpubr)
anova_model <- aov(brca1 ~ cellularity, data = MET)

TukeyHSD(anova_model)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = brca1 ~ cellularity, data = MET)
## 
## $cellularity
##                       diff          lwr         upr     p adj
## High-          0.221130375 -0.135430320  0.57769107 0.3818717
## Low-          -0.198194537 -0.588939601  0.19255053 0.5603116
## Moderate-      0.004621331 -0.355034873  0.36427754 0.9999870
## Low-High      -0.419324912 -0.617752744 -0.22089708 0.0000004
## Moderate-High -0.216509044 -0.343175872 -0.08984222 0.0000689
## Moderate-Low   0.202815868 -0.001122016  0.40675375 0.0519021
#Linear Models with covariate
lm_model <- lm(brca1 ~ cellularity + age_at_diagnosis + brca1_mut, data = MET)
summary(lm_model)
## 
## Call:
## lm(formula = brca1 ~ cellularity + age_at_diagnosis + brca1_mut, 
##     data = MET)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.5040 -0.6675 -0.0798  0.5274  4.6402 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## (Intercept)           -0.611338   0.169404  -3.609 0.000316 ***
## cellularityHigh        0.206705   0.137947   1.498 0.134188    
## cellularityLow        -0.194618   0.151209  -1.287 0.198226    
## cellularityModerate   -0.017717   0.139108  -0.127 0.898670    
## age_at_diagnosis       0.008904   0.001771   5.028 5.44e-07 ***
## brca1_mutC305S        -0.229319   0.985378  -0.233 0.816003    
## brca1_mutD1692N       -0.771559   0.986630  -0.782 0.434305    
## brca1_mutD420G        -0.206567   0.985231  -0.210 0.833953    
## brca1_mutD560Efs*6    -0.816604   0.987019  -0.827 0.408148    
## brca1_mutE1287K       -0.160619   0.985103  -0.163 0.870499    
## brca1_mutE143K        -0.913498   0.987026  -0.926 0.354823    
## brca1_mutE1494Kfs*11  -1.514440   0.984890  -1.538 0.124298    
## brca1_mutE1836K       -1.028153   0.985637  -1.043 0.297021    
## brca1_mutE391K        -0.650329   0.985027  -0.660 0.509198    
## brca1_mutE880Rfs*13   -0.823881   0.986516  -0.835 0.403745    
## brca1_mutE914K         1.085910   0.984931   1.103 0.270377    
## brca1_mutF709Sfs*29   -1.285412   0.985892  -1.304 0.192461    
## brca1_mutG1087E        1.331524   0.985197   1.352 0.176690    
## brca1_mutI171M         0.374069   0.986299   0.379 0.704534    
## brca1_mutI216S        -0.360132   0.985278  -0.366 0.714770    
## brca1_mutI946V        -0.696910   0.985235  -0.707 0.479435    
## brca1_mutK1667Qfs*11  -1.267960   0.985552  -1.287 0.198412    
## brca1_mutL1439F       -0.043258   0.985210  -0.044 0.964983    
## brca1_mutL502Sfs*2    -0.260279   0.984905  -0.264 0.791602    
## brca1_mutM1827L       -0.255456   0.985240  -0.259 0.795445    
## brca1_mutQ202Kfs*32   -1.341011   0.984912  -1.362 0.173503    
## brca1_mutR1074T       -0.206311   0.985669  -0.209 0.834228    
## brca1_mutR1737T       -0.690224   0.986205  -0.700 0.484091    
## brca1_mutR613K        -1.022885   0.984988  -1.038 0.299184    
## brca1_mutS1266T       -0.456964   0.986872  -0.463 0.643388    
## brca1_mutS153R         0.143552   0.985107   0.146 0.884156    
## brca1_mutS1551C       -1.787396   0.985759  -1.813 0.069959 .  
## brca1_mutS282*        -0.893809   0.984981  -0.907 0.364293    
## brca1_mutT150Pfs*13   -0.843435   0.985201  -0.856 0.392050    
## brca1_mutV1654Cfs*4   -0.924792   0.986002  -0.938 0.348407    
## brca1_mutV452A        -0.263758   0.985895  -0.268 0.789089    
## brca1_mutW372R         0.050171   0.985098   0.051 0.959387    
## brca1_mutX1453_splice -0.048254   0.985317  -0.049 0.960946    
## brca1_mutX1663_splice -0.915226   0.985054  -0.929 0.352951    
## brca1_mutX1760_splice  3.332169   0.985794   3.380 0.000739 ***
## brca1_mutY1127H        0.079797   0.696803   0.115 0.908839    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9844 on 1863 degrees of freedom
## Multiple R-squared:  0.05192,    Adjusted R-squared:  0.03156 
## F-statistic:  2.55 on 40 and 1863 DF,  p-value: 4.32e-07
anova(lm_model)
## Analysis of Variance Table
## 
## Response: brca1
##                    Df  Sum Sq Mean Sq F value    Pr(>F)    
## cellularity         3   38.38 12.7926 13.2026 1.572e-08 ***
## age_at_diagnosis    1   25.64 25.6378 26.4595 2.974e-07 ***
## brca1_mut          36   34.83  0.9676  0.9986    0.4719    
## Residuals        1863 1805.15  0.9689                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Effect size
eta_squared(lm_model)
## # Effect Size for ANOVA (Type I)
## 
## Parameter        | Eta2 (partial) |       95% CI
## ------------------------------------------------
## cellularity      |           0.02 | [0.01, 1.00]
## age_at_diagnosis |           0.01 | [0.01, 1.00]
## brca1_mut        |           0.02 | [0.00, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].
eta_squared(lm_model, partial = TRUE)
## # Effect Size for ANOVA (Type I)
## 
## Parameter        | Eta2 (partial) |       95% CI
## ------------------------------------------------
## cellularity      |           0.02 | [0.01, 1.00]
## age_at_diagnosis |           0.01 | [0.01, 1.00]
## brca1_mut        |           0.02 | [0.00, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].
pairwise <- pairwise.t.test(MET$brca1, MET$cellularity,
                            p.adjust.method = "bonferroni")

pairwise
## 
##  Pairwise comparisons using t tests with pooled SD 
## 
## data:  MET$brca1 and MET$cellularity 
## 
##                High    Low  
## High     0.666 -       -    
## Low      1.000 3.7e-07 -    
## Moderate 1.000 7.0e-05 0.064
## 
## P value adjustment method: bonferroni
ggplot(MET, aes(x = cellularity, y = brca1, fill = cellularity)) +
  geom_boxplot(alpha = 0.7) +
  stat_compare_means(method = "anova", label.y = max(MET$brca1)) +
  stat_compare_means(method = "t.test",
                     comparisons = list(c("Low","Moderate"),
                                        c("Low","High"),
                                        c("Moderate","High")),
                     label = "p.signif") +
  labs(
    title = "BRCA1 Expression Across Tumor Cellularity Groups",
    x = "Tumor Cellularity",
    y = "BRCA1 Expression"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold"),
    legend.position = "none"
  )