Nested t-test

18 views (last 30 days)
James Alix
James Alix on 14 Feb 2022
Commented: James Alix on 21 Feb 2022
Hi
I have have a series of observations two groups: healthy and diseased. For each individual I have more than one observation.
I want to do a t-test between the two groups but because I have more than one observation I need to nest each participants multiple observations with that participant (hopefully that makes sense!).
I seem to have hit a road block on how to do this.
My code for a simple t-test looks is below.
"Test_t" is my data matrix with all the observations for both groups
"names" is my data cell with all the study participant IDs in.
The first column in "names" has a label for each participant, in the second I add a group level label e.g:
Disease1_a 1
Disease1_b 1
Disease1_c 1
Disease2_a 1
Disease2_b 1
Disease2_c 1
Healthy1_a 2
Healthy1_b 2
Healthy1_c 2
... and so on.
Z= [names{:,2}]';
diseased=Test_t(Z==1,:);
healthy=Test_t(Z==2,:);
h=[];
p=[];
for i=1:1
[h(i,1),p(i,1)]=ttest2(diseased(:,i),healthy(:,i));
end
Does anyone know how to do the nesting?
Similarly, I have some data in which there are multiple observations e.g. I have 3 measurements per for disease_a, disease_b etc. For that I would need nested anova but I don't seem to be able to implement this either.
Thanks
  2 Comments
Scott MacKenzie
Scott MacKenzie on 19 Feb 2022
Edited: Scott MacKenzie on 20 Feb 2022
An initial question is whether you consider "measurement" an experimental factor.
If multiple measurements were made simply to smooth over potental inaccuracy or variability in the measurements, then testing whether the "a" measures differed from the "b" or "c" measures is likely of no particular interest. In this case, you can collapse the a, b, and c measures nto a sigle measure, m, and proceed with the t-test using ttest2. Clearly, there is no "nesting" in this case.
However, perhaps you are interested in testing for a measurement effect. This is reasonable if, for example, measurements were take at different points in time and you were interest in seeing if the "a" measures differed from the "b" or "c" measures? In this case, your experiment is a 2 x 3 mixed design. The factors are "health status" with two levels (healthy, diseased) and "measurement" with three levels (a, b, c). It is a mixed design because "health status" is between-subjects and "measurement" is within-subjects. The recommended MATLAB function in this case is ranova. The "nesting" you refer to is inherently included, since the anova tests for the main effect of "health status", the main effect of "measurement", and the Health Status x Measurement interaction effect.
BTW, it might help if you post the data (or a reasonable subset of the data).
James Alix
James Alix on 21 Feb 2022
Dear Scott,
Many thanks for replying.
Your first suggestion is what I've been doing.
Your section fits the bill and seems to work.
BW
James

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!