From ab8f1250377e69236643c2a9c0bf0e54a31876cb Mon Sep 17 00:00:00 2001 From: Tuomas Borman Date: Tue, 1 Dec 2026 21:56:22 +0200 Subject: [PATCH 1/2] generics --- DESCRIPTION | 2 + R/AllGenerics.R | 124 ++++++++++++++++++++++++++++++++++++++ R/getAnova.R | 9 +-- R/getChisqTest.R | 9 +-- R/getCorrelationTest.R | 23 +++---- R/getDunnTest.R | 9 +-- R/getEffectSize.R | 9 +-- R/getFirth.R | 9 +-- R/getFisherTest.R | 9 +-- R/getFriedmanTest.R | 9 +-- R/getGlm.R | 19 +++--- R/getKruskal.R | 9 +-- R/getLeveneTest.R | 9 +-- R/getLimma.R | 9 +-- R/getLm.R | 9 +-- R/getOrm.R | 9 +-- R/getPermanova.R | 9 +-- R/getPermdisp.R | 13 ++-- R/getShapiroTest.R | 9 +-- R/getTTest.R | 9 +-- R/getTukeyTest.R | 9 +-- R/getWilcoxonTest.R | 9 +-- R/utils.R | 40 ++++++------ R/zzz.R | 4 ++ README.Rmd | 5 +- README.md | 5 +- man/getAnova.Rd | 4 +- man/getChisqTest.Rd | 4 +- man/getCorrelationTest.Rd | 11 +--- man/getDunnTest.Rd | 4 +- man/getEffectSize.Rd | 10 +-- man/getFirth.Rd | 4 +- man/getFisherTest.Rd | 4 +- man/getFriedmanTest.Rd | 4 +- man/getGlm.Rd | 11 +--- man/getKruskal.Rd | 4 +- man/getLeveneTest.Rd | 4 +- man/getLimma.Rd | 4 +- man/getLm.Rd | 4 +- man/getOrm.Rd | 4 +- man/getPermanova.Rd | 13 +--- man/getPermdisp.Rd | 4 +- man/getShapiroTest.Rd | 4 +- man/getTTest.Rd | 4 +- man/getTukeyTest.Rd | 4 +- man/getWilcoxonTest.Rd | 4 +- vignettes/daa.Rmd | 5 +- 47 files changed, 310 insertions(+), 192 deletions(-) create mode 100644 R/AllGenerics.R create mode 100644 R/zzz.R diff --git a/DESCRIPTION b/DESCRIPTION index 882685a..d71b7de 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,11 +27,13 @@ Imports: lmerTest, logistf, MASS, + methods, permute, reformulas, rlang, rms, rstatix, + S7, stats, tidyr, utils, diff --git a/R/AllGenerics.R b/R/AllGenerics.R new file mode 100644 index 0000000..4d29ce4 --- /dev/null +++ b/R/AllGenerics.R @@ -0,0 +1,124 @@ +#' @export +getAnova <- S7::new_generic( + "getAnova", "x", + function(x, formula, ...) S7::S7_dispatch() +) + +#' @export +getChisqTest <- S7::new_generic( + "getChisqTest", "x", + function(x, formula, detection = 0, p.adjust.method = "BH", ...) S7::S7_dispatch() +) + +#' @export +getCorrelationTest <- S7::new_generic( + "getCorrelationTest", "x", + function(x, formula, method = c("spearman", "pearson", "kendall"), + adjust.by = NULL, p.adjust.method = "BH", ...) S7::S7_dispatch() +) + +#' @export +getDunnTest <- S7::new_generic( + "getDunnTest", "x", + function(x, formula, ...) S7::S7_dispatch() +) + +#' @export +getEffectSize <- S7::new_generic( + "getEffectSize", "x", + function(x, formula, + method = c("cliff", "cohen", "difference", "ratio", "log_ratio"), + pair.by = NULL, ...) S7::S7_dispatch() +) + +#' @export +getFirth <- S7::new_generic( + "getFirth", "x", + function(x, formula, p_adjust_method = "BH", ...) S7::S7_dispatch() +) + +#' @export +getFisherTest <- S7::new_generic( + "getFisherTest", "x", + function(x, formula, detection = 0, p.adjust.method = "BH", ...) S7::S7_dispatch() +) + +#' @export +getFriedmanTest <- S7::new_generic( + "getFriedmanTest", "x", + function(x, formula, pair.by, ...) S7::S7_dispatch() +) + +#' @export +getGlm <- S7::new_generic( + "getGlm", "x", + function(x, formula, family = poisson(), offset = NULL, + p_adjust_method = "BH", ...) S7::S7_dispatch() +) + +#' @export +getKruskal <- S7::new_generic( + "getKruskal", "x", + function(x, formula, ...) S7::S7_dispatch() +) + +#' @export +getLeveneTest <- S7::new_generic( + "getLeveneTest", "x", + function(x, formula, ...) S7::S7_dispatch() +) + +#' @export +getLimma <- S7::new_generic( + "getLimma", "x", + function(x, formula, ...) S7::S7_dispatch() +) + +#' @export +getLm <- S7::new_generic( + "getLm", "x", + function(x, formula, p_adjust_method = "BH", ...) S7::S7_dispatch() +) + +#' @export +getOrm <- S7::new_generic( + "getOrm", "x", + function(x, formula, p_adjust_method = "BH", ...) S7::S7_dispatch() +) + +#' @export +getPermanova <- S7::new_generic( + "getPermanova", "x", + function(x, formula, pairwise = FALSE, method = "bray", permutations = 999L, + p.adjust.method = "BH", pair.by = NULL, ...) S7::S7_dispatch() +) + +#' @export +getPermdisp <- S7::new_generic( + "getPermdisp", "x", + function(x, formula, method = "bray", permutations = 999L, ...) S7::S7_dispatch() +) + +#' @export +getShapiroTest <- S7::new_generic( + "getShapiroTest", "x", + function(x, formula, p.adjust.method = "BH") S7::S7_dispatch() +) + +#' @export +getTTest <- S7::new_generic( + "getTTest", "x", + function(x, formula, pair.by = NULL, ...) S7::S7_dispatch() +) + +#' @export +getTukeyTest <- S7::new_generic( + "getTukeyTest", "x", + function(x, formula, ...) S7::S7_dispatch() +) + +#' @export +getWilcoxonTest <- S7::new_generic( + "getWilcoxonTest", "x", + function(x, formula, pair.by = NULL, ...) S7::S7_dispatch() +) diff --git a/R/getAnova.R b/R/getAnova.R index 14fad37..8b4e579 100644 --- a/R/getAnova.R +++ b/R/getAnova.R @@ -3,7 +3,7 @@ #' @description #' Performs ANOVA to compare values between two or more groups. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the variable to test #' (assay name, colData, or rowData variable) and the RHS specifies the #' grouping variable, e.g., \code{counts ~ Group}. @@ -17,15 +17,16 @@ #' tse <- mia::agglomerateByRank(tse, "phylum") #' res <- getAnova(tse, counts ~ Geographical_location) #' +#' @name getAnova +#' @usage getAnova(x, formula, ...) #' @importFrom rstatix anova_test -#' @export -getAnova <- function(tse, formula, ...) { +S7::method(getAnova, methods::getClass("SummarizedExperiment")) <- function(x, formula, ...) { if (length(all.vars(formula[[3]])) != 1L) { stop("Formula RHS must specify exactly one grouping variable.", call. = FALSE ) } - df <- .get_long_data(tse, formula) + df <- .get_long_data(x, formula) res <- .calculate_rstatix( df = df, formula = formula, FUN = anova_test, ... diff --git a/R/getChisqTest.R b/R/getChisqTest.R index e089948..da81a67 100644 --- a/R/getChisqTest.R +++ b/R/getChisqTest.R @@ -12,7 +12,7 @@ #' features and added to column \code{p.adj}. The chi-square approximation can #' be inaccurate if there are few samples; use \code{\link{getFisherTest}} then. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the variable to test #' (assay name, colData, or rowData variable) and the RHS specifies the #' grouping variable, e.g., \code{counts ~ Group}. @@ -32,11 +32,12 @@ #' #' @seealso \code{\link{getFisherTest}} #' +#' @name getChisqTest +#' @usage getChisqTest(x, formula, detection = 0, p.adjust.method = "BH", ...) #' @importFrom rstatix chisq_test -#' @export -getChisqTest <- function(tse, formula, detection = 0, p.adjust.method = "BH", ...) { +S7::method(getChisqTest, methods::getClass("SummarizedExperiment")) <- function(x, formula, detection = 0, p.adjust.method = "BH", ...) { .calculate_contingency_test( - tse, formula, detection, p.adjust.method, + x, formula, detection, p.adjust.method, FUN = chisq_test, ... ) } diff --git a/R/getCorrelationTest.R b/R/getCorrelationTest.R index 5d6d372..4b0659b 100644 --- a/R/getCorrelationTest.R +++ b/R/getCorrelationTest.R @@ -25,7 +25,7 @@ #' slightly optimistic. Kendall correlation is not supported with #' \code{adjust.by}. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the variable to test #' (assay name, colData, or rowData variable) and the RHS specifies the #' numeric variable to correlate with, e.g., \code{counts ~ shannon}. @@ -53,8 +53,9 @@ #' # Correlation after removing the effect of covariates #' res <- getCorrelationTest(tse, counts ~ shannon, adjust.by = "Gender") #' -#' @export -getCorrelationTest <- function(tse, formula, method = c("spearman", "pearson", "kendall"), +#' @name getCorrelationTest +#' @usage getCorrelationTest(x, formula, method = c("spearman", "pearson", "kendall"), adjust.by = NULL, p.adjust.method = "BH", ...) +S7::method(getCorrelationTest, methods::getClass("SummarizedExperiment")) <- function(x, formula, method = c("spearman", "pearson", "kendall"), adjust.by = NULL, p.adjust.method = "BH", ...) { if (length(all.vars(formula[[3]])) != 1L) { stop("Formula RHS must specify exactly one numeric variable.", @@ -69,11 +70,11 @@ getCorrelationTest <- function(tse, formula, method = c("spearman", "pearson", " ) } res <- .get_adjusted_correlation( - tse, formula, method, adjust.by, p.adjust.method, ... + x, formula, method, adjust.by, p.adjust.method, ... ) } else { res <- .get_unadjusted_correlation( - tse, formula, method, p.adjust.method, ... + x, formula, method, p.adjust.method, ... ) } return(res) @@ -90,10 +91,10 @@ getCorrelationTest <- function(tse, formula, method = c("spearman", "pearson", " #' @importFrom rlang .data #' @importFrom dplyr group_by filter n #' @importFrom stats var complete.cases -.get_unadjusted_correlation <- function(tse, formula, method, p.adjust.method, ...) { +.get_unadjusted_correlation <- function(x, formula, method, p.adjust.method, ...) { lhs <- .get_lhs(formula) rhs <- .get_rhs(formula) - df <- .get_long_data(tse, formula) + df <- .get_long_data(x, formula) if (!is.numeric(df[[rhs]])) { stop("The independent variable must be numeric.", call. = FALSE) } @@ -123,7 +124,7 @@ getCorrelationTest <- function(tse, formula, method = c("spearman", "pearson", " #' @importFrom rstatix adjust_pvalue #' @importFrom stats reformulate #' @importFrom SummarizedExperiment colData -.get_adjusted_correlation <- function(tse, formula, method, adjust.by, p.adjust.method, ...) { +.get_adjusted_correlation <- function(x, formula, method, adjust.by, p.adjust.method, ...) { # Covariates are given as names or as a formula, e.g., ~ Gender + (1 | ID) adjust_formula <- if (inherits(adjust.by, "formula")) { adjust.by @@ -131,9 +132,9 @@ getCorrelationTest <- function(tse, formula, method = c("spearman", "pearson", " reformulate(adjust.by) } adjust_variables <- all.vars(adjust_formula) - if (!all(adjust_variables %in% colnames(colData(tse)))) { + if (!all(adjust_variables %in% colnames(colData(x)))) { stop("Covariate(s) not found in colData(x): ", - paste0("'", setdiff(adjust_variables, colnames(colData(tse))), + paste0("'", setdiff(adjust_variables, colnames(colData(x))), "'", collapse = ", " ), @@ -141,7 +142,7 @@ getCorrelationTest <- function(tse, formula, method = c("spearman", "pearson", " ) } # Covariates are sample variables, fetched in the same way as pair.by - data_list <- .get_wide_data(tse, formula, adjust_variables) + data_list <- .get_wide_data(x, formula, adjust_variables) if (!is.numeric(data_list[["sample_metadata"]][[.get_rhs(formula)]])) { stop("The independent variable must be numeric.", call. = FALSE) } diff --git a/R/getDunnTest.R b/R/getDunnTest.R index af548a8..5a32c5a 100644 --- a/R/getDunnTest.R +++ b/R/getDunnTest.R @@ -4,7 +4,7 @@ #' Performs Dunn's test to compare all pairs of groups after Kruskal-Wallis #' test. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the variable to test #' (assay name, colData, or rowData variable) and the RHS specifies the #' grouping variable, e.g., \code{counts ~ Group}. @@ -20,15 +20,16 @@ #' #' @seealso \code{\link{getKruskal}} #' +#' @name getDunnTest +#' @usage getDunnTest(x, formula, ...) #' @importFrom rstatix dunn_test -#' @export -getDunnTest <- function(tse, formula, ...) { +S7::method(getDunnTest, methods::getClass("SummarizedExperiment")) <- function(x, formula, ...) { if (length(all.vars(formula[[3]])) != 1L) { stop("Formula RHS must specify exactly one grouping variable.", call. = FALSE ) } - df <- .get_long_data(tse, formula) + df <- .get_long_data(x, formula) res <- .calculate_rstatix( df = df, formula = formula, FUN = dunn_test, ... diff --git a/R/getEffectSize.R b/R/getEffectSize.R index 4fa8529..d0a1b34 100644 --- a/R/getEffectSize.R +++ b/R/getEffectSize.R @@ -26,7 +26,7 @@ #' \code{\link{getWilcoxonTest}}. Positive values mean that values are higher #' in \code{group1} than in \code{group2}. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the variable to test #' (assay name, colData, or rowData variable) and the RHS specifies the #' grouping variable, e.g., \code{counts ~ Group}. @@ -59,8 +59,9 @@ #' \code{\link[effsize:cliff.delta]{effsize::cliff.delta}}, #' \code{\link[effsize:cohen.d]{effsize::cohen.d}} #' -#' @export -getEffectSize <- function(tse, formula, +#' @name getEffectSize +#' @usage getEffectSize(x, formula, method = c("cliff", "cohen", "difference", "ratio", "log_ratio"), pair.by = NULL, ...) +S7::method(getEffectSize, methods::getClass("SummarizedExperiment")) <- function(x, formula, method = c("cliff", "cohen", "difference", "ratio", "log_ratio"), pair.by = NULL, ...) { if (length(all.vars(formula[[3]])) != 1L) { @@ -76,7 +77,7 @@ getEffectSize <- function(tse, formula, ) return(NULL) } - df <- .get_long_data(tse, formula, pair.by) + df <- .get_long_data(x, formula, pair.by) .calculate_effect_size(df, formula, method, pair.by, ...) } diff --git a/R/getFirth.R b/R/getFirth.R index b7a2f10..9881e2c 100644 --- a/R/getFirth.R +++ b/R/getFirth.R @@ -3,7 +3,7 @@ #' @description #' Fits Firth logistic regression per feature using wide-format data. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the assay or colData #' variable (must be binary/presence-absence) and the RHS specifies variables #' from \code{colData(tse)}, e.g., \code{pa ~ Group + Age}. @@ -24,10 +24,11 @@ #' res <- getFirth(tse, pa ~ Geographical_location) #' } #' +#' @name getFirth +#' @usage getFirth(x, formula, p_adjust_method = "BH", ...) #' @importFrom logistf logistf logistf.control -#' @export -getFirth <- function(tse, formula, p_adjust_method = "BH", ...) { - data_list <- .get_wide_data(tse, formula) +S7::method(getFirth, methods::getClass("SummarizedExperiment")) <- function(x, formula, p_adjust_method = "BH", ...) { + data_list <- .get_wide_data(x, formula) res <- .train_model_per_feature( formula = formula, mat = data_list[["matrix"]], diff --git a/R/getFisherTest.R b/R/getFisherTest.R index ad60b7f..aead31b 100644 --- a/R/getFisherTest.R +++ b/R/getFisherTest.R @@ -11,7 +11,7 @@ #' absent in all samples are skipped. P-values are adjusted for the number of #' features and added to column \code{p.adj}. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the variable to test #' (assay name, colData, or rowData variable) and the RHS specifies the #' grouping variable, e.g., \code{counts ~ Group}. @@ -31,11 +31,12 @@ #' #' @seealso \code{\link{getChisqTest}} #' +#' @name getFisherTest +#' @usage getFisherTest(x, formula, detection = 0, p.adjust.method = "BH", ...) #' @importFrom rstatix fisher_test -#' @export -getFisherTest <- function(tse, formula, detection = 0, p.adjust.method = "BH", ...) { +S7::method(getFisherTest, methods::getClass("SummarizedExperiment")) <- function(x, formula, detection = 0, p.adjust.method = "BH", ...) { .calculate_contingency_test( - tse, formula, detection, p.adjust.method, + x, formula, detection, p.adjust.method, FUN = fisher_test, ... ) } diff --git a/R/getFriedmanTest.R b/R/getFriedmanTest.R index 80dfa11..d1d2556 100644 --- a/R/getFriedmanTest.R +++ b/R/getFriedmanTest.R @@ -8,7 +8,7 @@ #' The test is performed separately for each feature. Only pairing IDs present #' in all groups of the feature are used. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the variable to test #' (assay name, colData, or rowData variable) and the RHS specifies the #' grouping variable, e.g., \code{counts ~ Time}. @@ -24,8 +24,9 @@ #' tse$timepoint <- factor(tse$timepoint) #' res <- getFriedmanTest(tse, signal ~ timepoint, pair.by = "subject") #' -#' @export -getFriedmanTest <- function(tse, formula, pair.by, ...) { +#' @name getFriedmanTest +#' @usage getFriedmanTest(x, formula, pair.by, ...) +S7::method(getFriedmanTest, methods::getClass("SummarizedExperiment")) <- function(x, formula, pair.by, ...) { if (length(all.vars(formula[[3]])) != 1L) { stop("Formula RHS must specify exactly one grouping variable.", call. = FALSE @@ -33,7 +34,7 @@ getFriedmanTest <- function(tse, formula, pair.by, ...) { } lhs <- .get_lhs(formula) rhs <- .get_rhs(formula) - df <- .get_long_data(tse, formula, pair.by) |> + df <- .get_long_data(x, formula, pair.by) |> .get_complete_blocks(lhs, rhs, pair.by) .calculate_friedman(df, lhs, rhs, pair.by, ...) } diff --git a/R/getGlm.R b/R/getGlm.R index 1fbce2a..b123c03 100644 --- a/R/getGlm.R +++ b/R/getGlm.R @@ -24,7 +24,7 @@ #' binomial model. The \code{gaussian()} family gives the same result as #' \code{\link{getLm}}. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the assay or colData #' variable and the RHS specifies variables from \code{colData(tse)}, #' e.g., \code{counts ~ Group}. @@ -63,12 +63,13 @@ #' #' @seealso \code{\link{getLm}}, \code{\link{getFirth}} #' +#' @name getGlm +#' @usage getGlm(x, formula, family = poisson(), offset = NULL, p_adjust_method = "BH", ...) #' @importFrom stats poisson -#' @export -getGlm <- function(tse, formula, family = poisson(), offset = NULL, +S7::method(getGlm, methods::getClass("SummarizedExperiment")) <- function(x, formula, family = poisson(), offset = NULL, p_adjust_method = "BH", ...) { - data_list <- .get_wide_data(tse, formula) - offset_values <- .get_offset(tse, offset) + data_list <- .get_wide_data(x, formula) + offset_values <- .get_offset(x, offset) res <- .train_model_per_feature( formula = formula, mat = data_list[["matrix"]], @@ -90,18 +91,18 @@ getGlm <- function(tse, formula, family = poisson(), offset = NULL, #' @keywords internal #' @noRd #' @importFrom SummarizedExperiment colData -.get_offset <- function(tse, offset) { +.get_offset <- function(x, offset) { if (is.null(offset)) { return(NULL) } # Name of a column in colData if (is.character(offset) && length(offset) == 1L) { - if (!offset %in% colnames(colData(tse))) { + if (!offset %in% colnames(colData(x))) { stop("'offset' must be a column in colData(x).", call. = FALSE) } - offset <- colData(tse)[[offset]] + offset <- colData(x)[[offset]] } - if (!is.numeric(offset) || length(offset) != ncol(tse) || + if (!is.numeric(offset) || length(offset) != ncol(x) || anyNA(offset)) { stop("'offset' must be a numeric vector without missing values and ", "with a value for each sample.", diff --git a/R/getKruskal.R b/R/getKruskal.R index e2bb08b..2abc93d 100644 --- a/R/getKruskal.R +++ b/R/getKruskal.R @@ -3,7 +3,7 @@ #' @description #' Performs Kruskal-Wallis test to compare values between two or more groups. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the variable to test #' (assay name, colData, or rowData variable) and the RHS specifies the #' grouping variable, e.g., \code{counts ~ Group}. @@ -17,15 +17,16 @@ #' tse <- mia::agglomerateByRank(tse, "phylum") #' res <- getKruskal(tse, counts ~ Geographical_location) #' +#' @name getKruskal +#' @usage getKruskal(x, formula, ...) #' @importFrom rstatix kruskal_test -#' @export -getKruskal <- function(tse, formula, ...) { +S7::method(getKruskal, methods::getClass("SummarizedExperiment")) <- function(x, formula, ...) { if (length(all.vars(formula[[3]])) != 1L) { stop("Formula RHS must specify exactly one grouping variable.", call. = FALSE ) } - df <- .get_long_data(tse, formula) + df <- .get_long_data(x, formula) res <- .calculate_rstatix( df = df, formula = formula, FUN = kruskal_test, ... diff --git a/R/getLeveneTest.R b/R/getLeveneTest.R index 0dfdc6b..916b0f7 100644 --- a/R/getLeveneTest.R +++ b/R/getLeveneTest.R @@ -4,7 +4,7 @@ #' Performs Levene's test to check whether the variances are equal between #' groups. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the variable to test #' (assay name, colData, or rowData variable) and the RHS specifies the #' grouping variable, e.g., \code{counts ~ Group}. @@ -18,15 +18,16 @@ #' tse <- mia::agglomerateByRank(tse, "phylum") #' res <- getLeveneTest(tse, counts ~ Geographical_location) #' +#' @name getLeveneTest +#' @usage getLeveneTest(x, formula, ...) #' @importFrom rstatix levene_test -#' @export -getLeveneTest <- function(tse, formula, ...) { +S7::method(getLeveneTest, methods::getClass("SummarizedExperiment")) <- function(x, formula, ...) { if (length(all.vars(formula[[3]])) != 1L) { stop("Formula RHS must specify exactly one grouping variable.", call. = FALSE ) } - df <- .get_long_data(tse, formula) + df <- .get_long_data(x, formula) # Levene's test requires a factor df[[.get_rhs(formula)]] <- factor(df[[.get_rhs(formula)]]) res <- .calculate_rstatix( diff --git a/R/getLimma.R b/R/getLimma.R index 18c6d79..a1b67ca 100644 --- a/R/getLimma.R +++ b/R/getLimma.R @@ -3,7 +3,7 @@ #' @description #' Fits a limma model using wide-format data and sample metadata. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the assay or colData #' variable and the RHS specifies variables from \code{colData(tse)}, #' e.g., \code{counts ~ Group}. @@ -17,11 +17,12 @@ #' tse <- mia::agglomerateByRank(tse, "phylum") #' fit <- getLimma(tse, counts ~ Geographical_location) #' +#' @name getLimma +#' @usage getLimma(x, formula, ...) #' @importFrom limma eBayes lmFit #' @importFrom stats model.matrix -#' @export -getLimma <- function(tse, formula, ...) { - data_list <- .get_wide_data(tse, formula) +S7::method(getLimma, methods::getClass("SummarizedExperiment")) <- function(x, formula, ...) { + data_list <- .get_wide_data(x, formula) res <- .calculate_limma( formula = formula, mat = data_list[["matrix"]], diff --git a/R/getLm.R b/R/getLm.R index 3eddce6..6c2fdca 100644 --- a/R/getLm.R +++ b/R/getLm.R @@ -11,7 +11,7 @@ #' \code{lmerTest::lmer}, which provides p-values for the fixed effects. #' Otherwise, a linear model is fitted with \code{lm}. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the assay or colData #' variable and the RHS specifies variables from \code{colData(tse)}, #' e.g., \code{rclr ~ Group}. Random effects are given as in \code{lme4}, @@ -38,12 +38,13 @@ #' tse <- mia::transformAssay(tse, assay.type = "signal", method = "rclr") #' res <- getLm(tse, rclr ~ timepoint + (1 | subject)) #' +#' @name getLm +#' @usage getLm(x, formula, p_adjust_method = "BH", ...) #' @importFrom broom tidy #' @importFrom stats lm #' @importFrom reformulas findbars -#' @export -getLm <- function(tse, formula, p_adjust_method = "BH", ...) { - data_list <- .get_wide_data(tse, formula) +S7::method(getLm, methods::getClass("SummarizedExperiment")) <- function(x, formula, p_adjust_method = "BH", ...) { + data_list <- .get_wide_data(x, formula) # Random effects, e.g., (1 | Subject), require a mixed model FUN <- if (is.null(findbars(formula))) .run_lm else .run_lmm res <- .train_model_per_feature( diff --git a/R/getOrm.R b/R/getOrm.R index 9e88835..de63692 100644 --- a/R/getOrm.R +++ b/R/getOrm.R @@ -3,7 +3,7 @@ #' @description #' Fits an ordinal regression model (ORM) per feature using wide-format data. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the assay or colData #' variable and the RHS specifies variables from \code{colData(tse)}, #' e.g., \code{counts ~ Group}. @@ -21,11 +21,12 @@ #' tse <- mia::agglomerateByRank(tse, "phylum") #' res <- getOrm(tse, counts ~ Geographical_location) #' +#' @name getOrm +#' @usage getOrm(x, formula, p_adjust_method = "BH", ...) #' @importFrom rms orm #' @importFrom stats pchisq -#' @export -getOrm <- function(tse, formula, p_adjust_method = "BH", ...) { - data_list <- .get_wide_data(tse, formula) +S7::method(getOrm, methods::getClass("SummarizedExperiment")) <- function(x, formula, p_adjust_method = "BH", ...) { + data_list <- .get_wide_data(x, formula) res <- .train_model_per_feature( formula = formula, mat = data_list[["matrix"]], diff --git a/R/getPermanova.R b/R/getPermanova.R index 4cea31e..45e2b6c 100644 --- a/R/getPermanova.R +++ b/R/getPermanova.R @@ -22,7 +22,7 @@ #' The p-values are based on permutations, so set a seed for reproducible #' results. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the assay name and the RHS #' specifies the grouping variable from \code{colData}, e.g., #' \code{counts ~ Group}. @@ -57,8 +57,9 @@ #' @seealso #' \code{\link[vegan:adonis2]{vegan::adonis2}} #' -#' @export -getPermanova <- function(tse, formula, pairwise = FALSE, method = "bray", permutations = 999L, +#' @name getPermanova +#' @usage getPermanova(x, formula, pairwise = FALSE, method = "bray", permutations = 999L, p.adjust.method = "BH", pair.by = NULL, ...) +S7::method(getPermanova, methods::getClass("SummarizedExperiment")) <- function(x, formula, pairwise = FALSE, method = "bray", permutations = 999L, p.adjust.method = "BH", pair.by = NULL, ...) { if (length(all.vars(formula[[3]])) != 1L) { stop("Formula RHS must specify exactly one grouping variable.", @@ -68,7 +69,7 @@ getPermanova <- function(tse, formula, pairwise = FALSE, method = "bray", permut group_column <- .get_rhs(formula) # Assay (features x samples) and sample metadata with the grouping # variable and the pairing variable - data_list <- .get_wide_data(tse, formula, pair.by) + data_list <- .get_wide_data(x, formula, pair.by) # Samples as rows, as required by vegdist abundance <- data_list[["matrix"]] |> t() sample_data <- data_list[["sample_metadata"]] diff --git a/R/getPermdisp.R b/R/getPermdisp.R index ed920ea..1b9c122 100644 --- a/R/getPermdisp.R +++ b/R/getPermdisp.R @@ -14,7 +14,7 @@ #' compared with a permutation test. The p-value is based on permutations, so #' set a seed for reproducible results. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the assay name and the RHS #' specifies the grouping variable from \code{colData}, e.g., #' \code{counts ~ Group}. @@ -36,8 +36,9 @@ #' #' @seealso \code{\link[vegan:betadisper]{vegan::betadisper}} #' -#' @export -getPermdisp <- function(tse, formula, method = "bray", permutations = 999L, ...) { +#' @name getPermdisp +#' @usage getPermdisp(x, formula, method = "bray", permutations = 999L, ...) +S7::method(getPermdisp, methods::getClass("SummarizedExperiment")) <- function(x, formula, method = "bray", permutations = 999L, ...) { if (length(all.vars(formula[[3]])) != 1L) { stop("Formula RHS must specify exactly one grouping variable.", call. = FALSE @@ -45,7 +46,7 @@ getPermdisp <- function(tse, formula, method = "bray", permutations = 999L, ...) } group_column <- .get_rhs(formula) # Samples (rows) with a group, and their groups - samples <- .get_permdisp_samples(tse, formula, group_column) + samples <- .get_permdisp_samples(x, formula, group_column) # Distances to group centroids and a permutation test for the difference .calculate_permdisp( samples[["abundance"]], samples[["groups"]], method, permutations, ... @@ -61,8 +62,8 @@ getPermdisp <- function(tse, formula, method = "bray", permutations = 999L, ...) #' #' @keywords internal #' @noRd -.get_permdisp_samples <- function(tse, formula, group_column) { - data_list <- .get_wide_data(tse, formula) +.get_permdisp_samples <- function(x, formula, group_column) { + data_list <- .get_wide_data(x, formula) abundance <- data_list[["matrix"]] |> t() sample_data <- data_list[["sample_metadata"]] has_values <- stats::complete.cases(sample_data) diff --git a/R/getShapiroTest.R b/R/getShapiroTest.R index bef9961..2b399c5 100644 --- a/R/getShapiroTest.R +++ b/R/getShapiroTest.R @@ -17,7 +17,7 @@ #' warning. P-values are adjusted for the number of features and added to column #' \code{p.adj}. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the variable to test #' (assay name or colData variable) and the RHS specifies variables from #' \code{colData(tse)}, e.g., \code{counts ~ Group}. Random effects are @@ -41,13 +41,14 @@ #' #' @seealso \code{\link{getLeveneTest}}, \code{\link{getLm}} #' +#' @name getShapiroTest +#' @usage getShapiroTest(x, formula, p.adjust.method = "BH") #' @importFrom rstatix shapiro_test adjust_pvalue #' @importFrom stats lm residuals var update complete.cases #' @importFrom lmerTest lmer #' @importFrom reformulas findbars -#' @export -getShapiroTest <- function(tse, formula, p.adjust.method = "BH") { - data_list <- .get_wide_data(tse, formula) +S7::method(getShapiroTest, methods::getClass("SummarizedExperiment")) <- function(x, formula, p.adjust.method = "BH") { + data_list <- .get_wide_data(x, formula) res <- .train_model_per_feature( formula = formula, mat = data_list[["matrix"]], diff --git a/R/getTTest.R b/R/getTTest.R index 5051bb4..4da144b 100644 --- a/R/getTTest.R +++ b/R/getTTest.R @@ -3,7 +3,7 @@ #' @description #' Performs t-test to compare values between two groups. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the variable to test #' (assay name, colData, or rowData variable) and the RHS specifies the #' grouping variable, e.g., \code{counts ~ Group}. @@ -19,15 +19,16 @@ #' tse <- mia::agglomerateByRank(tse, "phylum") #' res <- getTTest(tse, counts ~ Geographical_location) #' +#' @name getTTest +#' @usage getTTest(x, formula, pair.by = NULL, ...) #' @importFrom rstatix t_test -#' @export -getTTest <- function(tse, formula, pair.by = NULL, ...) { +S7::method(getTTest, methods::getClass("SummarizedExperiment")) <- function(x, formula, pair.by = NULL, ...) { if (length(all.vars(formula[[3]])) != 1L) { stop("Formula RHS must specify exactly one grouping variable.", call. = FALSE ) } - df <- .get_long_data(tse, formula, pair.by) + df <- .get_long_data(x, formula, pair.by) res <- .calculate_rstatix( df = df, formula = formula, pair.by = pair.by, FUN = t_test, ... diff --git a/R/getTukeyTest.R b/R/getTukeyTest.R index e5fc118..3f4d7e1 100644 --- a/R/getTukeyTest.R +++ b/R/getTukeyTest.R @@ -4,7 +4,7 @@ #' Performs Tukey's honest significant difference test to compare all pairs of #' groups after ANOVA. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the variable to test #' (assay name, colData, or rowData variable) and the RHS specifies the #' grouping variable, e.g., \code{counts ~ Group}. @@ -20,15 +20,16 @@ #' #' @seealso \code{\link{getAnova}} #' +#' @name getTukeyTest +#' @usage getTukeyTest(x, formula, ...) #' @importFrom rstatix tukey_hsd -#' @export -getTukeyTest <- function(tse, formula, ...) { +S7::method(getTukeyTest, methods::getClass("SummarizedExperiment")) <- function(x, formula, ...) { if (length(all.vars(formula[[3]])) != 1L) { stop("Formula RHS must specify exactly one grouping variable.", call. = FALSE ) } - df <- .get_long_data(tse, formula) + df <- .get_long_data(x, formula) res <- .calculate_rstatix( df = df, formula = formula, FUN = tukey_hsd, ... diff --git a/R/getWilcoxonTest.R b/R/getWilcoxonTest.R index 8261131..1768827 100644 --- a/R/getWilcoxonTest.R +++ b/R/getWilcoxonTest.R @@ -12,7 +12,7 @@ #' The test does not calculate an effect size. Use #' \code{\link{getEffectSize}} as a separate step. #' -#' @param tse A \code{SummarizedExperiment} object. +#' @param x A \code{SummarizedExperiment} object. #' @param formula A formula where the LHS specifies the variable to test #' (assay name, colData, or rowData variable) and the RHS specifies the #' grouping variable, e.g., \code{counts ~ Group}. @@ -28,15 +28,16 @@ #' tse <- mia::agglomerateByRank(tse, "phylum") #' res <- getWilcoxonTest(tse, counts ~ Geographical_location) #' +#' @name getWilcoxonTest +#' @usage getWilcoxonTest(x, formula, pair.by = NULL, ...) #' @importFrom rstatix wilcox_test -#' @export -getWilcoxonTest <- function(tse, formula, pair.by = NULL, ...) { +S7::method(getWilcoxonTest, methods::getClass("SummarizedExperiment")) <- function(x, formula, pair.by = NULL, ...) { if (length(all.vars(formula[[3]])) != 1L) { stop("Formula RHS must specify exactly one grouping variable.", call. = FALSE ) } - df <- .get_long_data(tse, formula, pair.by) + df <- .get_long_data(x, formula, pair.by) res <- .calculate_rstatix( df = df, formula = formula, pair.by = pair.by, FUN = wilcox_test, ... diff --git a/R/utils.R b/R/utils.R index a7a9427..249c4b4 100644 --- a/R/utils.R +++ b/R/utils.R @@ -40,15 +40,15 @@ #' @keywords internal #' @noRd #' @importFrom SummarizedExperiment assayNames colData rowData assay -.get_long_data <- function(tse, formula, pair.by = NULL) { +.get_long_data <- function(x, formula, pair.by = NULL) { lhs <- .get_lhs(formula) - is_assay <- lhs %in% assayNames(tse) - is_coldata <- lhs %in% colnames(colData(tse)) - is_rowdata <- lhs %in% colnames(rowData(tse)) + is_assay <- lhs %in% assayNames(x) + is_coldata <- lhs %in% colnames(colData(x)) + is_rowdata <- lhs %in% colnames(rowData(x)) if (is_assay) { - df <- .merge_tse(tse, lhs) + df <- .merge_tse(x, lhs) } else { FUN <- if (is_coldata) { colData @@ -60,7 +60,7 @@ call. = FALSE ) } - df <- tse |> FUN() + df <- x |> FUN() df <- as.data.frame(df) df[["colnames"]] <- rownames(df) df[["rownames"]] <- lhs @@ -94,10 +94,10 @@ #' @importFrom SummarizedExperiment rowData colData assay #' @importFrom tidyr pivot_longer #' @importFrom dplyr left_join -.merge_tse <- function(tse, assay.type) { - rd <- tse |> rowData() - cd <- tse |> colData() - mat <- tse |> assay(assay.type) +.merge_tse <- function(x, assay.type) { + rd <- x |> rowData() + cd <- x |> colData() + mat <- x |> assay(assay.type) mat <- mat |> as.data.frame() mat[["rownames"]] <- rownames(mat) @@ -175,7 +175,7 @@ #' @noRd #' @importFrom dplyr bind_rows #' @importFrom stats p.adjust -.calculate_contingency_test <- function(tse, formula, detection, p.adjust.method, FUN, ...) { +.calculate_contingency_test <- function(x, formula, detection, p.adjust.method, FUN, ...) { if (length(all.vars(formula[[3]])) != 1L) { stop("Formula RHS must specify exactly one grouping variable.", call. = FALSE @@ -183,7 +183,7 @@ } lhs <- .get_lhs(formula) rhs <- .get_rhs(formula) - df <- .get_long_data(tse, formula) + df <- .get_long_data(x, formula) df <- df[!is.na(df[[lhs]]) & !is.na(df[[rhs]]), , drop = FALSE] results <- lapply(split(df, df[["rownames"]]), function(feature_data) { present <- feature_data[[lhs]] > detection @@ -270,13 +270,13 @@ #' @keywords internal #' @noRd #' @importFrom SummarizedExperiment assay colData assayNames -.get_wide_data <- function(tse, formula, pair.by = NULL) { +.get_wide_data <- function(x, formula, pair.by = NULL) { lhs <- .get_lhs(formula) rhs <- .get_rhs(formula) if (!all(c(lhs, rhs) %in% c( - assayNames(tse), - colnames(colData(tse)) + assayNames(x), + colnames(colData(x)) ))) { stop( "All formula variables must be in assayNames(x) or colData(x).", @@ -284,21 +284,21 @@ ) } # Pairing variable is a sample variable - if (!all(pair.by %in% colnames(colData(tse)))) { + if (!all(pair.by %in% colnames(colData(x)))) { stop("'pair.by' must be a column in colData(x).", call. = FALSE) } - is_assay <- lhs %in% assayNames(tse) + is_assay <- lhs %in% assayNames(x) if (is_assay) { - lhs_df <- assay(tse, lhs) + lhs_df <- assay(x, lhs) } else { - lhs_df <- colData(tse)[, lhs, drop = FALSE] |> + lhs_df <- colData(x)[, lhs, drop = FALSE] |> as.data.frame() |> t() } lhs_df <- lhs_df |> as.data.frame() - rhs_df <- colData(tse)[, c(rhs, pair.by), drop = FALSE] |> + rhs_df <- colData(x)[, c(rhs, pair.by), drop = FALSE] |> as.data.frame() if (!all(vapply(lhs_df, is.numeric, logical(1L)))) { diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..a81dfb1 --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,4 @@ +# Register the S7 methods when the package is loaded +.onLoad <- function(libname, pkgname) { + S7::methods_register() +} diff --git a/README.Rmd b/README.Rmd index 6e5340d..b7d4a7e 100644 --- a/README.Rmd +++ b/README.Rmd @@ -23,9 +23,8 @@ knitr::opts_chunk$set( ## Using the package -This package provides functions for differential abundance analysis (DAA) -of microbiome data. It works with `TreeSummarizedExperiment` and -`SummarizedExperiment` objects from the miaverse ecosystem. +This package provides functions for statistical testing for +`SummarizedExperiment` objects. **Available methods:** diff --git a/README.md b/README.md index b4bc61f..dcc6fb2 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,8 @@ coverage](https://codecov.io/gh/microbiome/daa/graph/badge.svg)](https://app.cod ## Using the package -This package provides functions for differential abundance analysis -(DAA) of microbiome data. It works with `TreeSummarizedExperiment` and -`SummarizedExperiment` objects from the miaverse ecosystem. +This package provides functions for statistical testing for +`SummarizedExperiment` objects. **Available methods:** diff --git a/man/getAnova.Rd b/man/getAnova.Rd index e088466..1e2a33c 100644 --- a/man/getAnova.Rd +++ b/man/getAnova.Rd @@ -4,10 +4,10 @@ \alias{getAnova} \title{Perform ANOVA} \usage{ -getAnova(tse, formula, ...) +getAnova(x, formula, ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the variable to test (assay name, colData, or rowData variable) and the RHS specifies the diff --git a/man/getChisqTest.Rd b/man/getChisqTest.Rd index fffb17b..4a9596c 100644 --- a/man/getChisqTest.Rd +++ b/man/getChisqTest.Rd @@ -4,10 +4,10 @@ \alias{getChisqTest} \title{Perform chi-square test} \usage{ -getChisqTest(tse, formula, detection = 0, p.adjust.method = "BH", ...) +getChisqTest(x, formula, detection = 0, p.adjust.method = "BH", ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the variable to test (assay name, colData, or rowData variable) and the RHS specifies the diff --git a/man/getCorrelationTest.Rd b/man/getCorrelationTest.Rd index c81671f..627b535 100644 --- a/man/getCorrelationTest.Rd +++ b/man/getCorrelationTest.Rd @@ -4,17 +4,10 @@ \alias{getCorrelationTest} \title{Perform correlation test} \usage{ -getCorrelationTest( - tse, - formula, - method = c("spearman", "pearson", "kendall"), - adjust.by = NULL, - p.adjust.method = "BH", - ... -) +getCorrelationTest(x, formula, method = c("spearman", "pearson", "kendall"), adjust.by = NULL, p.adjust.method = "BH", ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the variable to test (assay name, colData, or rowData variable) and the RHS specifies the diff --git a/man/getDunnTest.Rd b/man/getDunnTest.Rd index 4ff0d35..eed779a 100644 --- a/man/getDunnTest.Rd +++ b/man/getDunnTest.Rd @@ -4,10 +4,10 @@ \alias{getDunnTest} \title{Perform Dunn's post-hoc test} \usage{ -getDunnTest(tse, formula, ...) +getDunnTest(x, formula, ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the variable to test (assay name, colData, or rowData variable) and the RHS specifies the diff --git a/man/getEffectSize.Rd b/man/getEffectSize.Rd index 933b108..2c50f90 100644 --- a/man/getEffectSize.Rd +++ b/man/getEffectSize.Rd @@ -4,16 +4,10 @@ \alias{getEffectSize} \title{Calculate effect sizes between groups} \usage{ -getEffectSize( - tse, - formula, - method = c("cliff", "cohen", "difference", "ratio", "log_ratio"), - pair.by = NULL, - ... -) +getEffectSize(x, formula, method = c("cliff", "cohen", "difference", "ratio", "log_ratio"), pair.by = NULL, ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the variable to test (assay name, colData, or rowData variable) and the RHS specifies the diff --git a/man/getFirth.Rd b/man/getFirth.Rd index 8f484f8..8becf98 100644 --- a/man/getFirth.Rd +++ b/man/getFirth.Rd @@ -4,10 +4,10 @@ \alias{getFirth} \title{Fit Firth logistic regression per feature} \usage{ -getFirth(tse, formula, p_adjust_method = "BH", ...) +getFirth(x, formula, p_adjust_method = "BH", ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the assay or colData variable (must be binary/presence-absence) and the RHS specifies variables diff --git a/man/getFisherTest.Rd b/man/getFisherTest.Rd index bc47d38..799b206 100644 --- a/man/getFisherTest.Rd +++ b/man/getFisherTest.Rd @@ -4,10 +4,10 @@ \alias{getFisherTest} \title{Perform Fisher's exact test} \usage{ -getFisherTest(tse, formula, detection = 0, p.adjust.method = "BH", ...) +getFisherTest(x, formula, detection = 0, p.adjust.method = "BH", ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the variable to test (assay name, colData, or rowData variable) and the RHS specifies the diff --git a/man/getFriedmanTest.Rd b/man/getFriedmanTest.Rd index 7517f6b..2443833 100644 --- a/man/getFriedmanTest.Rd +++ b/man/getFriedmanTest.Rd @@ -4,10 +4,10 @@ \alias{getFriedmanTest} \title{Perform Friedman test} \usage{ -getFriedmanTest(tse, formula, pair.by, ...) +getFriedmanTest(x, formula, pair.by, ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the variable to test (assay name, colData, or rowData variable) and the RHS specifies the diff --git a/man/getGlm.Rd b/man/getGlm.Rd index 0363c3d..f1b81cc 100644 --- a/man/getGlm.Rd +++ b/man/getGlm.Rd @@ -4,17 +4,10 @@ \alias{getGlm} \title{Fit generalized linear model per feature} \usage{ -getGlm( - tse, - formula, - family = poisson(), - offset = NULL, - p_adjust_method = "BH", - ... -) +getGlm(x, formula, family = poisson(), offset = NULL, p_adjust_method = "BH", ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the assay or colData variable and the RHS specifies variables from \code{colData(tse)}, diff --git a/man/getKruskal.Rd b/man/getKruskal.Rd index 7bc066f..67715bc 100644 --- a/man/getKruskal.Rd +++ b/man/getKruskal.Rd @@ -4,10 +4,10 @@ \alias{getKruskal} \title{Perform Kruskal-Wallis test} \usage{ -getKruskal(tse, formula, ...) +getKruskal(x, formula, ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the variable to test (assay name, colData, or rowData variable) and the RHS specifies the diff --git a/man/getLeveneTest.Rd b/man/getLeveneTest.Rd index 43520d1..7b17d6b 100644 --- a/man/getLeveneTest.Rd +++ b/man/getLeveneTest.Rd @@ -4,10 +4,10 @@ \alias{getLeveneTest} \title{Perform Levene's test} \usage{ -getLeveneTest(tse, formula, ...) +getLeveneTest(x, formula, ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the variable to test (assay name, colData, or rowData variable) and the RHS specifies the diff --git a/man/getLimma.Rd b/man/getLimma.Rd index e66326b..076a3ff 100644 --- a/man/getLimma.Rd +++ b/man/getLimma.Rd @@ -4,10 +4,10 @@ \alias{getLimma} \title{Fit limma model} \usage{ -getLimma(tse, formula, ...) +getLimma(x, formula, ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the assay or colData variable and the RHS specifies variables from \code{colData(tse)}, diff --git a/man/getLm.Rd b/man/getLm.Rd index e90beeb..d03a2ed 100644 --- a/man/getLm.Rd +++ b/man/getLm.Rd @@ -4,10 +4,10 @@ \alias{getLm} \title{Fit linear model per feature} \usage{ -getLm(tse, formula, p_adjust_method = "BH", ...) +getLm(x, formula, p_adjust_method = "BH", ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the assay or colData variable and the RHS specifies variables from \code{colData(tse)}, diff --git a/man/getOrm.Rd b/man/getOrm.Rd index 60012ef..ff51ee5 100644 --- a/man/getOrm.Rd +++ b/man/getOrm.Rd @@ -4,10 +4,10 @@ \alias{getOrm} \title{Fit ordinal regression model per feature} \usage{ -getOrm(tse, formula, p_adjust_method = "BH", ...) +getOrm(x, formula, p_adjust_method = "BH", ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the assay or colData variable and the RHS specifies variables from \code{colData(tse)}, diff --git a/man/getPermanova.Rd b/man/getPermanova.Rd index 4100449..86f69d0 100644 --- a/man/getPermanova.Rd +++ b/man/getPermanova.Rd @@ -4,19 +4,10 @@ \alias{getPermanova} \title{Perform PERMANOVA} \usage{ -getPermanova( - tse, - formula, - pairwise = FALSE, - method = "bray", - permutations = 999L, - p.adjust.method = "BH", - pair.by = NULL, - ... -) +getPermanova(x, formula, pairwise = FALSE, method = "bray", permutations = 999L, p.adjust.method = "BH", pair.by = NULL, ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the assay name and the RHS specifies the grouping variable from \code{colData}, e.g., diff --git a/man/getPermdisp.Rd b/man/getPermdisp.Rd index 68d756a..9dd4d0d 100644 --- a/man/getPermdisp.Rd +++ b/man/getPermdisp.Rd @@ -4,10 +4,10 @@ \alias{getPermdisp} \title{Perform test for homogeneity of multivariate dispersions} \usage{ -getPermdisp(tse, formula, method = "bray", permutations = 999L, ...) +getPermdisp(x, formula, method = "bray", permutations = 999L, ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the assay name and the RHS specifies the grouping variable from \code{colData}, e.g., diff --git a/man/getShapiroTest.Rd b/man/getShapiroTest.Rd index 3162829..21fb257 100644 --- a/man/getShapiroTest.Rd +++ b/man/getShapiroTest.Rd @@ -4,10 +4,10 @@ \alias{getShapiroTest} \title{Perform Shapiro-Wilk test on residuals} \usage{ -getShapiroTest(tse, formula, p.adjust.method = "BH") +getShapiroTest(x, formula, p.adjust.method = "BH") } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the variable to test (assay name or colData variable) and the RHS specifies variables from diff --git a/man/getTTest.Rd b/man/getTTest.Rd index f6f4454..825668d 100644 --- a/man/getTTest.Rd +++ b/man/getTTest.Rd @@ -4,10 +4,10 @@ \alias{getTTest} \title{Perform t-test} \usage{ -getTTest(tse, formula, pair.by = NULL, ...) +getTTest(x, formula, pair.by = NULL, ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the variable to test (assay name, colData, or rowData variable) and the RHS specifies the diff --git a/man/getTukeyTest.Rd b/man/getTukeyTest.Rd index 08ecd54..c354742 100644 --- a/man/getTukeyTest.Rd +++ b/man/getTukeyTest.Rd @@ -4,10 +4,10 @@ \alias{getTukeyTest} \title{Perform Tukey's HSD post-hoc test} \usage{ -getTukeyTest(tse, formula, ...) +getTukeyTest(x, formula, ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the variable to test (assay name, colData, or rowData variable) and the RHS specifies the diff --git a/man/getWilcoxonTest.Rd b/man/getWilcoxonTest.Rd index 1261a5d..66b0bf4 100644 --- a/man/getWilcoxonTest.Rd +++ b/man/getWilcoxonTest.Rd @@ -4,10 +4,10 @@ \alias{getWilcoxonTest} \title{Perform Wilcoxon rank-sum test} \usage{ -getWilcoxonTest(tse, formula, pair.by = NULL, ...) +getWilcoxonTest(x, formula, pair.by = NULL, ...) } \arguments{ -\item{tse}{A \code{SummarizedExperiment} object.} +\item{x}{A \code{SummarizedExperiment} object.} \item{formula}{A formula where the LHS specifies the variable to test (assay name, colData, or rowData variable) and the RHS specifies the diff --git a/vignettes/daa.Rmd b/vignettes/daa.Rmd index 630a3f7..743d2cd 100644 --- a/vignettes/daa.Rmd +++ b/vignettes/daa.Rmd @@ -19,9 +19,8 @@ knitr::opts_chunk$set( # Introduction -The **daa** package provides methods for differential abundance analysis (DAA) -of microbiome data. It works with `TreeSummarizedExperiment` and -`SummarizedExperiment` objects from the miaverse ecosystem. +The **daa** package provides methods for statistical testing for +`SummarizedExperiment`. ## Installation From d59d3c046b795a467f5e4797a304305cf1cc9a89 Mon Sep 17 00:00:00 2001 From: TuomasBorman Date: Tue, 1 Dec 2026 19:59:43 +0000 Subject: [PATCH 2/2] Style code (GHA) --- R/AllGenerics.R | 18 +++++++++++++----- R/getCorrelationTest.R | 2 +- R/getEffectSize.R | 4 ++-- R/getGlm.R | 2 +- R/getPermanova.R | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/R/AllGenerics.R b/R/AllGenerics.R index 4d29ce4..e5f6e6b 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -14,7 +14,9 @@ getChisqTest <- S7::new_generic( getCorrelationTest <- S7::new_generic( "getCorrelationTest", "x", function(x, formula, method = c("spearman", "pearson", "kendall"), - adjust.by = NULL, p.adjust.method = "BH", ...) S7::S7_dispatch() + adjust.by = NULL, p.adjust.method = "BH", ...) { + S7::S7_dispatch() + } ) #' @export @@ -27,8 +29,10 @@ getDunnTest <- S7::new_generic( getEffectSize <- S7::new_generic( "getEffectSize", "x", function(x, formula, - method = c("cliff", "cohen", "difference", "ratio", "log_ratio"), - pair.by = NULL, ...) S7::S7_dispatch() + method = c("cliff", "cohen", "difference", "ratio", "log_ratio"), + pair.by = NULL, ...) { + S7::S7_dispatch() + } ) #' @export @@ -53,7 +57,9 @@ getFriedmanTest <- S7::new_generic( getGlm <- S7::new_generic( "getGlm", "x", function(x, formula, family = poisson(), offset = NULL, - p_adjust_method = "BH", ...) S7::S7_dispatch() + p_adjust_method = "BH", ...) { + S7::S7_dispatch() + } ) #' @export @@ -90,7 +96,9 @@ getOrm <- S7::new_generic( getPermanova <- S7::new_generic( "getPermanova", "x", function(x, formula, pairwise = FALSE, method = "bray", permutations = 999L, - p.adjust.method = "BH", pair.by = NULL, ...) S7::S7_dispatch() + p.adjust.method = "BH", pair.by = NULL, ...) { + S7::S7_dispatch() + } ) #' @export diff --git a/R/getCorrelationTest.R b/R/getCorrelationTest.R index 4b0659b..337f490 100644 --- a/R/getCorrelationTest.R +++ b/R/getCorrelationTest.R @@ -56,7 +56,7 @@ #' @name getCorrelationTest #' @usage getCorrelationTest(x, formula, method = c("spearman", "pearson", "kendall"), adjust.by = NULL, p.adjust.method = "BH", ...) S7::method(getCorrelationTest, methods::getClass("SummarizedExperiment")) <- function(x, formula, method = c("spearman", "pearson", "kendall"), - adjust.by = NULL, p.adjust.method = "BH", ...) { + adjust.by = NULL, p.adjust.method = "BH", ...) { if (length(all.vars(formula[[3]])) != 1L) { stop("Formula RHS must specify exactly one numeric variable.", call. = FALSE diff --git a/R/getEffectSize.R b/R/getEffectSize.R index d0a1b34..a04de3b 100644 --- a/R/getEffectSize.R +++ b/R/getEffectSize.R @@ -62,8 +62,8 @@ #' @name getEffectSize #' @usage getEffectSize(x, formula, method = c("cliff", "cohen", "difference", "ratio", "log_ratio"), pair.by = NULL, ...) S7::method(getEffectSize, methods::getClass("SummarizedExperiment")) <- function(x, formula, - method = c("cliff", "cohen", "difference", "ratio", "log_ratio"), - pair.by = NULL, ...) { + method = c("cliff", "cohen", "difference", "ratio", "log_ratio"), + pair.by = NULL, ...) { if (length(all.vars(formula[[3]])) != 1L) { stop("Formula RHS must specify exactly one grouping variable.", call. = FALSE diff --git a/R/getGlm.R b/R/getGlm.R index b123c03..1c0fd9b 100644 --- a/R/getGlm.R +++ b/R/getGlm.R @@ -67,7 +67,7 @@ #' @usage getGlm(x, formula, family = poisson(), offset = NULL, p_adjust_method = "BH", ...) #' @importFrom stats poisson S7::method(getGlm, methods::getClass("SummarizedExperiment")) <- function(x, formula, family = poisson(), offset = NULL, - p_adjust_method = "BH", ...) { + p_adjust_method = "BH", ...) { data_list <- .get_wide_data(x, formula) offset_values <- .get_offset(x, offset) res <- .train_model_per_feature( diff --git a/R/getPermanova.R b/R/getPermanova.R index 45e2b6c..b715930 100644 --- a/R/getPermanova.R +++ b/R/getPermanova.R @@ -60,7 +60,7 @@ #' @name getPermanova #' @usage getPermanova(x, formula, pairwise = FALSE, method = "bray", permutations = 999L, p.adjust.method = "BH", pair.by = NULL, ...) S7::method(getPermanova, methods::getClass("SummarizedExperiment")) <- function(x, formula, pairwise = FALSE, method = "bray", permutations = 999L, - p.adjust.method = "BH", pair.by = NULL, ...) { + p.adjust.method = "BH", pair.by = NULL, ...) { if (length(all.vars(formula[[3]])) != 1L) { stop("Formula RHS must specify exactly one grouping variable.", call. = FALSE