Differential regulation: ANOVA across more than two groups and posthoc t-tests#
This API example shows the functionality in the
acore.differential_regulation module:
Analysis of Variance (ANOVA) as omnibus test across more than two groups
posthoc t-tests between each of the groups
An omnibus analysis across groups is combined with posthoc analysis between each set of the separate groups.
The function is the same as for the two groups case. The group1 and
group2 columns give the posthoc comparison.
%pip install acore
BASE = (
"https://raw.githubusercontent.com/Multiomics-Analytics-Group/acore/"
"main/example_data/MTBLS13311/"
)
fname: str = "MTBLS13411_omics_and_meta.csv" # combined omics and meta data
covariates: list[str] = []
group: str = "group"
drop_cols: list[str] = ["Factor Value[Strain type]"]
subject_col: str | int = 0
factor_and_covars: list[str] = [group, *covariates]
ANOVA analysis for two groups#
Use combined dataset for ANOVA analysis.
| Factor Value[Strain type] | group | Uracil | Adenine | ... | Fructose 1,6-bisphosphate | Arginine | Ornithine | Lysine | |
|---|---|---|---|---|---|---|---|---|---|
| rapZE227Stop-1 | phage-resistant | rapZE227Stop | 26.271 | 21.874 | ... | 20.164 | 23.718 | 25.082 | 22.330 |
| rapZE227Stop-2 | phage-resistant | rapZE227Stop | 27.293 | 21.983 | ... | 20.355 | 23.611 | 25.016 | 21.867 |
| rapZE227Stop-3 | phage-resistant | rapZE227Stop | 26.788 | 21.833 | ... | 20.331 | 23.834 | 25.158 | 21.729 |
| rapZE227Stop-4 | phage-resistant | rapZE227Stop | 27.014 | 22.120 | ... | 20.545 | 23.634 | 24.943 | 21.525 |
| rapZE227Stop-5 | phage-resistant | rapZE227Stop | 26.364 | 21.957 | ... | 20.208 | 23.971 | 25.206 | 22.180 |
| rapZE227Stop-6 | phage-resistant | rapZE227Stop | 26.571 | 21.885 | ... | 20.324 | 23.917 | 25.163 | 21.768 |
| WT-1 | Wild Type | WT | 26.472 | 21.826 | ... | 20.368 | 24.265 | 25.163 | 21.638 |
| WT-2 | Wild Type | WT | 26.325 | 21.652 | ... | 20.385 | 24.175 | 25.260 | 21.040 |
| WT-3 | Wild Type | WT | 26.274 | 21.651 | ... | 20.407 | 24.244 | 25.090 | 21.393 |
| WT-4 | Wild Type | WT | 26.187 | 21.780 | ... | 20.605 | 24.218 | 25.216 | 21.399 |
| WT-5 | Wild Type | WT | 26.244 | 21.702 | ... | 20.392 | 24.384 | 25.164 | 21.348 |
| WT-6 | Wild Type | WT | 26.313 | 21.770 | ... | 20.455 | 24.136 | 25.156 | 21.379 |
| WRP-1 | phage-resistant | WRP | 26.301 | 22.169 | ... | 20.205 | 23.923 | 25.111 | 21.752 |
| WRP-2 | phage-resistant | WRP | 25.721 | 21.546 | ... | 20.523 | 23.822 | 24.924 | 21.126 |
| WRP-3 | phage-resistant | WRP | 26.929 | 21.612 | ... | 20.513 | 23.828 | 24.917 | 21.084 |
| WRP-4 | phage-resistant | WRP | 26.265 | 21.738 | ... | 20.533 | 23.843 | 24.988 | 21.132 |
| WRP-5 | phage-resistant | WRP | 26.279 | 21.596 | ... | 20.555 | 23.871 | 25.063 | 21.508 |
| WRP-6 | phage-resistant | WRP | 26.550 | 21.626 | ... | 20.514 | 23.927 | 25.011 | 21.180 |
| QC-1 | <NA> | QC | 26.321 | 21.572 | ... | 20.339 | 24.129 | 25.139 | 21.544 |
| QC-2 | <NA> | QC | 26.289 | 21.511 | ... | 20.324 | 24.052 | 25.049 | 21.564 |
| QC-3 | <NA> | QC | 26.287 | 21.556 | ... | 20.331 | 24.066 | 25.097 | 21.513 |
21 rows × 61 columns
Drop unnecessary columns, if there are any specified in drop_cols.
| group | Uracil | Adenine | Hypoxanthine | ... | Fructose 1,6-bisphosphate | Arginine | Ornithine | Lysine | |
|---|---|---|---|---|---|---|---|---|---|
| rapZE227Stop-1 | rapZE227Stop | 26.271 | 21.874 | 23.201 | ... | 20.164 | 23.718 | 25.082 | 22.330 |
| rapZE227Stop-2 | rapZE227Stop | 27.293 | 21.983 | 23.357 | ... | 20.355 | 23.611 | 25.016 | 21.867 |
| rapZE227Stop-3 | rapZE227Stop | 26.788 | 21.833 | 23.167 | ... | 20.331 | 23.834 | 25.158 | 21.729 |
| rapZE227Stop-4 | rapZE227Stop | 27.014 | 22.120 | 23.517 | ... | 20.545 | 23.634 | 24.943 | 21.525 |
| rapZE227Stop-5 | rapZE227Stop | 26.364 | 21.957 | 23.246 | ... | 20.208 | 23.971 | 25.206 | 22.180 |
| rapZE227Stop-6 | rapZE227Stop | 26.571 | 21.885 | 23.121 | ... | 20.324 | 23.917 | 25.163 | 21.768 |
| WT-1 | WT | 26.472 | 21.826 | 22.980 | ... | 20.368 | 24.265 | 25.163 | 21.638 |
| WT-2 | WT | 26.325 | 21.652 | 22.925 | ... | 20.385 | 24.175 | 25.260 | 21.040 |
| WT-3 | WT | 26.274 | 21.651 | 22.885 | ... | 20.407 | 24.244 | 25.090 | 21.393 |
| WT-4 | WT | 26.187 | 21.780 | 22.938 | ... | 20.605 | 24.218 | 25.216 | 21.399 |
| WT-5 | WT | 26.244 | 21.702 | 22.945 | ... | 20.392 | 24.384 | 25.164 | 21.348 |
| WT-6 | WT | 26.313 | 21.770 | 22.851 | ... | 20.455 | 24.136 | 25.156 | 21.379 |
| WRP-1 | WRP | 26.301 | 22.169 | 23.295 | ... | 20.205 | 23.923 | 25.111 | 21.752 |
| WRP-2 | WRP | 25.721 | 21.546 | 22.771 | ... | 20.523 | 23.822 | 24.924 | 21.126 |
| WRP-3 | WRP | 26.929 | 21.612 | 22.696 | ... | 20.513 | 23.828 | 24.917 | 21.084 |
| WRP-4 | WRP | 26.265 | 21.738 | 22.881 | ... | 20.533 | 23.843 | 24.988 | 21.132 |
| WRP-5 | WRP | 26.279 | 21.596 | 22.861 | ... | 20.555 | 23.871 | 25.063 | 21.508 |
| WRP-6 | WRP | 26.550 | 21.626 | 22.849 | ... | 20.514 | 23.927 | 25.011 | 21.180 |
| QC-1 | QC | 26.321 | 21.572 | 22.779 | ... | 20.339 | 24.129 | 25.139 | 21.544 |
| QC-2 | QC | 26.289 | 21.511 | 22.681 | ... | 20.324 | 24.052 | 25.049 | 21.564 |
| QC-3 | QC | 26.287 | 21.556 | 22.732 | ... | 20.331 | 24.066 | 25.097 | 21.513 |
21 rows × 60 columns
Check data types of the columns. Metadata can be numeric, but also strings.
Float64 59
string[python] 1
Name: count, dtype: int64
| group | |
|---|---|
| rapZE227Stop-1 | rapZE227Stop |
| rapZE227Stop-2 | rapZE227Stop |
| rapZE227Stop-3 | rapZE227Stop |
| rapZE227Stop-4 | rapZE227Stop |
| rapZE227Stop-5 | rapZE227Stop |
| rapZE227Stop-6 | rapZE227Stop |
| WT-1 | WT |
| WT-2 | WT |
| WT-3 | WT |
| WT-4 | WT |
| WT-5 | WT |
| WT-6 | WT |
| WRP-1 | WRP |
| WRP-2 | WRP |
| WRP-3 | WRP |
| WRP-4 | WRP |
| WRP-5 | WRP |
| WRP-6 | WRP |
| QC-1 | QC |
| QC-2 | QC |
| QC-3 | QC |
With four groups#
Acore make each combinatorial comparison between groups in the group column.
if isinstance(subject_col, int):
subject_col = omics_and_meta.index.name
anova = (
ad.run_anova(
omics_and_meta, # .reset_index(),
subject=subject_col,
drop_cols=[],
group=group,
).set_index(["identifier", "group1", "group2"])
# .sort_values(by="padj")
)
anova.head().T
| identifier | Uracil | ||||
|---|---|---|---|---|---|
| group1 | QC | WRP | |||
| group2 | WRP | WT | rapZE227Stop | WT | rapZE227Stop |
| mean(group1) | 26.299 | 26.299 | 26.299 | 26.341 | 26.341 |
| std(group1) | 0.019 | 0.019 | 0.019 | 0.396 | 0.396 |
| mean(group2) | 26.341 | 26.302 | 26.717 | 26.302 | 26.717 |
| std(group2) | 0.396 | 0.097 | 0.393 | 0.097 | 0.393 |
| posthoc Paired | False | False | False | False | False |
| posthoc Parametric | True | True | True | True | True |
| posthoc T-Statistics | -0.256 | -0.076 | -2.599 | 0.231 | -1.651 |
| posthoc dof | 5.047 | 5.728 | 5.047 | 10.000 | 10.000 |
| posthoc tail | two-sided | two-sided | two-sided | two-sided | two-sided |
| posthoc pvalue | 0.808 | 0.942 | 0.048 | 0.822 | 0.130 |
| posthoc BF10 | 0.534 | 0.524 | 2.287 | 0.475 | 1.041 |
| posthoc effsize | -0.110 | -0.034 | -1.118 | 0.123 | -0.880 |
| log2FC | -0.042 | -0.003 | -0.418 | 0.038 | -0.376 |
| FC | 0.972 | 0.998 | 0.749 | 1.027 | 0.771 |
| efftype | hedges | hedges | hedges | hedges | hedges |
| F-statistics | 2.441 | 2.441 | 2.441 | 2.441 | 2.441 |
| pvalue | 0.100 | 0.100 | 0.100 | 0.100 | 0.100 |
| padj | 0.123 | 0.123 | 0.123 | 0.123 | 0.123 |
| correction | FDR correction BH | FDR correction BH | FDR correction BH | FDR correction BH | FDR correction BH |
| rejected | False | False | False | False | False |
| -log10 pvalue | 0.093 | 0.026 | 1.320 | 0.085 | 0.887 |
| Method | One-way anova | One-way anova | One-way anova | One-way anova | One-way anova |
| posthoc padj | 0.860 | 0.958 | 0.110 | 0.836 | 0.219 |
pairwise t-test results:#
cols_pairwise_ttest = [
# "group1",
# "group2",
"mean(group1)",
"std(group1)",
"mean(group2)",
"std(group2)",
"posthoc Paired",
"posthoc Parametric",
"posthoc T-Statistics",
"posthoc dof",
"posthoc tail",
"posthoc pvalue",
"posthoc BF10",
"posthoc effsize",
# "identifier",
"log2FC",
"FC",
"efftype",
]
anova[cols_pairwise_ttest]
| mean(group1) | std(group1) | mean(group2) | std(group2) | ... | posthoc effsize | log2FC | FC | efftype | |||
|---|---|---|---|---|---|---|---|---|---|---|---|
| identifier | group1 | group2 | |||||||||
| Uracil | QC | WRP | 26.299 | 0.019 | 26.341 | 0.396 | ... | -0.110 | -0.042 | 0.972 | hedges |
| WT | 26.299 | 0.019 | 26.302 | 0.097 | ... | -0.034 | -0.003 | 0.998 | hedges | ||
| rapZE227Stop | 26.299 | 0.019 | 26.717 | 0.393 | ... | -1.118 | -0.418 | 0.749 | hedges | ||
| WRP | WT | 26.341 | 0.396 | 26.302 | 0.097 | ... | 0.123 | 0.038 | 1.027 | hedges | |
| rapZE227Stop | 26.341 | 0.396 | 26.717 | 0.393 | ... | -0.880 | -0.376 | 0.771 | hedges | ||
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| Lysine | QC | WT | 21.540 | 0.025 | 21.366 | 0.191 | ... | 0.957 | 0.175 | 1.129 | hedges |
| rapZE227Stop | 21.540 | 0.025 | 21.900 | 0.301 | ... | -1.256 | -0.359 | 0.779 | hedges | ||
| WRP | WT | 21.297 | 0.271 | 21.366 | 0.191 | ... | -0.271 | -0.069 | 0.953 | hedges | |
| rapZE227Stop | 21.297 | 0.271 | 21.900 | 0.301 | ... | -1.945 | -0.603 | 0.658 | hedges | ||
| WT | rapZE227Stop | 21.366 | 0.191 | 21.900 | 0.301 | ... | -1.957 | -0.534 | 0.691 | hedges |
354 rows × 15 columns
ANOVA results
anova.drop(columns=cols_pairwise_ttest)
| F-statistics | pvalue | padj | correction | rejected | -log10 pvalue | Method | posthoc padj | |||
|---|---|---|---|---|---|---|---|---|---|---|
| identifier | group1 | group2 | ||||||||
| Uracil | QC | WRP | 2.441 | 0.100 | 0.123 | FDR correction BH | False | 0.093 | One-way anova | 0.860 |
| WT | 2.441 | 0.100 | 0.123 | FDR correction BH | False | 0.026 | One-way anova | 0.958 | ||
| rapZE227Stop | 2.441 | 0.100 | 0.123 | FDR correction BH | False | 1.320 | One-way anova | 0.110 | ||
| WRP | WT | 2.441 | 0.100 | 0.123 | FDR correction BH | False | 0.085 | One-way anova | 0.836 | |
| rapZE227Stop | 2.441 | 0.100 | 0.123 | FDR correction BH | False | 0.887 | One-way anova | 0.219 | ||
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| Lysine | QC | WT | 7.393 | 0.002 | 0.005 | FDR correction BH | True | 1.121 | One-way anova | 0.104 |
| rapZE227Stop | 7.393 | 0.002 | 0.005 | FDR correction BH | True | 1.490 | One-way anova | 0.083 | ||
| WRP | WT | 7.393 | 0.002 | 0.005 | FDR correction BH | True | 0.206 | One-way anova | 0.655 | |
| rapZE227Stop | 7.393 | 0.002 | 0.005 | FDR correction BH | True | 2.350 | One-way anova | 0.020 | ||
| WT | rapZE227Stop | 7.393 | 0.002 | 0.005 | FDR correction BH | True | 2.367 | One-way anova | 0.015 |
354 rows × 8 columns
Test results
| posthoc pvalue | log2FC | FC | F-statistics | pvalue | padj | rejected | -log10 pvalue | posthoc padj | |||
|---|---|---|---|---|---|---|---|---|---|---|---|
| identifier | group1 | group2 | |||||||||
| Uracil | QC | WRP | 0.808 | -0.042 | 0.972 | 2.441 | 0.100 | 0.123 | False | 0.093 | 0.860 |
| WT | 0.942 | -0.003 | 0.998 | 2.441 | 0.100 | 0.123 | False | 0.026 | 0.958 | ||
| rapZE227Stop | 0.048 | -0.418 | 0.749 | 2.441 | 0.100 | 0.123 | False | 1.320 | 0.110 | ||
| WRP | WT | 0.822 | 0.038 | 1.027 | 2.441 | 0.100 | 0.123 | False | 0.085 | 0.836 | |
| rapZE227Stop | 0.130 | -0.376 | 0.771 | 2.441 | 0.100 | 0.123 | False | 0.887 | 0.219 | ||
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| Lysine | QC | WT | 0.076 | 0.175 | 1.129 | 7.393 | 0.002 | 0.005 | True | 1.121 | 0.104 |
| rapZE227Stop | 0.032 | -0.359 | 0.779 | 7.393 | 0.002 | 0.005 | True | 1.490 | 0.083 | ||
| WRP | WT | 0.622 | -0.069 | 0.953 | 7.393 | 0.002 | 0.005 | True | 0.206 | 0.655 | |
| rapZE227Stop | 0.004 | -0.603 | 0.658 | 7.393 | 0.002 | 0.005 | True | 2.350 | 0.020 | ||
| WT | rapZE227Stop | 0.004 | -0.534 | 0.691 | 7.393 | 0.002 | 0.005 | True | 2.367 | 0.015 |
354 rows × 9 columns