Skip to contents

This function performs pairwise comparisons between two groups for each combination of a categorical predictor (with exactly two levels) and a continuous outcome variable. It first converts any character variables in data to factors and, if specified, applies a log2 transformation to the continuous variables. Depending on the value of scale, the function conducts either a two-sample t-test (if scale = "log2") or a Mann-Whitney U test (if scale is NULL). The resulting p-values are printed and returned.

Usage

cyt_ttest(data, scale = NULL, verbose = TRUE, format_output = FALSE)

Arguments

data

A matrix or data frame containing continuous and categorical variables.

scale

A character specifying a transformation for continuous variables. Options are NULL (default) and "log2". When scale = "log2", a log2 transformation is applied and a two-sample t-test is used; when scale is NULL, a Mann-Whitney U test is performed.

verbose

A logical indicating whether to print the p-values of the statistical tests. Default is TRUE.

format_output

Logical. If TRUE, returns the results as a tidy data frame. Default is FALSE.

Value

If format_output is FALSE, returns a list of p-values (named by Outcome and Categorical variable). If TRUE, returns a data frame in a tidy format.

Examples

data_df <- ExampleData1[, -c(3)]
data_df <- dplyr::filter(data_df, Group != "ND", Treatment != "Unstimulated")
# Two sample T-test with log2 transformation
cyt_ttest(data_df[, c(1, 2, 5:6)], scale = "log2", verbose = TRUE, format_output = TRUE)
#>   Outcome Categorical      Comparison P_value
#> 1   IFN.G       Group   PreT2D vs T2D  0.0208
#> 2   IL.10       Group   PreT2D vs T2D  0.0248
#> 3   IFN.G   Treatment CD3/CD28 vs LPS  0.0000
#> 4   IL.10   Treatment CD3/CD28 vs LPS  0.0001
# Mann-Whitney U Test without transformation
cyt_ttest(data_df[, c(1, 2, 5:6)], verbose = TRUE, format_output = FALSE)
#> $IFN.G_Group
#> [1] 0.0085
#> 
#> $IL.10_Group
#> [1] 0.0119
#> 
#> $IFN.G_Treatment
#> [1] 0
#> 
#> $IL.10_Treatment
#> [1] 0
#>