T-Test2 on a singleton dimension
Show older comments
I am conducting a two-sample t-test on some self-organizing maps data. I am trying to obtain p-values at every grid cell between each node:
somVariable = sMap.codebook % 30 x7326 [double] ; node x [latxlon]
[sNum,sGrid] = size(somVariable);
pTest = NaN(sGrid,sNum);
for i = 1:sNum
[~,p] = ttest2(somVariable(1,:),somVariable(i,:),'VarType','equal');
pTest(:,i) = p';
clear p
end
but encounter an issue in which matlab jumps to the non-singleton dimension (7326) and I obtain one p-value. Is there a way to force matlab to recognize a singleton dimension as the starting dimension to test at each grid cell?
Thanks!
2 Comments
Scott MacKenzie
on 3 Jun 2021
I see some issues in your code and question. For example, ttest2 only returns one p-value. So, p and p' are the same.
@Manny Hernandez, I'm confused by which elements of your data you are trying to apply the t-test to. Let's take a small example. Suppose somVariable were:
somVariable = [ 2 3 5 7;
11 13 17 19;
23 29 31 37];
Exactly which t-tests are you trying to do? The way your code is written, you calculate three p-values:
- Row 1 vs. Row 1 (p = 1)
- Row 1 vs. Row 2 (p = 0.0024)
- Row 1 vs. Row 3 (p = 0.0002)
and then those three p-values are replicated four times (because you have defined pTest to have as many rows as somVariable has columns).
somVariable = [ 2 3 5 7;
11 13 17 19;
23 29 31 37];
[sNum,sGrid] = size(somVariable);
pTest = NaN(sGrid,sNum);
for i = 1:sNum
[~,p] = ttest2(somVariable(1,:)',somVariable(i,:)','VarType','equal');
pTest(:,i) = p';
clear p
end
disp(pTest)
Answers (0)
Categories
Find more on Hypothesis Tests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!