Programming Intro Exercises - NSBLab/MATLAB-connectome-intro GitHub Wiki
Programming Language Exercises
These exercises are intended to recap some of the topics covered in the previous sections (e.g. importing data, plotting data, simple statistics). These exercises are not specific to any particular language - you should attempt these in your choice of language.
The data required for the exercises are available in the repo here. Solutions are provided in MATLAB (exercises.mlx
here), and other languages coming soon.
Importing and Manipulating Data
- Import the data from
2-subjects.csv
as an array, matrix or equivalent- Note that each value is separated by commas
- The final result should be a 164 x 82 matrix: https://github.com/BMHLab/MATLAB-connectome-intro/wiki/images/Picture5.png
- Separate that data into 2 variables (which are square matrices). The first variable should be called
subj1
and should contain the data from the first 82 rows. The next variable should be calledsubj2
and should contain the data from the next 82 rows.- The first 34 rows/cols are the left hemisphere cortex. The next 7 are the left subcortex. The next 34 are the right hemisphere cortex. The last 7 are the right subcortex.
- Import the data from
coords.csv
as an array, matrix or equivalent into the variablecoords
- The columns represent the x, y, and z coordinates (in order) of each datapoint in the connectivity matrices
- The final result should be an 82 x 3 matrix: https://github.com/BMHLab/MATLAB-connectome-intro/wiki/images/Picture6.png
Plotting Data
- Create a figure with 2 sub figures. In the first subfigure, plot a heatmap of the connectivity for
subj1
; in the second, forsubj2
. Add titles to each subfigure. It should look like this: https://github.com/BMHLab/MATLAB-connectome-intro/wiki/images/Picture7.png - Create a new figure. Create a histogram showing the degree distribution of
subj1
(not the edge weight). Then, overlay the degree distribution ofsubj2
. Add axes labels, and title, and a legend showing which is which. It should look like this: https://github.com/BMHLab/MATLAB-connectome-intro/wiki/images/Picture8.png - Create a new figure. Create a 3-D scatter plot, with each point positioned according to the data in
coords
, and coloured according to the mean value of the degree across the two subjects.- You might need to fill in the data points, and set the axes to be scaled equally. https://github.com/BMHLab/MATLAB-connectome-intro/wiki/images/Picture9.png
Analysing Data
- Correlations between subjects
- Find the positions in the heatmaps that are non-zero for both
subj1
andsubj2
. - Plot the log of the edge weights of the two subjects at these locations on a 2-D scatter plot. https://github.com/BMHLab/MATLAB-connectome-intro/wiki/images/Picture10.png
- Find the correlation coefficient of this plot.
Correlation between log(subj1 edge weight) and log(subj2 edge weight) is 0.718259
- Optionally, plot a line of regression and find the regression coefficients.
Regression coefficients are 0.7398 -0.9963
- Find the positions in the heatmaps that are non-zero for both
Advanced Exercises
- GLM of eigenmodes
- Read in
modes.csv
to a variablemodes
. This should be a 34 x 25 matrix. Note that each of the 34 points corresponds to the first 34 points of thesubj
datasets. - Save the degree of the first 34 nodes of
subj1
to a variable calledsubj1_degree
(ideally as a column). - Use regression/a generalised linear model, find the loadings of the node degree onto the
modes
matrix.- Your output should be a 25 x 1 vector of coefficients indicating the loadings used to reconstruct the node degree.
- Now, create a reconstruction of the original degree data using the loadings and the data from modes. What is the correlation between the reconstruction and the original degree data?
Correlation between subj1 degree and 25 modes is 0.904497
- Using a
for
loop or otherwise, find the reconstruction accuracy/correlation coefficient when using 5, 10, 15, 20, or 25 modes:- Using 5 modes, recon accuracy = 0.668466
- Using 10 modes, recon accuracy = 0.779506
- Using 15 modes, recon accuracy = 0.827639
- Using 20 modes, recon accuracy = 0.883510
- Using 25 modes, recon accuracy = 0.904497
- Optionally, find and plot the reconstruction accuracy when using 2, 3, 4, ..., 25 modes: https://github.com/BMHLab/MATLAB-connectome-intro/wiki/images/Picture11.png
- Read in