Some formulas of linear regression

March 12th, 2010

y: dependent variable
X: independent variable
r: residual

$$y=X\beta+r$$
$$\beta=inv(X’*X)*X’*y$$
$$\sigma^2=r’*r/df$$
$$df=N-rank(X)$$
$$\sigma_\beta^2=\sigma^2inv(X’X)$$
$$T_\beta=\beta/\sigma_\beta$$
$$contrast variance = c’*\sigma_\beta^2*c$$
$$T_{contrast}=c’\beta/\sqrt{contrast variance}$$

Author: Xu Cui Categories: matlab Tags:

spm_get, spm_select, and char

March 11th, 2010

The mostly used functions I use in SPM is spm_get (for spm2) and spm_select (spm5 and 8).  These two functions are used to get files (usually image files). Frankly speaking I like spm_get much better as it’s intuitive and easy to use. Here is how to use them:

Select some image files interactively (a window pops up and users select),

    p = spm_get([],'*.img','Select the image(s)');
    p = spm_select([0:200],'IMAGE','Select the image(s)');

Select some files automatically,

    p = spm_get('files', pwd, '*.img');
    p = spm_select('list', pwd, '.*img');

The filter in spm_select is different from that in spm_get. In spm_get, the filter is traditional linux/windows file filters such as *.img, ???.hdr etc. In spm_select the filters are regular expressions. For example, to get all files starting with I and end with .img, you put something like ‘^I.*\.img’.

To concatenate two file lists vertically, you can use char function:

    p = char(p1, p2);

char will automatically fill blanks so p1 and p2 are of the same columns to be vertically concatenated.

Below are more examples of spm_get and spm_select:

% select some files interactively and save the file names into a variable P
P = spm_get
% select 6 (not 5, not 7, exactly 6) files interactively
P = spm_get(6)
% select 2 to 4 files interactively
P = spm_get([2:4])
% select 0 to 8 files interactively
P = spm_get([0:8])
% automatically get all imaging files in the directory c:\abc
P = spm_get('Files', 'c:\abc', '*.img')
% automatically get all mat files starting with e in the current working directory
P = spm_get('Files', pwd, 'e*.mat')
% automatically get the mat files in the directory c:\abc which satisfy the following condition: the file names end with f and another two characters. Pay attention to the usage of * and ?
P = spm_get('Files', 'c:\abc', '*f??.mat')
% select some (<200) folders interactively. Now you see, negative numbers means to select folder instead of files
P = spm_get([-200:0])

% select some files interactively and save the file names into a variable P
P = spm_select
% select 6 (not 5, not 7, exactly 6) files interactively
P = spm_select(6)
% select 2 to 4 files interactively
P = spm_select([2 4])
% automatically get all imaging files in the directory c:\abc. Files are saved in P and directories are saved in dirs
[P, dirs] = spm_select('list', 'c:\abc', 'img')
Author: Xu Cui Categories: brain, matlab Tags:

FSL environment setting

March 10th, 2010
setenv FSLDIR /fs/quarry/cuixu/fsl41/fsl
source ${FSLDIR}/etc/fslconf/fsl.csh
setenv PATH ${FSLDIR}/bin:${PATH}
Author: Xu Cui Categories: brain Tags:

Messy desktop

March 10th, 2010

Author: Xu Cui Categories: life Tags:

Too many emails

March 7th, 2010

My gmail inbox has 12,000 emails. I receive ~30 emails (after removing junk mails) each day. Though I have set to display 100 emails per page but some important but unreplied emails soon disappear from the first page. I often “star” important emails to reply them later. I did not do categorizing or tagging, the only way I do to find an old email is to search.

As my life is so much dependent on emails (and particularly gmail), I can’t help wondering:

  1. What if gmail is down, even only for a few days?
  2. How can I manage emails more efficiently?
Author: Xu Cui Categories: life Tags:

Famous brains

March 2nd, 2010

Text source: http://imaging.mrc-cbu.cam.ac.uk/imaging/MniTalairach

  1. Talairach brain (single)
    the brain dissected and photographed for the famous Talairach and Tournoux atlas.
    The atlas has Brodmann’s areas labelled, albeit in a rather approximate way.
  2. MNI 305 brain (average of 305 brains, all right handed, 239 M, 66 F, age 23.4 +/- 4.1)

    avg305

    avg305

  3. ICBM152
    the average of 152 normal MRI scans that have been matched to the MNI305 using a 9 parameter affine transform.
    adopted this as their standard template; it is the standard template in SPM99 and later.

    avg152

    avg152

  4. colin27 (single subject)
    one of the MNI lab members, Colin Holmes, was scanned 27 times, and the scans were coregistered and averaged to create a very high detail MRI dataset of one brain. This average was also matched to the MNI305, to create the image known as “colin27″. colin27 is used in the MNI brainweb simulator. SPM96 used colin27 as its standard template. SPM96 and later contains a 2mm resolution copy of the same image, in the canonical directory of the SPM distribution. In SPM96 this is called T1 in later distributions it is called single_subj_T1. Note that the images in the SPM “templates” directories have all been presmoothed to 8mm for use with the normalization routines.

    single_subject-T1

    single_subject-T1

  5. H.M. (Henry Gustav Molaison)
    A famous patient with memory loss. His hippocampus was largely removed in a surgery. As a result he couldn’t commit new events to long term memory. The slices of his brain is now at UCSD.
Author: Xu Cui Categories: brain Tags:

Delphi 7 on Windows 7, compatibility

February 28th, 2010

from Hans’ blog: http://weblog.hansotten.com/?p=833

Delphi 7 is not quite compatible with Win 7. But you can solve this problem by following Hans’ steps:

  1. Run this as administrator.
  2. Open the properties on c:/program files/delphixxx directory.
  3. On the first tab Clear the Read-only attribute and press Apply for all files including subdirectory.
  4. Open the security tab
  5. Give users (and admins if necessary) full access to  c:/program files/delphixxx directory
Author: Xu Cui Categories: programming Tags:

Conversion of coordinates between two images

February 17th, 2010

Assume you have an image F and you identify a point (x,y,z) on this image (say with SPM’s display function). You then normalize this image F according to a template image G using SPM. Now you want to know that point’s corresponding coordinate after normalization (x1, y1, z1). How do you do that?

If that point is still identifiable visually in the normalized image, then you can simply use SPM’s display function to get the coordinate. But if it’s not, or you have a lot of points to identify, you can use the following methods:

After normalization you will find a file called s_sn.mat. Load it, you will find several variables including Affine, VF, VG, etc. Now calculate conversion matrix  M as

M = VG.mat * inv(Affine) * inv(VF.mat)

Now you can calculate the new coordinate as

New = M * [old; 1]

(old is column vector [x;y;z]; new is column vector [x1;y1;z1;1])

Author: Xu Cui Categories: brain Tags:

Malicious website mimicing twitter

February 13th, 2010

You may receive a direct message from one of your friends saying:

Hi, xxx! A new twitter service! Try it, nice one! http://twltter.ru/

Don’t click the link! I clicked and it’s exactly identical to twitter’s own interface. I thought it was twitter so I entered my username/password, but nothing happened. After a few hours I realize this might be a malicious website. So I changed my twitter password.

Social networks make us more connected — but also more vulnerable for virus to spread. Be careful.

Author: Xu Cui Categories: web Tags:

E-prime vs MatLab (+Psychophysics Toolbox)

February 9th, 2010

Both E-prime and MatLab are popular tools for presenting stimuli for fMRI, NIRS and behavioral experiments. Here are a comparison between them.

E-Prime MatLab + psychophysics toolbox
price ~$1000 MatLab cost, $50-500
easy to use easy moderate
need coding no (most cases) yes
flexibility moderate very
timing control moderate can be very accurate
connecting hardware good good
full screen yes can be
Author: Xu Cui Categories: brain, matlab, psychToolbox Tags: