Two functions within a if statement
2 views (last 30 days)
Show older comments
I would like to run different statistical tests within an if statement. If certain assumptions were met run a parametric test, if not a non-parametric test should be run. The script I present below runs both analyses.
for ic = 1:size (Dg,2);
if Dg (1,ic) == 1
[p, h, stats] = signrank (Dd (:,ic),De(:,ic));
results(1,ic)=p;
results(2,ic)=h;
results(3,ic)=stats.zval;
results(4,ic)=stats.signedrank;
else
[h1,p1,ci1,stats1] = ttest(Dd,De);
end
end
In the end, I get two sets of outputs, and it looks like both statistical tests were run either Dg is equal to zero or not. I was expecting to a few missings in each set of outputs.
4 Comments
Rik
on 20 Oct 2018
There will be empty rows in your results matrix if any(Dg(1,ic)~=1)
For the else part, you could employ the same strategy of indexing the result, either to the same matrix or a different one. Currently you are overwriting the results.
Answers (1)
See Also
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!