Finding Mean Cortical Thickness Values Using R

Written 5/16/2007 by Liberty Hamilton. Updated 2/17/2009 by Owen Phillips. Email Dr. Katherine Narr if you have any questions. For more information, see the protocols page.


Running on the Command Line

To run on the command line, you must first make sure that your account is set up to use R on (the grid). To do this, follow these steps:

  1. In your home directory, make a backup of your .Renviron file that configures to run on inire (you may not have one).
  2. cp ~woods/.Renviron ./
  3. Connect to ssh -X
  4. source /usr/sge/loni/common/settings.csh (if you are using the .csh shell)

Once your account is configured to run R, you will need to create a text file listing all of the files for which you need a cortical thickness value. You can use a text file with other columns (that you used previously in an ANOVA, for example), or you can create a new one. Make sure the first line has the word "File" with a capital F, and that all files are listed row by row with the full path name for each.

Example File (let's call this file_list.txt):


Now you can run qsub on the grid to get the mean cortical thickness values for each hemisphere ucf in your file list.

> qsub -b y -q medium.q /ifs/woods/R/R-2.7.2/bin/R CMD BATCH --no-save --no-restore --quiet --args -list/your_path/subj_directory/filelist.txt /ifs/woods/rshape/batch_commands/compute_mean_attribute_batch.R file_list_mean_ct.txt

(This shouldn't take too long, you could probably put it in the short.q, but I haven't tried..)

Voila! See your output text file for the mean cortical thickness values in the same order as the files in your input list. You can now enter these into your master spreadsheet and perform stats using SPSS, excel, etc.


Calculate Mean Value within ROI

To calculate the Mean value within an ROI you will first need to create a ROI. See Create UCF Region of Interest (ROI).

Next, you will need to set up a script for each ROI in which you want to calculate the mean. A sample script can be found here: extract_mean_for_roi

Below are the line you need to edit:

extract_mean_for_roi("List_of_ucf_files.txt", "ROI.ucf", 0.5)

Where the list of text files will be a spreadsheet that lists the full path to you ucf files. ROI.ucf will be the full path to the ROI you have already created. This script will then take all the ucf listed in your text files and calculate the mean within the ROI.ucf provided for each subject.

Next, you will need to execute the script you have just created using the following command - run on or

qsub -b y -q short.q /ifs/woods/R/R-2.7.2/bin/R CMD BATCH --no-save --no-restore --quiet full_path/extract_mean_for_roi.R full_path/Mean_within_ROI.txt