help >

**Design matrix for a few repeat scans**Showing 1-5 of 5 posts

Jan 30, 2021 03:01 PM | jdc77

Design matrix for a few repeat scans

Hi Dr. Zalesky,

First of all, thank you for providing researchers with this very useful tool.

I wanted to write a contrast that compares two groups A and B. A subset of the subjects were scanned twice. I have 200 data sets, and 25 were from the same subject . I was wondering how to account for the repeat scans in the design matrix and include this as a covariate in the contrast. My other covariates are age and gender.

I did:

1 0 1 24

1 0 2 18

1 0 1 35

1 0 1 42

0 1 2 16

0 1 2 18

0 1 1 29

0 1 1 32

Where

Column 1 = group A

Column 2 = group B

Column 3 = gender (1 = male)

Column 4 = age

In the example above, rows 3 and 4 are the same subject, scanned twice at age 35 and 42. Rows 7 and 8 are also the same individual, scanned at different times.

I plan to do a [-1 1 0 0] contrast to compare the two groups. May I ask what is the proper way to add repeat scans in the design matrix?

Thank you!

Best,

Jay

First of all, thank you for providing researchers with this very useful tool.

I wanted to write a contrast that compares two groups A and B. A subset of the subjects were scanned twice. I have 200 data sets, and 25 were from the same subject . I was wondering how to account for the repeat scans in the design matrix and include this as a covariate in the contrast. My other covariates are age and gender.

I did:

1 0 1 24

1 0 2 18

1 0 1 35

1 0 1 42

0 1 2 16

0 1 2 18

0 1 1 29

0 1 1 32

Where

Column 1 = group A

Column 2 = group B

Column 3 = gender (1 = male)

Column 4 = age

In the example above, rows 3 and 4 are the same subject, scanned twice at age 35 and 42. Rows 7 and 8 are also the same individual, scanned at different times.

I plan to do a [-1 1 0 0] contrast to compare the two groups. May I ask what is the proper way to add repeat scans in the design matrix?

Thank you!

Best,

Jay

Jan 30, 2021 10:01 PM | Andrew Zalesky

RE: Design matrix for a few repeat scans

Hi Jay,

to model repeat scans, add an additional column to the design matrix to represent each individual. So you would have an extra column with a one at rows 3 and 4, and zeros everywhere else. And another extra column with a one at rows 7 and 8, and zeros elsewhere.

Note that if you end up adding an extra column for all subjects then you will need to remove either column 1 or 2. In this case, your contrast will be [1 0 0 ...] or [-1 0 0 ...]

A more principled (but complex) approach is to use a mixed effects model.

Andrew

to model repeat scans, add an additional column to the design matrix to represent each individual. So you would have an extra column with a one at rows 3 and 4, and zeros everywhere else. And another extra column with a one at rows 7 and 8, and zeros elsewhere.

Note that if you end up adding an extra column for all subjects then you will need to remove either column 1 or 2. In this case, your contrast will be [1 0 0 ...] or [-1 0 0 ...]

A more principled (but complex) approach is to use a mixed effects model.

Andrew

*Originally posted by jdc77:*Hi Dr. Zalesky,

First of all, thank you for providing researchers with this very useful tool.

I wanted to write a contrast that compares two groups A and B. A subset of the subjects were scanned twice. I have 200 data sets, and 25 were from the same subject . I was wondering how to account for the repeat scans in the design matrix and include this as a covariate in the contrast. My other covariates are age and gender.

I did:

1 0 1 24

1 0 2 18

1 0 1 35

1 0 1 42

0 1 2 16

0 1 2 18

0 1 1 29

0 1 1 32

Where

Column 1 = group A

Column 2 = group B

Column 3 = gender (1 = male)

Column 4 = age

In the example above, rows 3 and 4 are the same subject, scanned twice at age 35 and 42. Rows 7 and 8 are also the same individual, scanned at different times.

I plan to do a [-1 1 0 0] contrast to compare the two groups. May I ask what is the proper way to add repeat scans in the design matrix?

Thank you!

Best,

Jay

First of all, thank you for providing researchers with this very useful tool.

I wanted to write a contrast that compares two groups A and B. A subset of the subjects were scanned twice. I have 200 data sets, and 25 were from the same subject . I was wondering how to account for the repeat scans in the design matrix and include this as a covariate in the contrast. My other covariates are age and gender.

I did:

1 0 1 24

1 0 2 18

1 0 1 35

1 0 1 42

0 1 2 16

0 1 2 18

0 1 1 29

0 1 1 32

Where

Column 1 = group A

Column 2 = group B

Column 3 = gender (1 = male)

Column 4 = age

In the example above, rows 3 and 4 are the same subject, scanned twice at age 35 and 42. Rows 7 and 8 are also the same individual, scanned at different times.

I plan to do a [-1 1 0 0] contrast to compare the two groups. May I ask what is the proper way to add repeat scans in the design matrix?

Thank you!

Best,

Jay

Jan 31, 2021 12:01 AM | jdc77

RE: Design matrix for a few repeat scans

Thanks for your response!

So, that means my design matrix will be:

1 1 0 0 1 24

1 0 1 0 2 18

1 0 0 1 1 35

1 0 0 1 1 42

0 1 0 0 2 16

0 0 1 0 1 18

0 0 0 1 1 29

0 0 0 1 1 32

I added a column for all subjects including those with single scans only. Or do I only add for those with 2 scans?

My contrast will be [1 0 0 0 0 0] if I wanted to compare group A vs B (A > B).

Would these be correct?

Thank you again! I appreciate your help.

Jay

So, that means my design matrix will be:

1 1 0 0 1 24

1 0 1 0 2 18

1 0 0 1 1 35

1 0 0 1 1 42

0 1 0 0 2 16

0 0 1 0 1 18

0 0 0 1 1 29

0 0 0 1 1 32

I added a column for all subjects including those with single scans only. Or do I only add for those with 2 scans?

My contrast will be [1 0 0 0 0 0] if I wanted to compare group A vs B (A > B).

Would these be correct?

Thank you again! I appreciate your help.

Jay

Jan 31, 2021 01:01 AM | Andrew Zalesky

RE: Design matrix for a few repeat scans

Hi Jay,

With this design, ideally you should have repeat scans in all subjects. If you only have repeat scan in some subjects, but not others, you may want to consider a linear mixed effects model, which is a better option in this case (but a lot more complex and slower). There is an R package called NBR which implements NBS in a mixed effects model.

If you stick with the current model, I would add a column for all subjects, not just those with repeat scans. Once again though, this is not an optimal model when not all subjects have repeat scans.

When modeling sex, use 0 and 1, rather than 1 and 2.

Yes - the contrast is correct.

Andrew

With this design, ideally you should have repeat scans in all subjects. If you only have repeat scan in some subjects, but not others, you may want to consider a linear mixed effects model, which is a better option in this case (but a lot more complex and slower). There is an R package called NBR which implements NBS in a mixed effects model.

If you stick with the current model, I would add a column for all subjects, not just those with repeat scans. Once again though, this is not an optimal model when not all subjects have repeat scans.

When modeling sex, use 0 and 1, rather than 1 and 2.

Yes - the contrast is correct.

Andrew

*Originally posted by jdc77:*Thanks for your response!

So, that means my design matrix will be:

1 1 0 0 1 24

1 0 1 0 2 18

1 0 0 1 1 35

1 0 0 1 1 42

0 1 0 0 2 16

0 0 1 0 1 18

0 0 0 1 1 29

0 0 0 1 1 32

I added a column for all subjects including those with single scans only. Or do I only add for those with 2 scans?

My contrast will be [1 0 0 0 0 0] if I wanted to compare group A vs B (A > B).

Would these be correct?

Thank you again! I appreciate your help.

Jay

So, that means my design matrix will be:

1 1 0 0 1 24

1 0 1 0 2 18

1 0 0 1 1 35

1 0 0 1 1 42

0 1 0 0 2 16

0 0 1 0 1 18

0 0 0 1 1 29

0 0 0 1 1 32

I added a column for all subjects including those with single scans only. Or do I only add for those with 2 scans?

My contrast will be [1 0 0 0 0 0] if I wanted to compare group A vs B (A > B).

Would these be correct?

Thank you again! I appreciate your help.

Jay

Jan 31, 2021 02:01 PM | jdc77

RE: Design matrix for a few repeat scans

Thank you!

I will take a look at the R package you suggested.

Jay

I will take a look at the R package you suggested.

Jay