Differences between revisions 5 and 6
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 [wiki:Self:FsTutorial/CreateFsgdFile 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.] and [wiki:Self:FsTutorial/CreateContrastVectors Exercise C.] you should have an FSGD file called my_gender_age.txt and a contrast file called age.mat, both in your SUBJECTS_DIR/stats directory . The following are sample commands, that can be used with the data, to complete a group analysis:
Line 22: Line 22:
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
}}}
Line 33: Line 23:
{{{
# 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
mris_preproc --fsgd my_gender_age.txt --target average --hemi lh -- meas thickness --out lh.my_gender_age.thickness.mgh
Line 68: Line 27:
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: Once this completes, you can do the smoothing step:
Line 71: Line 30:
mri_surf2surf --hemi lh --s your_average_subject --sval lh.your_fsgd.thickness.mgh --fwhm 10 --tval lh.your_fsgd.thickness.10.mgh mri_surf2surf --hemi lh --s average --sval lh.my_gender_age.thickness.mgh --fwhm 10 --tval lh.my_gender_age.thickness.10.mgh
Line 74: Line 33:
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.

 * [wiki:Self:FsTutorial/CreateContrastVectors Exercise C. Specify contrast vectors to test 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:
Once this is complete, you can move on to test your contrast vector:
Line 86: Line 36:
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 mri_glmfit --y lh.my_gender_age.thickness.10.mgh --fsgd my_gender_age.txt --glmdir lh.my_gender_age.glmdir --pca --surf --average lh --C age.mat
Line 89: Line 39:
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.
Line 91: Line 40:
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 coefficients[[BR]]
eres.mgh - residual error[[BR]]
fsgd.X.mat - [[BR]]
mri_glmfit.log - execution parameters[[BR]]
rstd.mgh - residual error stddev (just sqrt of rvar)[[BR]]
rvar.mgh - residual error variance[[BR]]
Xg.dat - [[BR]]
y.fsgd - fsgd file[[BR]]

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 matrix[[BR]]
F.mgh - F-ratio[[BR]]
gamma.mgh - contrast[[BR]]
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 values[[BR]]
v.mgh - spatial eigenvectors[[BR]]
u.mat - frame eigenvectors[[BR]]
In addition, there is stats.dat with 5 columns:[[BR]]
  (1) component number[[BR]]
  (2) variance spanned by that component[[BR]]
  (3) cumulative variance spanned up to that component[[BR]]
  (4) percent variance spanned by that component[[BR]]
  (5) cumulative percent variance spanned up to that component[[BR]]
 
The commands are the same for the right hemisphere, replacing every '''lh''' with an '''rh'''.

[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.] and [wiki:FsTutorial/CreateContrastVectors Exercise C.] you should have an FSGD file called my_gender_age.txt and a contrast file called age.mat, both in your SUBJECTS_DIR/stats directory . The following are sample commands, that can be used with the data, to complete a group analysis:

# For the left hemisphere

mris_preproc --fsgd my_gender_age.txt --target average --hemi lh -- meas thickness --out lh.my_gender_age.thickness.mgh

Once this completes, you can do the smoothing step:

mri_surf2surf --hemi lh --s average --sval lh.my_gender_age.thickness.mgh --fwhm 10 --tval lh.my_gender_age.thickness.10.mgh

Once this is complete, you can move on to test your contrast vector:

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

The commands are the same for the right hemisphere, replacing every lh with an rh.

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