tidy scripts and using age as criteria for adults
This commit is contained in:
parent
49c18d390f
commit
1e6e9eaef1
3 changed files with 110 additions and 115 deletions
|
@ -5,37 +5,43 @@ getwd()
|
|||
############################################################
|
||||
# TASK: unpaired (time) analysis of mediators: serum
|
||||
############################################################
|
||||
my_sample_type = "serum"
|
||||
|
||||
#=============
|
||||
# Input
|
||||
#=============
|
||||
source("data_extraction_formatting.R")
|
||||
|
||||
table(metadata_all$flustat[metadata_all$adult == 1])
|
||||
# check: adult variable and age variable discrepancy!
|
||||
metadata_all$mosaic[metadata_all$adult==1 & metadata_all$age<=18]
|
||||
|
||||
# clear variables
|
||||
rm(sam_adults_lf, sam_df_adults_clean
|
||||
, npa_adults_lf, npa_df_adults_clean)
|
||||
rm(colnames_sam_df, expected_rows_sam_lf
|
||||
, colnames_npa_df, expected_rows_npa_lf)
|
||||
|
||||
rm(pivot_cols)
|
||||
|
||||
my_sample_type = "serum"
|
||||
#=============
|
||||
# Output: unpaired analysis of time for serum
|
||||
#=============
|
||||
outfile_name = paste0("flu_stats_time_unpaired_", my_sample_type, ".csv")
|
||||
flu_stats_time_unpaired = paste0(outdir_stats, outfile_name)
|
||||
|
||||
#%%========================================================
|
||||
#===============================
|
||||
# data assignment for stats
|
||||
wf = serum_df_adults_clean[serum_df_adults_clean$flustat == 1,]
|
||||
lf = serum_adults_lf[serum_adults_lf$flustat == 1,]
|
||||
#%%========================================================
|
||||
#================================
|
||||
wf = serum_wf[serum_wf$flustat == 1,]
|
||||
lf = serum_lf[serum_lf$flustat == 1,]
|
||||
lf$timepoint = paste0("t", lf$timepoint)
|
||||
|
||||
########################################################################
|
||||
# clear variables
|
||||
rm(sam_lf, sam_wf
|
||||
, npa_lf, npa_wf)
|
||||
rm(colnames_sam_df, expected_rows_sam_lf
|
||||
, colnames_npa_df, expected_rows_npa_lf)
|
||||
|
||||
rm(pivot_cols)
|
||||
|
||||
# sanity checks
|
||||
table(lf$timepoint)
|
||||
lf$timepoint = paste0("t", lf$timepoint)
|
||||
|
||||
if (table(lf$flustat) == table(serum_adults_lf$flustat)[[2]]){
|
||||
if (table(lf$flustat) == table(serum_lf$flustat)[[2]]){
|
||||
cat("Analysing Flu positive patients for:", my_sample_type)
|
||||
}else{
|
||||
cat("FAIL: problem with subsetting data for:", my_sample_type)
|
||||
|
@ -43,7 +49,8 @@ if (table(lf$flustat) == table(serum_adults_lf$flustat)[[2]]){
|
|||
}
|
||||
|
||||
########################################################################
|
||||
# Unpaired stats at each timepoint b/w groups: wilcoxon UNpaired analysis with correction
|
||||
# Unpaired stats at each timepoint b/w groups: wilcoxon UNpaired analysis
|
||||
# with correction
|
||||
#######################################################################
|
||||
# with adjustment: fdr and BH are identical
|
||||
my_adjust_method = "BH"
|
||||
|
@ -56,8 +63,8 @@ sum(is.na(lf_t1$value))
|
|||
|
||||
foo = lf_t1[which(is.na(lf_t1$value)),]
|
||||
ci = which(is.na(lf_t1$value))
|
||||
|
||||
#lf_t1_comp = lf_t1[-ci,]
|
||||
|
||||
lf_t1_comp = lf_t1[-which(is.na(lf_t1$value)),]
|
||||
stats_un_t1 = compare_means(value~obesity
|
||||
, group.by = "mediator"
|
||||
|
@ -68,8 +75,8 @@ stats_un_t1 = compare_means(value~obesity
|
|||
|
||||
foo$mosaic[!unique(foo$mosaic)%in%unique(lf_t1_comp$mosaic)]
|
||||
|
||||
# add timepoint and convert to df
|
||||
stats_un_t1$timepoint = "t1"
|
||||
|
||||
stats_un_t1 = as.data.frame(stats_un_t1)
|
||||
class(stats_un_t1)
|
||||
|
||||
|
@ -78,7 +85,9 @@ n_t1 = data.frame(table(lf_t1_comp$mediator))
|
|||
colnames(n_t1) = c("mediator", "n_obs")
|
||||
n_t1$mediator = as.character(n_t1$mediator)
|
||||
|
||||
# merge stats + n_obs df
|
||||
#==================================
|
||||
# Merge: merge stats + n_obs df
|
||||
#==================================
|
||||
merging_cols = intersect(names(stats_un_t1), names(n_t1)); merging_cols
|
||||
if (all(n_t1$mediator%in%stats_un_t1$mediator)) {
|
||||
cat("PASS: merging stats and n_obs on column/s:", merging_cols)
|
||||
|
@ -115,8 +124,8 @@ stats_un_t2 = compare_means(value~obesity
|
|||
, data = lf_t2_comp
|
||||
, paired = FALSE
|
||||
, p.adjust.method = my_adjust_method)
|
||||
# add timepoint and convert to df
|
||||
stats_un_t2$timepoint = "t2"
|
||||
|
||||
stats_un_t2 = as.data.frame(stats_un_t2)
|
||||
class(stats_un_t2)
|
||||
|
||||
|
@ -125,7 +134,9 @@ n_t2 = data.frame(table(lf_t2_comp$mediator))
|
|||
colnames(n_t2) = c("mediator", "n_obs")
|
||||
n_t2$mediator = as.character(n_t2$mediator)
|
||||
|
||||
# merge stats + n_obs df
|
||||
#==================================
|
||||
# Merge: merge stats + n_obs df
|
||||
#==================================
|
||||
merging_cols = intersect(names(stats_un_t2), names(n_t2)); merging_cols
|
||||
if (all(n_t2$mediator%in%stats_un_t2$mediator)) {
|
||||
cat("PASS: merging stats and n_obs on column/s:", merging_cols)
|
||||
|
@ -163,8 +174,8 @@ stats_un_t3 = compare_means(value~obesity
|
|||
, paired = FALSE
|
||||
, p.adjust.method = my_adjust_method)
|
||||
|
||||
# add timepoint and convert to df
|
||||
stats_un_t3$timepoint = "t3"
|
||||
|
||||
stats_un_t3 = as.data.frame(stats_un_t3)
|
||||
class(stats_un_t3)
|
||||
|
||||
|
@ -174,7 +185,9 @@ n_t3 = data.frame(table(lf_t3_comp$mediator))
|
|||
colnames(n_t3) = c("mediator", "n_obs")
|
||||
n_t3$mediator = as.character(n_t3$mediator)
|
||||
|
||||
# merge stats + n_obs df
|
||||
#==================================
|
||||
# Merge: merge stats + n_obs df
|
||||
#==================================
|
||||
merging_cols = intersect(names(stats_un_t3), names(n_t3)); merging_cols
|
||||
if (all(n_t3$mediator%in%stats_un_t3$mediator)) {
|
||||
cat("PASS: merging stats and n_obs on column/s:", merging_cols)
|
||||
|
@ -198,7 +211,7 @@ stats_un_t3$p_adj_bonferroni = p.adjust(stats_un_t3$p, method = "bonferroni")
|
|||
|
||||
rm(n_t3)
|
||||
rm(lf_t3_comp)
|
||||
|
||||
########################################################################
|
||||
#==============
|
||||
# Rbind these dfs
|
||||
#==============
|
||||
|
@ -318,8 +331,7 @@ colnames(combined_unpaired_stats_f) = c("mediator"
|
|||
, "p_bon_signif")
|
||||
|
||||
colnames(combined_unpaired_stats_f)
|
||||
|
||||
|
||||
########################################################################
|
||||
#******************
|
||||
# write output file
|
||||
#******************
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue