Skip to content

Commit

Permalink
Merge pull request #55 from neurorepro/iquant
Browse files Browse the repository at this point in the history
Fix typo. Add solution to challenge.
  • Loading branch information
neurorepro authored Jun 4, 2021
2 parents c1c8a33 + 0aa257b commit 5af985c
Showing 1 changed file with 303 additions and 13 deletions.
316 changes: 303 additions & 13 deletions code/6_sMRI_quantification_stats.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
"source": [
"import nibabel.imagestats as imagestats\n",
"# Volume of the Left hippocampus\n",
"imagestats.mask_volume(roi_mask_int)"
"imagestats.mask_volume(roi_mask)"
]
},
{
Expand Down Expand Up @@ -840,12 +840,14 @@
},
{
"cell_type": "code",
"execution_count": 480,
"execution_count": 520,
"metadata": {},
"outputs": [],
"source": [
"fs_stats_dir = \"../local_data/AOMIC/derivatives/fs_stats\"\n",
"hemi=\"lh\""
"hemi=\"lh\"\n",
"stats_file = os.path.join(fs_stats_dir, \n",
" f\"data-cortical_type-aparc.a2009s_measure-thickness_hemi-{hemi}.tsv\")"
]
},
{
Expand Down Expand Up @@ -2503,7 +2505,7 @@
"source": [
"plt.figure(figsize=(12, 6))\n",
"g = sns.scatterplot(x=predictor, y=response, hue='hemi', alpha=0.7,\n",
" palette=sns.color_palette('husl',2), data=plot_df)"
" palette=sns.color_palette('husl',2), data=fs_all_df)"
]
},
{
Expand Down Expand Up @@ -3097,15 +3099,6 @@
" stat_map_rh[stat_labels] = t_stat"
]
},
{
"cell_type": "code",
"execution_count": 424,
"metadata": {},
"outputs": [],
"source": [
"plotting.plot_surf_roi?"
]
},
{
"cell_type": "code",
"execution_count": 501,
Expand Down Expand Up @@ -3147,6 +3140,61 @@
" vmin=-5, vmax=5);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# If on Binder shutdown your notebook and restart from here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import glob\n",
"import numpy as np\n",
"import pandas as pd\n",
"import nilearn\n",
"from nilearn import plotting\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"import nibabel as nib\n",
"from bids import BIDSLayout"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data_dir = '../local_data/AOMIC'\n",
"fmriprep_dir = '../local_data/AOMIC/derivatives/fmriprep'\n",
"fsstats_dir = '../local_data/AOMIC/derivatives/fs_stats'\n",
"vbm_dir = '../local_data/AOMIC/derivatives/vbm'\n",
"bids_layout = BIDSLayout(data_dir, derivatives=True)\n",
"bids_layout"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -4249,6 +4297,248 @@
"source": [
"plotting.plot_stat_map(zmap226, threshold=zthr, colorbar=True, display_mode='z');"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solutions to data cleaning challenge"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge 1"
]
},
{
"cell_type": "code",
"execution_count": 523,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>participant_id</th>\n",
" <th>age</th>\n",
" <th>sex</th>\n",
" <th>BMI</th>\n",
" <th>handedness</th>\n",
" <th>education_category</th>\n",
" <th>raven_score</th>\n",
" <th>NEO_N</th>\n",
" <th>NEO_E</th>\n",
" <th>NEO_O</th>\n",
" <th>NEO_A</th>\n",
" <th>NEO_C</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>104</th>\n",
" <td>sub-0105</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>13</td>\n",
" <td>43</td>\n",
" <td>35</td>\n",
" <td>39</td>\n",
" <td>53</td>\n",
" </tr>\n",
" <tr>\n",
" <th>198</th>\n",
" <td>sub-0199</td>\n",
" <td>NaN</td>\n",
" <td>F</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>applied</td>\n",
" <td>16.0</td>\n",
" <td>41</td>\n",
" <td>52</td>\n",
" <td>41</td>\n",
" <td>46</td>\n",
" <td>59</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" participant_id age sex BMI handedness education_category raven_score \\\n",
"104 sub-0105 NaN NaN NaN NaN NaN NaN \n",
"198 sub-0199 NaN F NaN NaN applied 16.0 \n",
"\n",
" NEO_N NEO_E NEO_O NEO_A NEO_C \n",
"104 13 43 35 39 53 \n",
"198 41 52 41 46 59 "
]
},
"execution_count": 523,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"subjects_info_withna.loc[subjects_info_withna.isnull().any(axis=1), :]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge 2"
]
},
{
"cell_type": "code",
"execution_count": 521,
"metadata": {},
"outputs": [],
"source": [
"subjects_info = subjects_info_withna.copy()"
]
},
{
"cell_type": "code",
"execution_count": 526,
"metadata": {},
"outputs": [],
"source": [
"subjects_info[\"age\"] = subjects_info_withna[\"age\"].fillna(subjects_info_withna[\"age\"].mean())\n",
"subjects_info[\"sex\"] = subjects_info_withna[\"sex\"].fillna(subjects_info_withna[\"sex\"].mode()[0])"
]
},
{
"cell_type": "code",
"execution_count": 527,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>participant_id</th>\n",
" <th>age</th>\n",
" <th>sex</th>\n",
" <th>BMI</th>\n",
" <th>handedness</th>\n",
" <th>education_category</th>\n",
" <th>raven_score</th>\n",
" <th>NEO_N</th>\n",
" <th>NEO_E</th>\n",
" <th>NEO_O</th>\n",
" <th>NEO_A</th>\n",
" <th>NEO_C</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>104</th>\n",
" <td>sub-0105</td>\n",
" <td>21.955357</td>\n",
" <td>F</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>13</td>\n",
" <td>43</td>\n",
" <td>35</td>\n",
" <td>39</td>\n",
" <td>53</td>\n",
" </tr>\n",
" <tr>\n",
" <th>198</th>\n",
" <td>sub-0199</td>\n",
" <td>21.955357</td>\n",
" <td>F</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>applied</td>\n",
" <td>16.0</td>\n",
" <td>41</td>\n",
" <td>52</td>\n",
" <td>41</td>\n",
" <td>46</td>\n",
" <td>59</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" participant_id age sex BMI handedness education_category \\\n",
"104 sub-0105 21.955357 F NaN NaN NaN \n",
"198 sub-0199 21.955357 F NaN NaN applied \n",
"\n",
" raven_score NEO_N NEO_E NEO_O NEO_A NEO_C \n",
"104 NaN 13 43 35 39 53 \n",
"198 16.0 41 52 41 46 59 "
]
},
"execution_count": 527,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"subjects_info.loc[subjects_info.isnull().any(axis=1), :]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit 5af985c

Please sign in to comment.