# Defining second-level contrasts on nilearn

Hi all,

We are doing a second level analysis and have a 2x4 design with a design matrix as follows:

We would like to compute a contrast for “f vs nf” and would like to make sure that we have added the subjects in the array correctly.

So our array looks like this:

``````contr = [ 1.  1.  1.  1. -1. -1. -1. -1.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
``````

Is adding the subjects as zeros correct in this case?

Thanks a lot in advance!

Hi,
Yes, your design matrix is well-specified.
Yet, there is an issue: the matrix is not full rank, as the sum of the first eight columns is 1, as is the sum of all the others. This will lead to erratic numerical estimates.
The simplest fix is to get rid of one of the first eight columns, (say: `nf_pl`), so that the contrast `f_col` becomes implicitly `f_col-nf_pl`. This does not affect contrasts such as `f_col-f_high` since the added term cancels out.
HTH,
Bertrand

2 Likes

Thanks for your reply Bertrand, it is not completely clear to me how to set up the contrast for the main effect “f vs nf” after removing the “pl_nf” column, would it be something like;

`contr = [ 1. 1. 1. 0. -1. -1. -1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]`

with pl_f set to zero?

or

`contr = [ 1. 1. 1. 1. -1. -1. -1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]`

Thanks!

Actually, it is `contr = [ 1. 1. 1. 1. -1. -1. -1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]`, as all the above contrasts are xx - pl_nf, such that the linear combination contains the - pl_nf term once.
I’m not really satisfied with this API-wise, see Rank-Deficient second-level design matrices should be allowed · Issue #3361 · nilearn/nilearn · GitHub
Best,
Bertrand

1 Like