-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreefactors.Rd
161 lines (136 loc) · 6.01 KB
/
threefactors.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/iDAS_functions.R
\name{threefactors}
\alias{threefactors}
\title{iDAS: Interpretable Differential Analysis of Genes Using Three Factors}
\usage{
threefactors(
Z,
factor1,
factor2,
factor3,
random_effect = NULL,
model_fit_function = "lm",
test_function = "anova_test",
pval_quantile_cutoff = 0.02,
pval_cutoff_full = 0.05,
pval_cutoff_interaction = 0.01,
pval_cutoff_factor1 = 0.01,
pval_cutoff_factor2 = 0.01,
pval_cutoff_factor3 = 0.01,
pval_cutoff_int12 = 0.01,
pval_cutoff_int13 = 0.01,
pval_cutoff_int23 = 0.01,
pval_cutoff_int123 = 0.01,
p_adjust_method = "BH",
factor1_name = NULL,
factor2_name = NULL,
factor3_name = NULL,
random_effect_name = NULL,
...
)
}
\arguments{
\item{Z}{A numeric matrix or data frame where each column represents a gene's expression (or abundance)
and each row corresponds to an observation (e.g., a sample).}
\item{factor1}{A factor or vector representing the primary experimental factor.}
\item{factor2}{A factor or vector representing the secondary experimental factor.}
\item{factor3}{A factor or vector representing the tertiary experimental factor.}
\item{random_effect}{An optional factor or vector for random effects (e.g., subject ID). Use \code{NULL}
if no random effects are included.}
\item{model_fit_function}{A character string specifying the model-fitting function (e.g., \code{"lm"}
for linear models, \code{"lmer"} for mixed-effects models). Default is \code{"lm"}.}
\item{test_function}{A character string specifying the testing function to use
(e.g., \code{"anova_test"}). Default is \code{"anova_test"}.}
\item{pval_quantile_cutoff}{A numeric threshold for the quantile-based filtering of overall p-values
(i.e., only genes with overall p-values below the specified quantile are considered for further tests).
Default is \code{0.02}.}
\item{pval_cutoff_full}{A numeric p-value cutoff for the overall model test. Default is \code{0.05}.}
\item{pval_cutoff_interaction}{A numeric p-value cutoff for the omnibus interaction test (i.e., is there
\emph{any} interaction?). Default is \code{0.01}.}
\item{pval_cutoff_factor1}{A numeric p-value cutoff for testing the main effect of \code{factor1}.
Default is \code{0.01}.}
\item{pval_cutoff_factor2}{A numeric p-value cutoff for testing the main effect of \code{factor2}.
Default is \code{0.01}.}
\item{pval_cutoff_factor3}{A numeric p-value cutoff for testing the main effect of \code{factor3}.
Default is \code{0.01}.}
\item{pval_cutoff_int12}{A numeric p-value cutoff for the two-way interaction between \code{factor1}
and \code{factor2}. Default is \code{0.01}.}
\item{pval_cutoff_int13}{A numeric p-value cutoff for the two-way interaction between \code{factor1}
and \code{factor3}. Default is \code{0.01}.}
\item{pval_cutoff_int23}{A numeric p-value cutoff for the two-way interaction between \code{factor2}
and \code{factor3}. Default is \code{0.01}.}
\item{pval_cutoff_int123}{A numeric p-value cutoff for the three-way interaction among \code{factor1},
\code{factor2}, and \code{factor3}. Default is \code{0.01}.}
\item{p_adjust_method}{A character string specifying the method used to adjust p-values for multiple
comparisons (e.g., \code{"BH"}). Default is \code{"BH"}.}
\item{factor1_name}{An optional character string to label \code{factor1} in outputs or formulas.
Default is \code{NULL}.}
\item{factor2_name}{An optional character string to label \code{factor2} in outputs or formulas.
Default is \code{NULL}.}
\item{factor3_name}{An optional character string to label \code{factor3} in outputs or formulas.
Default is \code{NULL}.}
\item{random_effect_name}{An optional character string to label the random effect in outputs or formulas.
Default is \code{NULL}.}
\item{\dots}{Additional arguments passed to internal functions, model-fitting routines, or test functions.}
}
\value{
A list containing:
\describe{
\item{\code{pval_matrix}}{A matrix of adjusted p-values for each gene, including main effects and
interactions.}
\item{\code{stat_matrix}}{A matrix of corresponding test statistics.}
\item{\code{class_df}}{A data frame classifying each gene based on the significance of main effects
and interactions.}
}
}
\description{
This function implements the iDAS (Interpretable Differential Analysis Signature) framework to identify genes
associated with three experimental factors (\code{factor1}, \code{factor2}, and \code{factor3}), as well as
their interactions. The analysis involves an overall model test, interaction tests (two-way and three-way),
and main effects tests. Results include adjusted p-values and test statistics for each gene.
}
\details{
Internally, the function:
\enumerate{
\item Builds the appropriate model formulas for each gene, depending on \code{model_fit_function}
(e.g., \code{lm} vs. \code{lmer}) and whether \code{random_effect} is provided.
\item Performs an overall significance test for each gene (the \code{pval_cutoff_full} threshold).
\item For those genes passing the overall test, conducts an omnibus interaction test and further
specific tests (main effects or two-way/three-way interactions) controlled by the respective
p-value cutoffs.
}
Multiple testing corrections are applied based on \code{p_adjust_method}.
}
\examples{
\dontrun{
# Generate sample data
set.seed(123)
Z <- matrix(rnorm(1000), ncol = 10)
colnames(Z)=paste0("gene",1:10)
factor1 <- as.factor(rep(1:2, each = 5))
factor2 <- as.factor(rep(1:2, times = 5))
factor3 <- as.factor(rep(1:2, length.out = 10))
# Run the differential analysis using iDAS
result <- threefactors(
Z, factor1, factor2, factor3,
model_fit_function = "lm",
test_function = "anova_test",
pval_quantile_cutoff = 0.02,
pval_cutoff_full = 0.05,
pval_cutoff_interaction = 0.01,
pval_cutoff_factor1 = 0.01,
pval_cutoff_factor2 = 0.01,
pval_cutoff_factor3 = 0.01,
pval_cutoff_int12 = 0.01,
pval_cutoff_int13 = 0.01,
pval_cutoff_int23 = 0.01,
pval_cutoff_int123 = 0.01,
p_adjust_method = "BH"
)
# Inspect results
head(result$pval_matrix)
head(result$stat_matrix)
head(result$class_df)
}
}