Time Series Analysis: Difference between revisions
Line 4: | Line 4: | ||
== FreeSurfer == | == FreeSurfer == | ||
=== Surface Parcellation and Functional Analysis === | |||
The first precondition for these analyses in surface space is that the anatomical data must be processed in [[FreeSurfer#Structural_Preprocessing | FreeSurfer]], and a [[FreeSurfer#Functional_Analysis | functional analysis]] must be run on the BOLD data. | The first precondition for these analyses in surface space is that the anatomical data must be processed in [[FreeSurfer#Structural_Preprocessing | FreeSurfer]], and a [[FreeSurfer#Functional_Analysis | functional analysis]] must be run on the BOLD data. | ||
Line 9: | Line 10: | ||
=== Detrending === | === Detrending === | ||
Over the course of a run, there can be a linear drift in the signal in different regions of the brain. There are many possible causes for this that have nothing to do with any interesting aspect of your data -- in other words, this linear drift is a nuisance artifact. | Over the course of a run, there can be a linear drift in the signal in different regions of the brain. There are many possible causes for this that have nothing to do with any interesting aspect of your data -- in other words, this linear drift is a nuisance artifact. The second step is to remove this signal drift from the data because it can introduce spurious correlations between two unrelated time series. You can see this for yourself in a quick experiment you could whip up in Excel: take two vectors of 100 randomly generated numbers (e.g., <code>randbetween(1,99)</code>). They should be uncorrelated. Now add 1, 2, 3, ... , 99, 100 to the values in each vector. This simulates a linear trend in the data. You shouldn't be surprised to find that the two vectors are now highly and positively correlated! | ||
A script has been written called detrend.sh that removes the linear trend in your BOLD data: | A script has been written called detrend.sh that removes the linear trend in your BOLD data: |
Revision as of 11:45, 4 May 2016
Inferences about functional connectivity can be made from analyses of time series data. The underlying assumption is that correlations between brain activity in different brain regions indexes connectivity between them. These correlations are calculated over vectors of activation values across a period of time.
When doing these analyses on MRI data, we must define the regions from which these time series will be drawn, and then extract the time series for each region that will be entered into the analysis. The time series vectors are saved into a flexibly interpretable file (e.g., plaintext) that can be read into some other software suitable for operating over sets of numbers (e.g., R, MATLAB, Excel).
FreeSurfer
Surface Parcellation and Functional Analysis
The first precondition for these analyses in surface space is that the anatomical data must be processed in FreeSurfer, and a functional analysis must be run on the BOLD data.
The brain regions from which the time series are drawn can be defined any number of ways. One way of defining these regions has been to use anatomical region definitions. Because different anatomical regions vary greatly in size, we have been using the Lausanne 2008 parcellation scheme to divide the cortex into roughly 1000 regions of comparable size. The second precondition for this analysis is to define your regions of interest. Any definition method that has been documented is allowable, though at this point, instructions exist on this wiki for the Lausanne 2008 parcellation scheme.
Detrending
Over the course of a run, there can be a linear drift in the signal in different regions of the brain. There are many possible causes for this that have nothing to do with any interesting aspect of your data -- in other words, this linear drift is a nuisance artifact. The second step is to remove this signal drift from the data because it can introduce spurious correlations between two unrelated time series. You can see this for yourself in a quick experiment you could whip up in Excel: take two vectors of 100 randomly generated numbers (e.g., randbetween(1,99)
). They should be uncorrelated. Now add 1, 2, 3, ... , 99, 100 to the values in each vector. This simulates a linear trend in the data. You shouldn't be surprised to find that the two vectors are now highly and positively correlated!
A script has been written called detrend.sh that removes the linear trend in your BOLD data:
detrend.sh
#!/bin/bash USAGE="Usage: detrend.sh filepattern sub1 ... subN" if [ "$#" == "0" ]; then echo "$USAGE" exit 1 fi #first parameter is the filepattern for the .nii.gz time series to be detrended, up to the hemisphere indicator #e.g., fmcpr.sm6.self.?h.nii.gz would use fmcpr.sm6.self as the filepattern filepat="$1" shift #after the shift command, all the arguments are shifted down one place and the first argument (the filepattern) #falls off the list. The remaining arguments should be subject_ids subs=( "$@" ); hemis=( "lh" "rh" ); for sub in "${subs[@]}"; do source_dir=${SUBJECTS_DIR}/${sub}/bold if [ ! -d ${source_dir} ]; then #The subject_id does not exist echo "${source_dir} does not exist!" else cd ${source_dir} readarray -t runs < runs for r in "${runs[@]}"; do for hemi in "${hemis[@]}"; do cd ${source_dir}/${r} pwd #subject_id does exist. Detrend mri_glmfit --y ${source_dir}/${r}/${filepat}.${hemi}.nii.gz \ --glmdir ${source_dir}/${r}/${hemi}.detrend --qa \ --save-yhat --eres-save --surf ${sub} ${hemi} mv ${source_dir}/${r}/${hemi}.detrend/eres.mgh \ ${source_dir}/${r}/${filepat}.${hemi}.mgh done done fi done
Before running this script, you will need to create a text file called 'runs' in the bold/ directory for each subject's dataset, e.g.,
- FS_T1_501/
- bold/
- runs
- 003/
- 004/
- bold/
The runs
file simply lists each run folder on its own line:
003 004
The detrend.sh script uses this file to determine the folders containing the data to be detrended. Assuming all your subject folders have the same run folders to detrend, you would detrend multiple subjects using detrend.sh, specifying a file pattern for the source data (i.e., the name of the preprocessed files generated by FS-FAST, omitting anything after the '?h' hemisphere identifier), followed by a list of subject IDs:
detrend.sh fmcpr.sm6.self FS_T1_501 FS_T2_501 FS_T1_505 FS_T2_505
The gist is that it calls the mri_glmfit function and saves the residuals after the linear trend has been removed from the data. The detrended data is saved in each run directory as a new file called detrend.something.?h.mgh.
SPM
Steps for SPM data have not been implemented yet.