0todd0000 / spm1d

One-Dimensional Statistical Parametric Mapping in Python
GNU General Public License v3.0
61 stars 21 forks source link

Contrast vectors for general linear model with multiple covariates #192

Closed 0todd0000 closed 2 years ago

0todd0000 commented 2 years ago

(This is paraphrased from an email discussion.)

  1. For analysis using spm1d.stats.glm, if I have four independent parameters (x1, x2, x3, x4), is it correct to define the design matrix, X = [x1, x2, x3, x4, 1] where the last column contains 1’s as the intercept?
  2. Additionally, to primarily test the effect of x1, correcting for the other independent parameters, should I specify the contrast vector, c = [3, -1, -1, -1, 0] or c = [1, 0, 0, 0, 0]?
0todd0000 commented 2 years ago

(Here are some answers)



(1) Yes, that is a suitable design matrix definition. The order of the variables doesn't matter, provided the contrast vector is updated according to the new order of the variables.



(2) The latter contrast vector: c = [1, 0, 0, 0, 0] is likely the better choice. To see why, consider the contrast vector in the context of simpler designs...


First, consider simple linear regression. Using a similar pseudo-code approach to the one presented above:



Next consider a two-sample t-test.



The two simple examples above clarify that the contrast vector follows directly from the null hypothesis, and vice versa. Once you specify the null hypothesis, then it should be easy to construct the contrast vector.


I am not sure what H0 is your case, but from the proposed contrast vector it sounds like:


The other proposed contrast vector (c = [3, -1, -1, -1, 0]) is also valid, it just corresponds to a different hypothesis. The hypothesis is: H0: 3a1 - a2 - a3 - a4 = 0 I am not certain whether this H0 is suitable for your experiment.

josh-auger commented 2 years ago

Todd,

Thank you for the helpful clarification on contrast vectors. I have a follow-up question about the design matrix that accompanies the contrast vector:

Does the design matrix need to consist of only binary vectors? I notice the example (ex1d_glm.m) in the spm1d package contains continuous values for the parameter, x.

0todd0000 commented 2 years ago

No, continuous variables are fine too. The simple linear regression example above uses a continuous variable x1. The design matrix can consist of binary vectors, continuous vectors, a constant (i.e., intercept) or any mix of these.

josh-auger commented 2 years ago

Good to know, thank you for the help!

0todd0000 commented 2 years ago

No problem!