In this unit we want to work through an example of linear regression, in particular the estimation part.
First, I will walk/talk you through an example of how to load in some data, get a timecourse from a single voxel at a time, the designMatrix and then show the linear regression bit in action.
go to subfolder and you can also have a look at the PDF file I produced from the analysis script using the publish() feature in Matlab.
If we have time, we can also think about how we can take the logic of the code I wrote in the script into a function that takes as inputs
y_filenameX_filenamecoordsThe function linRegress() should be of the following form:
b = linRegress( y_filename, X_filename, coords)y_filename (a nifti file) which provides data and information about timing
y_filename to make a vector of numbers that specify time (call one t_seeconds, another t_volumes) discussion point in your groups! why?? how??y from the data stored in y_filename using the coords variable (hint: how are x,y,z stored, how can we get them out??). consider reusing code we wrote last time?!X_filenamefinds: beta = X\y; using backslash operation
beta values on command line (disp, sprintf, fprintf)modelfit = X*beta on top of timecourse plot (same figure)Ultimately, running the following should work
cd('facesVhouses');
b = linRegress( 'filtered_func_data.nii', 'designMatrix.txt', [18, 14, 4])
cd('..'); % come back up one folder
To orient you with some of the calculations, consider the following plot:
