diff --git a/scripts/9_correction_batch_effects_filtered.Rmd b/scripts/9_correction_batch_effects_filtered.Rmd index 17500de..777c58d 100644 --- a/scripts/9_correction_batch_effects_filtered.Rmd +++ b/scripts/9_correction_batch_effects_filtered.Rmd @@ -97,7 +97,7 @@ if (correction_variable_1 == "PLEASE FILL IN"){ var_explained = 100*round(summary(PCA_object)$importance[2,], 2), cumm_var_explained = 100*round(summary(PCA_object)$importance[3,], 2)) - variance_explained %>% +screeplot <- variance_explained %>% dplyr::slice(1:10) %>% ggplot(aes(x = factor(PC, level = PC), y = var_explained, group = 1)) + geom_point() + @@ -105,6 +105,7 @@ if (correction_variable_1 == "PLEASE FILL IN"){ geom_text(aes(label = cumm_var_explained), vjust = 1.5) + labs(x = "Principal Component", y = "Variance Explained (%)", title = "Scree Plot", subtitle = "Note: cumulative variance explained (%) is displayed as text") +print(screeplot) R <- pc_cutoff(variance_explained) # automatically calculate number of PCs print(paste0(R, " PCs were included")) @@ -241,7 +242,8 @@ if (correction_variable_1 == "PLEASE FILL IN"){ ``` ```{r, print p-value table for batch effects after correction of first batch effect variable} -anova_lm_pvalue_df %>% paged_table() +if (correction_variable_1 != "PLEASE FILL IN"){ + anova_lm_pvalue_df %>% paged_table()} ``` ```{r, correction of second batch effect and PCA, results='asis'} @@ -260,7 +262,7 @@ if (correction_variable_2 == "PLEASE FILL IN"){ var_explained = 100*round(summary(PCA_object)$importance[2,], 2), cumm_var_explained = 100*round(summary(PCA_object)$importance[3,], 2)) - variance_explained %>% +screeplot <- variance_explained %>% dplyr::slice(1:10) %>% ggplot(aes(x = factor(PC, level = PC), y = var_explained, group = 1)) + geom_point() + @@ -268,6 +270,7 @@ if (correction_variable_2 == "PLEASE FILL IN"){ geom_text(aes(label = cumm_var_explained), vjust = 1.5) + labs(x = "Principal Component", y = "Variance Explained (%)", title = "Scree Plot", subtitle = "Note: cumulative variance explained (%) is displayed as text") +print(screeplot) R <- pc_cutoff(variance_explained) # automatically calculate number of PCs print(paste0(R, " PCs were included")) @@ -404,7 +407,8 @@ if (correction_variable_2 == "PLEASE FILL IN"){ ``` ```{r, print p-value table for batch effects after correction of second batch effect variable} -anova_lm_pvalue_df %>% paged_table() +if (correction_variable_2 == "PLEASE FILL IN"){ + anova_lm_pvalue_df %>% paged_table()} ``` ```{r, correction of third batch effect and PCA} @@ -423,7 +427,7 @@ if (correction_variable_3 == "PLEASE FILL IN"){ var_explained = 100*round(summary(PCA_object)$importance[2,], 2), cumm_var_explained = 100*round(summary(PCA_object)$importance[3,], 2)) - variance_explained %>% +screeplot <- variance_explained %>% dplyr::slice(1:10) %>% ggplot(aes(x = factor(PC, level = PC), y = var_explained, group = 1)) + geom_point() + @@ -431,6 +435,7 @@ if (correction_variable_3 == "PLEASE FILL IN"){ geom_text(aes(label = cumm_var_explained), vjust = 1.5) + labs(x = "Principal Component", y = "Variance Explained (%)", title = "Scree Plot", subtitle = "Note: cumulative variance explained (%) is displayed as text") +print(screeplot) R <- pc_cutoff(variance_explained) # automatically calculate number of PCs print(paste0(R, " PCs were included")) @@ -566,7 +571,8 @@ if (correction_variable_3 == "PLEASE FILL IN"){ ``` ```{r, print p-value table for batch effects after correction of third batch effect variable} -anova_lm_pvalue_df %>% paged_table() +if (correction_variable_3 == "PLEASE FILL IN"){ + anova_lm_pvalue_df %>% paged_table()} ``` ```{r, convertion M to Beta and save, include=FALSE}