From e35e88e6ac8538b8f1b1215d4af2af97dfcdeaf8 Mon Sep 17 00:00:00 2001 From: jcohenadad Date: Tue, 9 Jan 2024 23:15:47 -0500 Subject: [PATCH] Fixed output statistics --- data_processing.ipynb | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/data_processing.ipynb b/data_processing.ipynb index 6ee1def..5bb6feb 100644 --- a/data_processing.ipynb +++ b/data_processing.ipynb @@ -417,7 +417,7 @@ { "cell_type": "code", "execution_count": null, - "id": "95ab4e6d", + "id": "f8b90a09", "metadata": {}, "outputs": [], "source": [ @@ -439,26 +439,33 @@ " all_data.extend(wa_data)\n", "\n", " if all_data:\n", - " A = np.mean(all_data)\n", - " SD = np.std(all_data)\n", - " data_summary.append([subject, shim_mode, A, SD])\n", + " mean_data = np.mean(all_data)\n", + " sd_data = np.std(all_data)\n", + " data_summary.append([subject, shim_mode, mean_data, sd_data])\n", "\n", "# Convert to DataFrame and save to CSV\n", "df_summary = pd.DataFrame(data_summary, columns=['Subject', 'Shim_Mode', 'Average', 'Standard_Deviation'])\n", "df_summary.to_csv(os.path.join(path_results, 'subject_shim_mode_summary.csv'), index=False)\n", "\n", - "# Step 3: Compute statistics across subjects\n", - "df_grouped = df_summary.groupby('Shim_Mode').agg({'Average': 'mean', 'Standard_Deviation': 'mean'}).reset_index()\n", - "df_grouped.to_csv(os.path.join(path_results, 'average_across_subjects.csv'), index=False)\n", + "# Compute statistics across subjects\n", + "grouped_means = df_summary.groupby('Shim_Mode').agg({'Average': ['mean', 'std'], 'Standard_Deviation': ['mean', 'std']})\n", "\n", - "# Step 4: ANOVA and Posthoc Tests\n", + "# Format mean ± standard deviation\n", + "grouped_means['Average_formatted'] = grouped_means['Average']['mean'].map(\"{:.2f}\".format) + \" ± \" + grouped_means['Average']['std'].map(\"{:.2f}\".format)\n", + "grouped_means['Standard_Deviation_formatted'] = grouped_means['Standard_Deviation']['mean'].map(\"{:.2f}\".format) + \" ± \" + grouped_means['Standard_Deviation']['std'].map(\"{:.2f}\".format)\n", + "\n", + "# Drop multi-level index and only keep formatted columns\n", + "grouped_means = grouped_means.drop(columns=['Average', 'Standard_Deviation'])\n", + "grouped_means.columns = ['Average', 'Standard_Deviation'] # Rename columns for clarity\n", + "grouped_means.reset_index().to_csv(os.path.join(path_results, 'average_across_subjects.csv'), index=False)\n", + "\n", + "# Perform ANOVA and Posthoc Tests\n", "anova_result = f_oneway(*[group[\"Average\"].values for name, group in df_summary.groupby(\"Shim_Mode\")])\n", "print(\"ANOVA Result:\", anova_result)\n", "\n", - "# Perform posthoc test if ANOVA is significant\n", "if anova_result.pvalue < 0.05:\n", " posthoc_result = pairwise_tukeyhsd(df_summary['Average'], df_summary['Shim_Mode'])\n", - " print(\"Posthoc Tukey HSD Result:\\n\", posthoc_result)" + " print(\"Posthoc Tukey HSD Result:\\n\", posthoc_result)\n" ] } ],