Step 5C - Comparing gradient slopes

written by R.A.I. Bethlehem for the Autism Gradients project at Brainhack Cambridge 2017

In [2]:
import numpy as np 
import matplotlib as mpl 
import pandas as pd
output = pd.read_csv('./data/Gradients.csv')
output.head()


Out[2]:
SUB_ID X subject SITE_ID FILE_ID DX_GROUP DSM_IV_TR AGE_AT_SCAN SEX HANDEDNESS_CATEGORY ... 1 2 3 4 5 6 7 8 9 file
0 50004 3 50004 PITT Pitt_0050004 1 1 19.09 1 R ... 0.008470 0.007940 0.007781 0.008144 0.009179 0.008527 0.008443 0.007053 0.007298 Pitt_0050004_rois_cc400.1D.npy
1 50009 8 50009 PITT Pitt_0050009 1 1 33.86 1 R ... 0.008657 0.008265 0.008871 0.008278 0.008208 0.007907 0.007276 0.008844 0.008266 Pitt_0050009_rois_cc400.1D.npy
2 50010 9 50010 PITT Pitt_0050010 1 1 35.20 1 L ... 0.008397 0.007800 0.007688 0.006135 0.007923 0.007170 0.007871 0.006554 0.005794 Pitt_0050010_rois_cc400.1D.npy
3 50012 11 50012 PITT Pitt_0050012 1 1 21.48 1 R ... 0.008173 0.008331 0.008421 0.008395 0.007317 0.008295 0.007617 0.007579 0.008206 Pitt_0050012_rois_cc400.1D.npy
4 50020 18 50020 PITT Pitt_0050020 1 1 20.83 1 R ... 0.008207 0.008663 0.007796 0.008236 0.007974 0.008120 0.008483 0.010089 0.007470 Pitt_0050020_rois_cc400.1D.npy

5 rows × 118 columns


In [20]:
# Column names are strings, so need to provide a list of strings to index:
df = output[['DX_GROUP'] + [str(x) for x in range(10)]]
ASC = df['DX_GROUP'] == 2
NT = df['DX_GROUP'] == 1
G1 = df[ASC]
G2 = df[NT]

In [22]:
%matplotlib inline

## agg backend is used to create plot as a .png file
mpl.use('agg')

import matplotlib.pyplot as plt 

# some plotting options
fs = 10  # fontsize
flierprops = dict(marker='o', markerfacecolor='green', markersize=12,
                  linestyle='none')

## combine the group collections into a list    
Grd0 = [G1['0'], G2['0']]
Grd1 = [G1['1'], G2['1']]
Grd2 = [G1['2'], G2['2']]
Grd3 = [G1['3'], G2['3']]
Grd4 = [G1['4'], G2['4']]
Grd5 = [G1['5'], G2['5']]
Grd6 = [G1['6'], G2['6']]
Grd7 = [G1['7'], G2['7']]
Grd8 = [G1['8'], G2['8']]
Grd9 = [G1['9'], G2['9']]

fig, axes = plt.subplots(nrows=2, ncols=5, figsize=(6, 6), sharey=True)

axes[0, 0].boxplot(Grd0, patch_artist=True)
axes[0, 0].set_title('G0', fontsize=fs)

axes[0, 1].boxplot(Grd1, patch_artist=True)
axes[0, 1].set_title('G1', fontsize=fs)

axes[0, 2].boxplot(Grd2, patch_artist=True)
axes[0, 2].set_title('G2', fontsize=fs)

axes[0, 3].boxplot(Grd3, patch_artist=True)
axes[0, 3].set_title('G3', fontsize=fs)

axes[0, 4].boxplot(Grd4, patch_artist=True)
axes[0, 4].set_title('G4', fontsize=fs)

axes[1, 0].boxplot(Grd5, patch_artist=True)
axes[1, 0].set_title('G5', fontsize=fs)

axes[1, 1].boxplot(Grd6, patch_artist=True)
axes[1, 1].set_title('G6', fontsize=fs)

axes[1, 2].boxplot(Grd7, patch_artist=True)
axes[1, 2].set_title('G7', fontsize=fs)

axes[1, 3].boxplot(Grd8, patch_artist=True)
axes[1, 3].set_title('G8', fontsize=fs)

axes[1, 4].boxplot(Grd9, patch_artist=True)
axes[1, 4].set_title('G9', fontsize=fs)

fig.suptitle("Gradient Slopes")
fig.subplots_adjust(hspace=0.4)