Skip to content

Commit

Permalink
🚧 document ANOVA vs pairwise-ttest results
Browse files Browse the repository at this point in the history
  • Loading branch information
enryH committed Feb 20, 2025
1 parent 995ce24 commit 682671e
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 30 deletions.
128 changes: 104 additions & 24 deletions docs/api_examples/ANCOVA_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"For easier inspection we just sample five protein groups. Remove this step in a\n",
"For easier inspection we just sample 100 protein groups. Remove this step in a\n",
"real analysis."
]
},
Expand All @@ -171,7 +171,7 @@
"metadata": {},
"outputs": [],
"source": [
"omics = omics.sample(5, axis=1, random_state=42)\n",
"omics = omics.sample(100, axis=1, random_state=42)\n",
"omics"
]
},
Expand Down Expand Up @@ -403,8 +403,17 @@
"metadata": {},
"source": [
"The first columns contain group averages for each group for the specific\n",
"protein group\n",
"ancova.iloc[:, :6]"
"protein group"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2653ab02",
"metadata": {},
"outputs": [],
"source": [
"# ancova.iloc[:, :6]"
]
},
{
Expand Down Expand Up @@ -480,6 +489,34 @@
"anova"
]
},
{
"cell_type": "markdown",
"id": "89b1ab90",
"metadata": {},
"source": [
"Set subject to None"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "92cc96ee",
"metadata": {},
"outputs": [],
"source": [
"anova = (\n",
" ad.run_anova(\n",
" omics_and_clinic,\n",
" subject=None,\n",
" drop_cols=covariates,\n",
" group=\"AD\",\n",
" )\n",
" .set_index(\"identifier\")\n",
" .sort_values(by=\"padj\")\n",
")\n",
"anova"
]
},
{
"cell_type": "markdown",
"id": "28434ecb",
Expand Down Expand Up @@ -589,19 +626,7 @@
"metadata": {},
"source": [
"# With three and more groups\n",
"Acore make each combinatorial comparison between groups in the group column.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "33105f5d",
"metadata": {},
"outputs": [],
"source": [
"import math\n",
"\n",
"math.comb(4, 2)"
"Acore make each combinatorial comparison between groups in the group column."
]
},
{
Expand Down Expand Up @@ -635,10 +660,10 @@
{
"cell_type": "markdown",
"id": "55a88fd4",
"metadata": {
"lines_to_next_cell": 0
},
"source": []
"metadata": {},
"source": [
"Sample five protein groups (for easier inspection) and combine with metadata."
]
},
{
"cell_type": "code",
Expand All @@ -647,7 +672,7 @@
"metadata": {},
"outputs": [],
"source": [
"omics_and_clinic = omics.join(meta)\n",
"omics_and_clinic = omics.sample(5, axis=1, random_state=42).join(meta)\n",
"omics_and_clinic"
]
},
Expand All @@ -664,13 +689,68 @@
" subject=\"Sample ID\",\n",
" drop_cols=[\"age\", \"gender\"],\n",
" group=\"site\",\n",
" )\n",
" .set_index([\"identifier\", \"group1\", \"group2\"])\n",
" ).set_index([\"identifier\", \"group1\", \"group2\"])\n",
" # .sort_values(by=\"padj\")\n",
")\n",
"anova"
]
},
{
"cell_type": "markdown",
"id": "ce0bfc17",
"metadata": {},
"source": [
"pairwise t-test results:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "719f895f",
"metadata": {},
"outputs": [],
"source": [
"cols_pairwise_ttest = [\n",
" # \"group1\",\n",
" # \"group2\",\n",
" \"mean(group1)\",\n",
" \"std(group1)\",\n",
" \"mean(group2)\",\n",
" \"std(group2)\",\n",
" \"posthoc Paired\",\n",
" \"posthoc Parametric\",\n",
" \"posthoc T-Statistics\",\n",
" \"posthoc dof\",\n",
" \"posthoc tail\",\n",
" \"posthoc pvalue\",\n",
" \"posthoc BF10\",\n",
" \"posthoc effsize\",\n",
" # \"identifier\",\n",
" \"log2FC\",\n",
" \"FC\",\n",
" \"efftype\",\n",
"]\n",
"anova[cols_pairwise_ttest]"
]
},
{
"cell_type": "markdown",
"id": "d041469a",
"metadata": {},
"source": [
"ANOVA results"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "57513226",
"metadata": {},
"outputs": [],
"source": [
"anova.drop(columns=cols_pairwise_ttest)"
]
},
{
"cell_type": "markdown",
"id": "c7eed4d2",
Expand Down
56 changes: 50 additions & 6 deletions docs/api_examples/ANCOVA_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@
# %% [markdown]
# The first columns contain group averages for each group for the specific
# protein group

# %%
# ancova.iloc[:, :6]

# %% [markdown]
Expand Down Expand Up @@ -225,6 +227,22 @@
)
anova

# %% [markdown]
# Set subject to None

# %%
anova = (
ad.run_anova(
omics_and_clinic,
subject=None,
drop_cols=covariates,
group="AD",
)
.set_index("identifier")
.sort_values(by="padj")
)
anova

# %% [markdown]
# view averages per protein group

Expand Down Expand Up @@ -265,12 +283,6 @@
# %% [markdown]
# # With three and more groups
# Acore make each combinatorial comparison between groups in the group column.
#

# %%
import math

math.comb(4, 2)

# %%
CLINIC: str = "meta.csv" # clincial data
Expand Down Expand Up @@ -312,6 +324,38 @@
)
anova

# %% [markdown]
# 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]

# %% [markdown]
# ANOVA results

# %%
anova.drop(columns=cols_pairwise_ttest)

# %% [markdown]
# Test results

Expand Down

0 comments on commit 682671e

Please sign in to comment.