Last active
December 6, 2022 15:27
-
-
Save acvill/5273c874f0668ea17aadf825ecedfaf5 to your computer and use it in GitHub Desktop.
Takes 2 tables, performs column-wise Wilcoxon test for each shared colname, generates p value table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(tibble) | |
require(dplyr) | |
require(stats) | |
# make mock data, genes as columns | |
control <- tibble(subject = paste0("control", sprintf('%0.2d', 1:20)), | |
gene1 = rnorm(20, 10, 2), | |
gene2 = rnorm(20, 10, 2), | |
gene3 = rnorm(20, 10, 2)) | |
lupus <- tibble(subject = paste0("lupus", sprintf('%0.2d', 1:20)), | |
gene1 = rnorm(20, 10, 2), | |
gene2 = rnorm(20, 10, 2), | |
gene3 = rnorm(20, 10, 2)) | |
# extract list of genes shared by both datasets | |
genes <- dplyr::intersect(colnames(control[,-1]), | |
colnames(lupus[,-1])) | |
# return dataframe of p values for each gene | |
results <- sapply(genes, | |
function(gene) { | |
c_dat <- purrr::as_vector(dplyr::select(control, gene)) | |
l_dat <- purrr::as_vector(dplyr::select(lupus, gene)) | |
wilcox.test(c_dat, l_dat)$p.value | |
}) |> tibble::enframe() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment