1. knitr::opts_chunk$set(warning = F, message = F)
  2. library(dplyr)
  3. library(tibble)

load phenotype

  1. phen <- read.csv("../../Result/phenotype/phenotype_20200111.csv")

group information

  1. with(phen, table(Group, Sex))

Sex

  1. with(phen, chisq.test(Group, Sex))

Age

  1. wilcox.test(Age ~ Group, data = phen)

other clincal parameters

  1. ncolumns <- c(1, 4, 13:ncol(phen))
  2. dat <- phen[, ncolumns] %>%
  3. mutate(Group = factor(Group))
  4. datphen <- dat[, c(1:2)]
  5. datprof <- dat[, c(1, 3:ncol(dat))]
  6. fr <- levels(datphen$Group)
  7. res <- apply(datprof[, -1], 2, function(x, group){
  8. df <- data.frame(Value=x, Group=group) %>% na.omit()
  9. num <- as.numeric(table(df$Group))
  10. pval <- t.test(Value ~ Group, data = df)$p.value
  11. mn <- with(df, tapply(Value, Group, mean))
  12. if ( mn[1] > mn[2]) {
  13. enrich <- fr[1]
  14. } else {
  15. enrich <- fr[2]
  16. }
  17. sd <- with(df, tapply(Value, Group, sd))
  18. mn_sd <- c(paste(signif(mn[1], 3), signif(sd[1], 3), sep = "+/-"),
  19. paste(signif(mn[2], 3), signif(sd[2], 3), sep = "+/-"))
  20. res <- c(pval, num, enrich, mn_sd)
  21. return(res)
  22. }, datphen$Group) %>%
  23. t() %>% data.frame() %>%
  24. setNames(c("Pvalue", paste0(fr, "_Number"),
  25. "Enrichment", paste0(fr, "_MeanSD"))) %>%
  26. rownames_to_column("ClincalParam")
  27. DT::datatable(res)

version

  1. sessionInfo()