Skip to content
This repository was archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Cleaned up ANOVA alpha thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicasyu committed Apr 15, 2022
1 parent 92030ea commit 9261662
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions analysis/_/ANOVA_testing.json
Git LFS file not shown
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
numpy
tqdm
tqdm
pandas
16 changes: 8 additions & 8 deletions run_anova_tests.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,15 @@
" out = {}\n",
" \n",
" # Run two-way ANOVA with interaction.\n",
" anova = run_two_way_anova_with_interaction(group)\n",
" anova = run_two_way_anova_with_interaction(group, alpha=0.05)\n",
" out[\"anova_int\"] = anova.to_dict()\n",
"\n",
" # Depending on interaction significance, perform additional tests.\n",
" if anova[\"is_significant\"][\"X1:X2\"]:\n",
" simple_main_1 = run_simple_main_effects(group, \"X1\")\n",
" simple_main_2 = run_simple_main_effects(group, \"X2\")\n",
" tukey_1 = run_tukey_tests(group, \"X1\", True)\n",
" tukey_2 = run_tukey_tests(group, \"X2\", True)\n",
" simple_main_1 = run_simple_main_effects(group, \"X1\", alpha=0.05)\n",
" simple_main_2 = run_simple_main_effects(group, \"X2\", alpha=0.05)\n",
" tukey_1 = run_tukey_tests(group, \"X1\", True, alpha=0.01)\n",
" tukey_2 = run_tukey_tests(group, \"X2\", True, alpha=0.01)\n",
" \n",
" out[\"simple_main\"] = {\n",
" \"X1\": simple_main_1.to_dict(),\n",
Expand All @@ -456,9 +456,9 @@
" \"X2\": tukey_2.to_dict(\"records\") if tukey_2 is not None else [],\n",
" }\n",
" else:\n",
" anova_noint = run_two_way_anova_without_interaction(group)\n",
" tukey_1 = run_tukey_tests(group, \"X1\", False)\n",
" tukey_2 = run_tukey_tests(group, \"X2\", False)\n",
" anova_noint = run_two_way_anova_without_interaction(group, alpha=0.05)\n",
" tukey_1 = run_tukey_tests(group, \"X1\", False, alpha=0.01)\n",
" tukey_2 = run_tukey_tests(group, \"X2\", False, alpha=0.01)\n",
" \n",
" out[\"anova_noint\"] = anova_noint.to_dict()\n",
" \n",
Expand Down
18 changes: 9 additions & 9 deletions scripts/anova.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def calculate_skewness(df):

return coeff*numerator/denominator/se

def test_skewness(df, alpha=0.05):
def test_skewness(df, alpha=0.01):
"""Test for normality using standardized skewness."""
# Get data subsets
subsets = get_subsets(df)
Expand All @@ -110,7 +110,7 @@ def test_skewness(df, alpha=0.05):
table = pd.DataFrame(results, columns=columns)
return table

def test_shapiro(df, alpha=0.05):
def test_shapiro(df, alpha=0.01):
"""Test for normality using Shapiro-Wilks."""

# Get data subsets
Expand All @@ -135,7 +135,7 @@ def test_shapiro(df, alpha=0.05):
table = pd.DataFrame(results, columns=columns)
return table

def test_levene(df, alpha=0.05):
def test_levene(df, alpha=0.01):
"""Test for homogeneity of variance using Levene's."""

# Get data subsets
Expand Down Expand Up @@ -214,7 +214,7 @@ def calculate_effect_means(df):

# ANOVA ========================================================================

def run_two_way_anova_with_interaction(df, alpha=0.05):
def run_two_way_anova_with_interaction(df, alpha=0.01):
"""Run two-way ANOVA with interaction."""

# Get data levels
Expand Down Expand Up @@ -268,7 +268,7 @@ def run_two_way_anova_with_interaction(df, alpha=0.05):

return table

def run_two_way_anova_without_interaction(df, alpha=0.05):
def run_two_way_anova_without_interaction(df, alpha=0.01):
"""Run two-way ANOVA without interaction."""

# Get data levels
Expand Down Expand Up @@ -321,7 +321,7 @@ def run_two_way_anova_without_interaction(df, alpha=0.05):

return table

def run_simple_main_effects(df, factor, alpha=0.05):
def run_simple_main_effects(df, factor, alpha=0.01):
"""Run simple main effects testing."""

# Get data levels
Expand Down Expand Up @@ -380,7 +380,7 @@ def run_simple_main_effects(df, factor, alpha=0.05):

return table

def run_tukey_tests(df, factor, interaction, alpha=0.05):
def run_tukey_tests(df, factor, interaction, alpha=0.01):
"""Run pairwise Tukey tests."""

# Get data levels
Expand Down Expand Up @@ -410,14 +410,14 @@ def run_tukey_tests(df, factor, interaction, alpha=0.05):
df_subset = df[df[factor_subset] == subset]

# Get results
results_summary = pairwise_tukeyhsd(df_subset.Y, df_subset[factor]).summary()
results_summary = pairwise_tukeyhsd(df_subset.Y, df_subset[factor], alpha=alpha).summary()
results_as_csv = results_summary.as_csv().replace(" ", "").split("\n")[2:]
[results.append([subset] + row.split(",")) for row in results_as_csv]

df = pd.DataFrame(results, columns=columns)
else:
columns = ['group1', 'group2', 'meandiff', 'p-adj', 'lower', 'upper', 'is_significant']
results_summary = pairwise_tukeyhsd(df.Y, df[factor]).summary()
results_summary = pairwise_tukeyhsd(df.Y, df[factor], alpha=alpha).summary()
results_as_csv = results_summary.as_csv().replace(" ", "").split("\n")[2:]
results = [row.split(",") for row in results_as_csv]
df = pd.DataFrame(results, columns=columns)
Expand Down

0 comments on commit 9261662

Please sign in to comment.