Avoiding for loop with anova1
Show older comments
I have 2 large 3D matrices, and I've noticed that passing a DIM argument for the ttest2 function decreases the computational time on my computer substantially as opposed to looping through each index in the first 2 dimensions (near 60-fold for the data I'm working with):
[~,~,~,stats]=ttest2(A,B,[],[],[],3);
vs.
stats=cell(rmax,cmax);
for r=1:rmax
for c=1:cmax
[~,~,~,stats{r,c}]=ttest2(A(r,c,:),B(r,c,:));
end
end
Now I would like to do the same thing, but adding another matrix C and using anova1 instead of ttest2. The documentation for anova1 suggests that it won't accept a similar DIM argument, but I'm wondering if there's a similar way to cut down on time and avoid looping through each element.
Thanks!
Zach
4 Comments
Star Strider
on 5 Apr 2015
I don’t know your data or your experimental design, so what you’re doing could be appropriate, especially if you’ve discussed it with your statisticians and they suggest the approach you’re doing.
If that’s not the situation, although I didn’t want to comment earlier, I’m uncomfortable with your running lots of paired t-tests without some sort of correction for multiple comparisons.
See if the multcompare function might be more appropriate. It does the same thing, but incorporates corrections for multiple comparisons,
The anova1 analysis is a good step, but that should have been your first approach, and multiple comparisons the second.
Be sure to talk this over with a statistician before going further if you have not already.
Zach
on 5 Apr 2015
Star Strider
on 5 Apr 2015
I still have no idea what you’re doing, but if you’re doing clustering, you might want to look through the Statistics Toolbox for cluster algorithms such as clusterdata. There are several others, and several related functions, such as those listed at the end of that webpage.
Zach
on 6 Apr 2015
Accepted Answer
More Answers (0)
Categories
Find more on Analysis of Variance and Covariance 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!