##### Child pages
• Linear regression on non-imaging data
Skip to end of banner
Go to start of banner

# Linear regression on non-imaging data

Skip to end of metadata
Go to start of metadata

Warning: this is a somewhat complicated example and is probably not the final version: I'm hoping to find cleaner ways to do some of this.

The code below regresses the NEO-FFI agreeableness (A) measure against conscientiousness (C), not because I expect the result to be interesting, but because the Connectome Python tutorial already shows how to get those values.

You'll need a few Python packages installed (numpy, scipy, matplotlib) to make this work. I ran this in an IPython notebook with pylab for plotting.

```In : import pyxnat
In : import numpy as np
In : from scipy import stats
In : cdb = pyxnat.Interface('https://db.humanconnectome.org','username','password')
In : fields = ['{}/{}'.format('nt:scores',f) for f in ['SUBJECT_ID']+['NEO_NEOFAC_{}'.format(e) for e in 'AOCNE']]
In : constraints = [('nt:scores/PROJECTS','LIKE','%HCP_Q2')]
In : scores_json = cdb.select('nt:scores',fields).where(constraints)
In : scores_json.headers()
Out: ['subject_id', 'neo_neofac_a', 'neo_neofac_c', 'neo_neofac_e', 'neo_neofac_n', 'neo_neofac_o']
In : scores = np.array([[float(v) if v else np.nan for v in row.values()[1:]] for row in scores_json.data]).transpose()
In : missing = np.isnan(scores)
In : neo_a = scores[~missing]
In : neo_c = scores[~missing]
In : slope,intercept,r_value,p_value,std_err = stats.linregress(neo_a,neo_c)
In : line = slope * neo_a + intercept
In : plot(neo_a, line, 'r-', neo_a, neo_c, 'o')
Out: [<matplotlib.lines.Line2D at 0x54bedd0>, <matplotlib.lines.Line2D at 0x54c4050>]``` • No labels