T-Test2 on a singleton dimension

조회 수: 12 (최근 30일)
Manny Hernandez
Manny Hernandez 2021년 6월 3일
댓글: the cyclist 2021년 6월 4일
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
Scott MacKenzie
Scott MacKenzie 2021년 6월 3일
I see some issues in your code and question. For example, ttest2 only returns one p-value. So, p and p' are the same.
the cyclist
the cyclist 2021년 6월 4일
@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)
1.0000 0.0024 0.0002 1.0000 0.0024 0.0002 1.0000 0.0024 0.0002 1.0000 0.0024 0.0002

댓글을 달려면 로그인하십시오.

답변 (0개)

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by