Skip to content

Commit

Permalink
fix paired ttest
Browse files Browse the repository at this point in the history
  • Loading branch information
pcastellanoescuder committed Mar 7, 2024
1 parent dc99f52 commit 51a4ac3
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: POMA
Title: Tools for Omics Data Analysis
Version: 1.13.22
Version: 1.13.23
Authors@R:
c(person(given = "Pol",
family = "Castellano-Escuder",
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# POMA 1.13.22
# POMA 1.13.23

* New POMA theme and colorblind-friendly palette
* Available sample normalization (sum and quantile)
Expand Down
34 changes: 25 additions & 9 deletions R/PomaUnivariate.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @param method Character. The univariate statistical test to be performed. Available options include "ttest" (T-test), "anova" (analysis of variance), "mann" (Wilcoxon rank-sum test), and "kruskal" (Kruskal-Wallis test).
#' @param covs Character vector. Indicates the names of `colData` columns to be included as covariates. Default is NULL (no covariates). If not NULL, an ANCOVA model will be fitted using the specified covariates. Note: The order of the covariates is important and should be listed in increasing order of importance in the experimental design.
#' @param error Character vector. Indicates the name of a `colData` column to be included as an error term (e.g. replicates). Default is NULL (no error term).
#' @param paired_samples Logical. Indicates if the data is paired or not. Default is FALSE.
#' @param paired Logical. Indicates if the data is paired or not. Default is FALSE.
#' @param var_equal Logical. Indicates if the data variances are assumed to be equal or not. Default is FALSE.
#' @param adjust Character. Multiple comparisons correction method to adjust p-values. Available options are: "fdr" (false discovery rate), "holm", "hochberg", "hommel", "bonferroni", "BH" (Benjamini-Hochberg), and "BY" (Benjamini-Yekutieli).
#' @param run_post_hoc Logical. Indicates if computing post-hoc tests or not. Setting this parameter to FALSE can save time for large datasets.
Expand All @@ -30,7 +30,7 @@
#' # Perform Mann-Whitney U test
#' st000336 %>%
#' PomaImpute() %>%
#' PomaUnivariate(method = "mann", paired_samples = FALSE, adjust = "fdr")
#' PomaUnivariate(method = "mann", adjust = "fdr")
#'
#' data("st000284")
#' # Perform Two-Way ANOVA
Expand All @@ -52,7 +52,7 @@ PomaUnivariate <- function(data,
method = "ttest",
covs = NULL,
error = NULL,
paired_samples = FALSE,
paired = FALSE,
var_equal = FALSE,
adjust = "fdr",
run_post_hoc = TRUE){
Expand Down Expand Up @@ -106,11 +106,27 @@ PomaUnivariate <- function(data,
if (length(table(group_factor)[table(group_factor) != 0]) != 2) {
stop("Grouping factor must have exactly 2 levels (first column of the metadata file)")
}

result <- data.frame(pvalue = apply(to_univariate, 2, function(x){t.test(x ~ group_factor, na.rm = TRUE,
alternative = "two.sided",
var.equal = var_equal,
paired = paired_samples)$p.value})) %>%

test_result <- data.frame(pvalue = apply(to_univariate, 2, function(x) {
if (!paired) {
res <- t.test(x ~ group_factor, data = data.frame(x, group_factor),
na.rm = TRUE,
alternative = "two.sided",
var.equal = var_equal)
} else {
group1 <- x[group_factor == levels(group_factor)[1]]
group2 <- x[group_factor == levels(group_factor)[2]]

res <- t.test(group1, group2,
na.rm = TRUE,
alternative = "two.sided",
var.equal = var_equal,
paired = TRUE)
}
res$p.value
}))

result <- test_result %>%
tibble::rownames_to_column("feature") %>%
dplyr::mutate(adj_pvalue = p.adjust(pvalue, method = adjust)) %>%
dplyr::bind_cols(group_means, group_sd) %>%
Expand Down Expand Up @@ -219,7 +235,7 @@ PomaUnivariate <- function(data,

suppressWarnings({
result <- data.frame(pvalue = apply(to_univariate, 2, function(x){wilcox.test(x ~ as.factor(group_factor),
paired = paired_samples)$p.value})) %>%
paired = paired)$p.value})) %>%
tibble::rownames_to_column("feature") %>%
dplyr::mutate(adj_pvalue = p.adjust(pvalue, method = adjust)) %>%
dplyr::bind_cols(group_means, group_sd) %>%
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ output: github_document
| _BioC_ branch | Status | Version | Dependencies | Rank |
|- |- |- |- |- |
| [Release](http://bioconductor.org/packages/release/bioc/html/POMA.html) | [![Bioc release status](https://bioconductor.org/shields/build/release/bioc/POMA.svg)](https://bioconductor.org/checkResults/release/bioc-LATEST/POMA/) | [![BioC released version](https://img.shields.io/badge/release%20version-1.12.0-blue.svg)](https://www.bioconductor.org/packages/POMA) | [![Dependencies](http://bioconductor.org/shields/dependencies/release/POMA.svg)](http://bioconductor.org/packages/release/bioc/html/POMA.html#since) | [![Rank](http://www.bioconductor.org/shields/downloads/release/POMA.svg)](https://bioconductor.org/packages/stats/bioc/POMA) |
| [Devel](http://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Bioc devel status](https://bioconductor.org/shields/build/devel/bioc/POMA.svg)](https://bioconductor.org/checkResults/devel/bioc-LATEST/POMA/) | [![BioC devel version](https://img.shields.io/badge/devel%20version-1.13.22-blue.svg)](https://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Dependencies](http://bioconductor.org/shields/dependencies/devel/POMA.svg)](http://bioconductor.org/packages/devel/bioc/html/POMA.html#since) | [![Rank](http://www.bioconductor.org/shields/downloads/devel/POMA.svg)](https://bioconductor.org/packages/stats/bioc/POMA) |
| [Devel](http://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Bioc devel status](https://bioconductor.org/shields/build/devel/bioc/POMA.svg)](https://bioconductor.org/checkResults/devel/bioc-LATEST/POMA/) | [![BioC devel version](https://img.shields.io/badge/devel%20version-1.13.23-blue.svg)](https://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Dependencies](http://bioconductor.org/shields/dependencies/devel/POMA.svg)](http://bioconductor.org/packages/devel/bioc/html/POMA.html#since) | [![Rank](http://www.bioconductor.org/shields/downloads/devel/POMA.svg)](https://bioconductor.org/packages/stats/bioc/POMA) |

<!-- badges: end -->

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/li
| *BioC* branch | Status | Version | Dependencies | Rank |
|-------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| [Release](http://bioconductor.org/packages/release/bioc/html/POMA.html) | [![Bioc release status](https://bioconductor.org/shields/build/release/bioc/POMA.svg)](https://bioconductor.org/checkResults/release/bioc-LATEST/POMA/) | [![BioC released version](https://img.shields.io/badge/release%20version-1.12.0-blue.svg)](https://www.bioconductor.org/packages/POMA) | [![Dependencies](http://bioconductor.org/shields/dependencies/release/POMA.svg)](http://bioconductor.org/packages/release/bioc/html/POMA.html#since) | [![Rank](http://www.bioconductor.org/shields/downloads/release/POMA.svg)](https://bioconductor.org/packages/stats/bioc/POMA) |
| [Devel](http://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Bioc devel status](https://bioconductor.org/shields/build/devel/bioc/POMA.svg)](https://bioconductor.org/checkResults/devel/bioc-LATEST/POMA/) | [![BioC devel version](https://img.shields.io/badge/devel%20version-1.13.22-blue.svg)](https://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Dependencies](http://bioconductor.org/shields/dependencies/devel/POMA.svg)](http://bioconductor.org/packages/devel/bioc/html/POMA.html#since) | [![Rank](http://www.bioconductor.org/shields/downloads/devel/POMA.svg)](https://bioconductor.org/packages/stats/bioc/POMA) |
| [Devel](http://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Bioc devel status](https://bioconductor.org/shields/build/devel/bioc/POMA.svg)](https://bioconductor.org/checkResults/devel/bioc-LATEST/POMA/) | [![BioC devel version](https://img.shields.io/badge/devel%20version-1.13.23-blue.svg)](https://bioconductor.org/packages/devel/bioc/html/POMA.html) | [![Dependencies](http://bioconductor.org/shields/dependencies/devel/POMA.svg)](http://bioconductor.org/packages/devel/bioc/html/POMA.html#since) | [![Rank](http://www.bioconductor.org/shields/downloads/devel/POMA.svg)](https://bioconductor.org/packages/stats/bioc/POMA) |

<!-- badges: end -->

Expand Down
6 changes: 3 additions & 3 deletions man/PomaUnivariate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 51a4ac3

Please sign in to comment.