Differences between revisions 5 and 29 (spanning 24 versions)
Revision 5 as of 2006-02-09 17:38:56
Size: 7692
Editor: JenniPacheco
Comment:
Revision 29 as of 2021-09-22 11:38:51
Size: 3786
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
[wiki:Self:FsTutorial top] | [wiki:Self:FsTutorial/GroupAnalysis previous] [[FsTutorial|top]] | [[FsTutorial/GroupAnalysis|previous]]
Line 4: Line 4:
 *To follow this exercise exactly be sure you've downloaded the [[FsTutorial/Data|tutorial data set]] before you begin. If you choose not to download the data set you can follow these instructions on your own data, but you will have to substitute your own specific paths and subject names.
Line 5: Line 6:
In order to compute the contrats you will first need to change to the tutorial data directory and setup SUBJECTS_DIR: In order to compute the contrasts you will first need to change to the tutorial data directory and setup SUBJECTS_DIR:
Line 8: Line 9:
cd $FREESURFER_HOME/subjects/buckner_data/tutorial_subjs/group_analysis_tutorial cd $TUTORIAL_DATA/buckner_data/tutorial_subjs/group_analysis_tutorial
Line 18: Line 19:
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 [[FsTutorial/CreateFsgdFile|Exercise A.]] and [[FsTutorial/CreateContrastVectors|Exercise B.]] you should have an FSGD file called my_gender_age_fsgd.txt and a contrast file called age.mat, both in your SUBJECTS_DIR/stats directory. Confirm that those files exist:
{{{
ls my_gender_age_fsgd.txt age.mat
}}}
If my_gender_age_fsgd.txt does not exist, complete [[FsTutorial/CreateFsgdFile|Exercise A.]] If age.mat does not exist, complete [[FsTutorial/CreateContrastVectors|Exercise B.]], or just create a file called age.mat containing this line:
{{{
0 0 1
}}}

The following are sample commands, that can be used with the data, to complete a group analysis:
Line 22: Line 32:
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

mris_preproc --fsgd my_gender_age_fsgd.txt \
  --target average \
  --hemi lh \
  --meas thickness \
  --out lh.my_gender_age.thickness.mgh
Line 33: Line 40:
{{{
# 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:
Once this completes you should see the file lh.my_gender_age.thickness.mgh. The next step, the smoothing step, will use this as input:
Line 64: Line 43:
mris_preproc --fsgd your_fsgd.txt --target your_average_subject --hemi lh -- meas thickness --out lh.your_fsgd.thickness.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 67: Line 50:

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 is complete you should see the file lh.my_gender_age.thickness.10.mgh. The next step will test the hypothesis you've set up using your contrast vector:
Line 71: Line 53:
mri_surf2surf --hemi lh --s your_average_subject --sval lh.your_fsgd.thickness.mgh --fwhm 10 --tval lh.your_fsgd.thickness.10.mgh mri_glmfit --y lh.my_gender_age.thickness.10.mgh \
  --fsgd my_gender_age_fsgd.txt doss \
  --glmdir lh.my_gender_age.glmdir \
  --pca \
  --surf average lh \
  --C age.mat
Line 74: Line 61:
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:
You should have two new directories in $TUTORIAL_DATA/buckner_data/tutorial_subjs/group_analysis_tutorial/stats - lh.my_gender_age.glmdir and rh.my_gender_age.glmdir. If you do:
Line 86: Line 64:
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 ls lh.my_gender_age.glmdir
Line 89: Line 67:
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:
you should see this:
Line 94: Line 70:

ar1.mgh eres.mgh mri_glmfit.log rstd.mgh age/ y.fsgd
beta.mgh fsgd.X.mat pca-eres/ rvar.mgh Xg.dat
age/ beta.mgh fsgd.X.mat pca-eres/ rvar.mgh y.fsgd
ar1.mgh eres.mgh mri_glmfit.log rstd.mgh Xg.dat
Line 99: Line 74:
the outputs are as follows: and if you do:
{{{
ls lh.my_gender_age.glmdir/age
}}}
Line 101: Line 79:
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:
you should see this:
Line 117: Line 85:
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:
You can view your results by opening the average subject in tksurfer:
Line 128: Line 87:
sdiag.mat stats.dat u.mat v.mgh tksurfer average lh inflated
Line 131: Line 90:
The outputs are as follows: and loading in your overlay, '''File -> Load Overlay''' and browse to stats/lh.my_gender_age.glmdir/age/sig.mgh.
Line 133: Line 92:
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]]
 
It should look like this:
{{attachment:sig.mgh.jpg}}

If you would like to also view the scatter plots associated with this you can do so by '''File -> Load Group Descriptor File''' and browse to stats/lh.my_gender_age.glmdir/y.fsgd. Once that file is loaded, a window titled 'Thickness' will appear. Once that appears, then click on any point on the surface, and the thickness data for that surface vertex will appear in the Thickness plot window. The surface areas in blue indicating cortical thinning with age, as shown in the plot.

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

top | previous

Group Analysis command lines

  • To follow this exercise exactly be sure you've downloaded the tutorial data set before you begin. If you choose not to download the data set you can follow these instructions on your own data, but you will have to substitute your own specific paths and subject names.

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

cd $TUTORIAL_DATA/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 Exercise A. and Exercise B. you should have an FSGD file called my_gender_age_fsgd.txt and a contrast file called age.mat, both in your SUBJECTS_DIR/stats directory. Confirm that those files exist:

ls my_gender_age_fsgd.txt age.mat

If my_gender_age_fsgd.txt does not exist, complete Exercise A. If age.mat does not exist, complete Exercise B., or just create a file called age.mat containing this line:

0 0 1

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_fsgd.txt \
  --target average \
  --hemi lh \
  --meas thickness \
  --out lh.my_gender_age.thickness.mgh

Once this completes you should see the file lh.my_gender_age.thickness.mgh. The next step, the smoothing step, will use this as input:

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 should see the file lh.my_gender_age.thickness.10.mgh. The next step will test the hypothesis you've set up using your contrast vector:

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

You should have two new directories in $TUTORIAL_DATA/buckner_data/tutorial_subjs/group_analysis_tutorial/stats - lh.my_gender_age.glmdir and rh.my_gender_age.glmdir. If you do:

ls lh.my_gender_age.glmdir

you should see this:

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

and if you do:

ls lh.my_gender_age.glmdir/age

you should see this:

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

You can view your results by opening the average subject in tksurfer:

tksurfer average lh inflated

and loading in your overlay, File -> Load Overlay and browse to stats/lh.my_gender_age.glmdir/age/sig.mgh.

It should look like this: sig.mgh.jpg

If you would like to also view the scatter plots associated with this you can do so by File -> Load Group Descriptor File and browse to stats/lh.my_gender_age.glmdir/y.fsgd. Once that file is loaded, a window titled 'Thickness' will appear. Once that appears, then click on any point on the surface, and the thickness data for that surface vertex will appear in the Thickness plot window. The surface areas in blue indicating cortical thinning with age, as shown in the plot.

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)