Skip to content

Commit

Permalink
Fixed output statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
jcohenadad committed Jan 10, 2024
1 parent 368778e commit e35e88e
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions data_processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "95ab4e6d",
"id": "f8b90a09",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -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"
]
}
],
Expand Down

0 comments on commit e35e88e

Please sign in to comment.