Differences between revisions 4 and 5
Deletions are marked like this. Additions are marked like this.
Line 18: Line 18:
Upon successful completion of the make_average_subject command you should have an average subject in your SUBJECTS_DIR. After successfully completing Exercise A. you should also have an FSGD file called gender_age.txt in your SUBJECTS_DIR/stats directory. Upon successful completion of the make_average_subject command you should have an average subject in your SUBJECTS_DIR. After successfully completing [wiki:Self:FsTutorial/CreateFsgdFile Exercise A.] you should also have an FSGD file called gender_age.txt in your SUBJECTS_DIR/stats directory.

[wiki:FsTutorial top] | [wiki:FsTutorial/GroupAnalysis previous]

Group Analysis command lines

In order to compute the contrats you will first need to change to the tutorial data directory and setup SUBJECTS_DIR:

cd $FREESURFER_HOME/subjects/buckner_data/tutorial_subjs/group_analysis_tutorial
setenv SUBJECTS_DIR ${PWD}

Change into the directory you ran the estimation step in, most likely called 'stats':

cd stats

Upon successful completion of the make_average_subject command you should have an average subject in your SUBJECTS_DIR. After successfully completing [wiki:FsTutorial/CreateFsgdFile Exercise A.] you should also have an FSGD file called gender_age.txt in your SUBJECTS_DIR/stats directory.

# For the left hemisphere
mris_glm --hemi lh \
         --trgsubj average \
         --fsgd ./my_gender_age_fsgd.txt doss \
         --beta_in ./beta_doss-thickness-100lh.mgz \
         --var_in ./var_doss-thickness-100lh.mgz \
         --gcv 0 0 1 \
         --ces ./ces_Age_doss-thickness-100lh.mgz \
         --t ./t_Age_doss-thickness-100lh.mgz \
         --sigt ./sigt_Age_doss-thickness-100lh.mgz

# For the right hemisphere
mris_glm --hemi rh \
         --trgsubj average \
         --fsgd ./my_gender_age_fsgd.txt doss \
         --beta_in ./beta_doss-thickness-100rh.mgz \
         --var_in ./var_doss-thickness-100rh.mgz \
         --gcv 0 0 1 \
         --ces ./ces_Age_doss-thickness-100rh.mgz \
         --t ./t_Age_doss-thickness-100rh.mgz \
         --sigt ./sigt_Age_doss-thickness-100rh.mgz 

With the above configuration, mris_glm tests the given subjects for straight correlation between thickness and age. The command will read in the regression coefficients (--beta_in) and noise variance (--var_in) that were generated from the estimation process, and save the contrast effect size (ces), t-ratio of the contrast, and the significance of the t-ratio (i.e., t-test) in the same directory, all in paint format.

Upon completion, make sure that the following files are available in the directory from which mris_glm was run by typing:

ls -l ces_Age_doss-thickness-100lh.mgz
ls -l t_Age_doss-thickness-100lh.mgz
ls -l sigt_Age_doss-thickness-100lh.mgz

ls -l ces_Age_doss-thickness-100rh.mgz
ls -l t_Age_doss-thickness-100rh.mgz
ls -l sigt_Age_doss-thickness-100rh.mgz

in that directory.

3.3 Preprocessing steps BR

Once an FSGD file is set up and the average subject is made the preprocessing steps can be followed. The first step will use mris_preproc to assemble your data into a single file in the common surface space, your_average_subject for this example (which is the average you have made for this particular study). In this step you will have to specify your FSGD file, your_fsgd.txt here, your target subject, your_average_subject here, the hemisphere and measure you are using. You will also name the output file - it's a good idea to use a naming convention that will make it obvious what comparison you are working with. The following is a sample command line, using mris_preproc, for a thickness study:

mris_preproc --fsgd your_fsgd.txt --target your_average_subject --hemi lh -- meas thickness --out lh.your_fsgd.thickness.mgh

The next step is to do surface smoothing. Smooth input with a Gaussian kernel with the given full-width/half-maximum (fwhm) specified in mm. To do this mri_surf2surf will be used along with the output from mris_preproc and your average subject. Here is a sample command line:

mri_surf2surf --hemi lh --s your_average_subject --sval lh.your_fsgd.thickness.mgh --fwhm 10 --tval lh.your_fsgd.thickness.10.mgh

You can do the surface smoothing as part of the first step with mris_preproc, but if you do it afterwards as a separate step you can smooth to many different levels without having to rebuild the data each time.

3.4 mri_glmfit BR

mri_glmfit is replacing mris_glm, which previously only worked on surfaces, to perform the general linear model (GLM) analysis in the volume or the surface. Options include simulation for correction for multiple comparisons, weighted LMS, variance smoothing, PCA/SVD analysis of residuals, per-voxel design matrices, and 'self' regressors. This program performs both the estimation and inference. The framework for testing specific hypotheses is specified in the form of a contrast vector. For instance, a contrast vector such as [1 0 0 0 ...] is used to examine the strength of the observed effect from the EV in the first design matrix column. Another contrast vector, [1 -1 0 0 ...], is used to compare the effects between the first two EVs in the design matrix. You can specify your contrast vector as a separate file, which will be read in by mri_glmfit, and used to test your hypotheses.

mri_glmfit will take the output from your smoothing step above, your fsgd file, your average subject and the contrast vector as inputs. You will also have to specify a glm directory name, and in this directory all of the outputs will be saved. It is a good idea to use a descriptive name, so you can easily recognize which outputs are in which directory. Here is a sample mri_glmfit command:

mri_glmfit --y lh.your_fsgd.thickness.10.mgh --fsgd your_fsgd.txt --glmdir lh.your_fsgd.glmdir --pca --surf --your_average_subject lh --C age.mat

age.mat is the contrast vector that was created during exercise C. the flag --surf is used to specify that the input has a surface geometry from the hemisphere of the given FreeSurfer subject. If --surf is not specified, then mri_glmfit will assume that the data are volume-based and use the geometry as specified in the header to make spatial calculations. The flag --pca is used to perform PCA/SVD analysis on the residual.

Once you have run this command you will have an output directory, lh.your_fsgd.glmdir. There will be a number of output files in this directory, as well as two other directories. If you do an ls in your glmdir you should see this:

ar1.mgh   eres.mgh    mri_glmfit.log  rstd.mgh  age/  y.fsgd
beta.mgh  fsgd.X.mat  pca-eres/       rvar.mgh  Xg.dat

the outputs are as follows:

ar1.mgh - BR beta.mgh - all regression coefficientsBR eres.mgh - residual errorBR fsgd.X.mat - BR mri_glmfit.log - execution parametersBR rstd.mgh - residual error stddev (just sqrt of rvar)BR rvar.mgh - residual error varianceBR Xg.dat - BR y.fsgd - fsgd fileBR

The two subdirectories that were created, age/ (named for your contrast file) and pca-eres/ contain some additional outputs. In the age/ directory you will see:

C.dat  F.mgh  gamma.mgh  maxvox.dat  sig.mgh

The outputs are as follows:

C.dat - copy of contrast matrixBR F.mgh - F-ratioBR gamma.mgh - contrastBR sig.mgh - significance from F-test (actually -log10(p))BR

In the pca-eres/ directory you will see:

sdiag.mat  stats.dat  u.mat  v.mgh

The outputs are as follows:

sdiag.mat - singular valuesBR v.mgh - spatial eigenvectorsBR u.mat - frame eigenvectorsBR In addition, there is stats.dat with 5 columns:BR

  • (1) component numberBR (2) variance spanned by that componentBR (3) cumulative variance spanned up to that componentBR (4) percent variance spanned by that componentBR (5) cumulative percent variance spanned up to that componentBR

FsTutorial/ComputeContrast (last edited 2021-09-22 11:38:51 by DevaniCordero)