Two functions within a if statement

2 views (last 30 days)
Belina Rodrigues
Belina Rodrigues on 20 Oct 2018
Answered: Belina Rodrigues on 14 Nov 2018
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
Belina Rodrigues
Belina Rodrigues on 20 Oct 2018
Hi Rik,
It is true, it works.
It seems to run both analyses even when Dg is different from 1. I was expecting two different set of results with a few missings in each.
Thanks
Rik
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.

Sign in to comment.

Answers (1)

Belina Rodrigues
Belina Rodrigues on 14 Nov 2018
Many thanks.

Community Treasure Hunt

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

Start Hunting!