help > Design/contrast matrix for paired groups with binary clinical variable
Showing 1-4 of 4 posts
Display:
Results per page:
Apr 17, 2022  03:04 PM | Lawrence Binding
Design/contrast matrix for paired groups with binary clinical variable
Hi team, 

I've been trying to wrap my brain around design matrices for my experimental design and I think I have a rough hold of it, I just need some explanation on the contrasts if possible?  

Data: Diffusion connectome pre and post surgery (X_pre, X_post) and whether patients had language decline (Y). 

Hypothesis: Patients with language decline had increased resection of connections. 

Setup: I have concatenated the patients data so lets say I have 5 patients (5 pre and 5 post connectomes each with 164x164 nodes). So the data looks like 164x164x10. With the first 5 data points being preop and the last 5 being postop. Now I have set the design matrix accordingly: pre/post ; language decline  ; patient 1 ; patient 2; patient 3 ; patient 4 ; patient 5 resulting in: 

1; -1;   1;0;0;0;0
1; 1;    0;1;0;0;0
1; 1 ;   0;0;1;0;0
1; -1;   0;0;0;1;0
1; 1;    0;0;0;0;1
-1; -1;  1;0;0;0;0
-1; 1;   0;1;0;0;0
-1; 1;   0;0;1;0;0
-1; -1;  0;0;0;1;0
-1; 1;   0;0;0;0;1


This was set accordingly to contrast the pre (1) and post (-2) network, and contrast those who did (1) vs. did not (-1) have language decline. The patient columns are to remove specific patient means as per https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/GLM#Single-Group_Paired_Difference_.28Paired_T-Test.29 (see end of page). 

Now to the hypothesis, I expect to see post surgery (-1) have lower values than pre surgery (1) for patients with language decline (1) than those without (-1). Would my contrast be [1, -1, 0, 0, 0, 0, 0]? I think I understand this as saying we expect preop to have more connections with language decline as having less? Is this right or am completely off track?
Apr 18, 2022  12:04 AM | Andrew Zalesky
RE: Design/contrast matrix for paired groups with binary clinical variable
Hi Lawrence, 

the design matrix is not quite right - it will be rank deficient. 

Note that it seems language decline does not change between pre and post assessments, and thus it should not be modelled in a repeated measures design. 

I suspect that you are interested in testing the interaction effect between language decline and surgery. E.g. does surgery impact connectivity to a greater/lesser extent in individuals with/without language decline. 

To test for this interaction effect, the 2nd column of your design matrix should be replaced with the element-wise multiplication of the current 1st and 2nd columns. 

So the 2nd column would be replaced by: [-1 1 1 -1 1 1 -1 -1 1 -1].

The contrast would then be: [0 1 0 0 0 0] or [ 0 -1 0 0 0 0], and select the t-test. 

You might want to also test for the main effect of surgery, in which case the contrast would be: [1 0 0 0 0 0 ] or [ 0 -1 0 0 0 0] and select the t-test.

It does not make sense to test for the main effect of language in a repeated measures design because language remains the same at pre and post. So a cross-section design could be used. If you want to test for the main effect of language, you could average the pre and post matrices for each individual, or test the pre and post data separately. 

Also, remember to replace the semi-colons with commas in your design matrix. 

Let me know if you have any further questions. 

best wishes, 
Andrew


Originally posted by Lawrence Binding:
Hi team, 

I've been trying to wrap my brain around design matrices for my experimental design and I think I have a rough hold of it, I just need some explanation on the contrasts if possible?  

Data: Diffusion connectome pre and post surgery (X_pre, X_post) and whether patients had language decline (Y). 

Hypothesis: Patients with language decline had increased resection of connections. 

Setup: I have concatenated the patients data so lets say I have 5 patients (5 pre and 5 post connectomes each with 164x164 nodes). So the data looks like 164x164x10. With the first 5 data points being preop and the last 5 being postop. Now I have set the design matrix accordingly: pre/post ; language decline  ; patient 1 ; patient 2; patient 3 ; patient 4 ; patient 5 resulting in: 

1; -1;   1;0;0;0;0
1; 1;    0;1;0;0;0
1; 1 ;   0;0;1;0;0
1; -1;   0;0;0;1;0
1; 1;    0;0;0;0;1
-1; -1;  1;0;0;0;0
-1; 1;   0;1;0;0;0
-1; 1;   0;0;1;0;0
-1; -1;  0;0;0;1;0
-1; 1;   0;0;0;0;1


This was set accordingly to contrast the pre (1) and post (-2) network, and contrast those who did (1) vs. did not (-1) have language decline. The patient columns are to remove specific patient means as per https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/GLM#Single-Group_Paired_Difference_.28Paired_T-Test.29 (see end of page). 

Now to the hypothesis, I expect to see post surgery (-1) have lower values than pre surgery (1) for patients with language decline (1) than those without (-1). Would my contrast be [1, -1, 0, 0, 0, 0, 0]? I think I understand this as saying we expect preop to have more connections with language decline as having less? Is this right or am completely off track?
Apr 21, 2022  10:04 AM | Maja Nikolova
RE: Design/contrast matrix for paired groups with binary clinical variable
Hello,

I`m using NBS but my code return`s me nan as resultat. What I am going wrong?
Thanx,
Maja
This is my code
pval, adj, null = nbs.nbs_bct(GroupGMAdjacencyMatrix, GroupWMAdjacencyMatrix, thresh = 2.3 , k = 10, paired = True, tail = "right")
print(pval)

print(len(pval))
new_num = len(pval)
for i in range(len(pval)):
if(len(adj[adj==i+1])<3 or pval>0.05):
adj = np.where(adj!=i+1, adj, 0)
new_num -= 1

print(new_num)
count = 0
print("Component lengths")
for i in range(len(pval)):
if(len(adj[adj==i+1])>2 and pval[i]>0.05):
print(len(adj[adj==i+1]))
[/i]
[i]adj = (adj - np.min(adj))/np.ptp(adj)
print (adj)
[/i]
Apr 22, 2022  12:04 AM | Andrew Zalesky
RE: Design/contrast matrix for paired groups with binary clinical variable
Hi Maja, 

this appears to be customized code and thus difficult to debug without further details and test data. 

In general, a nan indicates that the test statistic could not be computed. This could be because one or more subjects had a nan or inf value in their connectivity matrix. You would need to check the input connectivity matrices for each subject. 

Alternatively, it could be because there is no variation across subjects in the connectivity value. If all subjects have a connectivity value of exactly 1 for a particular connection, then a variance cannot be estimated to compute the test statistic. 

best,
Andrew
Originally posted by Maja Nikolova:
Hello,

I`m using NBS but my code return`s me nan as resultat. What I am going wrong?
Thanx,
Maja
This is my code
pval, adj, null = nbs.nbs_bct(GroupGMAdjacencyMatrix, GroupWMAdjacencyMatrix, thresh = 2.3 , k = 10, paired = True, tail = "right")
print(pval)

print(len(pval))
new_num = len(pval)
for i in range(len(pval)):
if(len(adj[adj==i+1])<3 or pval>0.05):
adj = np.where(adj!=i+1, adj, 0)
new_num -= 1

print(new_num)
count = 0
print("Component lengths")
for i in range(len(pval)):
if(len(adj[adj==i+1])>2 and pval[i]>0.05):
print(len(adj[adj==i+1]))
[/i]
[i]adj = (adj - np.min(adj))/np.ptp(adj)
print (adj)
[/i]