Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
ttest2,Anovan question

Subject: ttest2,Anovan question

From: Walk

Date: 19 Dec, 2012 02:45:11

Message: 1 of 2

I have 3 vectors
a=[1 2 3 4 5];
b=[2 4 6 8 10 12 14 16];
c=[1 2 4 8 16 32];

All I want to do is determine whether or not there is evidence to conclude whether these samples come from the same distribution. With only two vectors, this would be done with ttest2(a,b). How do I expand this into checking between 3 or more vectors? From what I've read, anovan is supposed to do this, but when I read the documentation and look at the example, it appears to be meant for something entirely different, or is explained in a way that I can't follow. Unfortunately, all of the other example's I've managed to find simply regurgitate this one example, which is of no use to me. Am I missing something obvious, or do I have to go through ttest2 and compare a to b, then a to c, then b to c?

Subject: ttest2,Anovan question

From: Claudio

Date: 19 Dec, 2012 16:13:08

Message: 2 of 2

"Walk" wrote in message <kar9nn$jgg$1@newscl01ah.mathworks.com>...
> I have 3 vectors
> a=[1 2 3 4 5];
> b=[2 4 6 8 10 12 14 16];
> c=[1 2 4 8 16 32];
>
> All I want to do is determine whether or not there is evidence to conclude whether these samples come from the same distribution. With only two vectors, this would be done with ttest2(a,b). How do I expand this into checking between 3 or more vectors? From what I've read, anovan is supposed to do this, but when I read the documentation and look at the example, it appears to be meant for something entirely different, or is explained in a way that I can't follow. Unfortunately, all of the other example's I've managed to find simply regurgitate this one example, which is of no use to me. Am I missing something obvious, or do I have to go through ttest2 and compare a to b, then a to c, then b to c?


Hello Walk,

You can use the anova1(X) function. From the Matlab help: "In a one-way analysis of variance, you compare the means of several groups to test the hypothesis that they are all the same, against the general alternative that they are not all the same".

You should arrange your vectors in a matrix, but remember to put NaNs to fill in shorter vectors. Using your example vectors :
X=[...
1 2 3 4 5 NaN NaN NaN; ...
2 4 6 8 10 12 14 16 ;...
1 2 4 8 16 32 NaN NaN]';

p = anova1(X);

Look at the Matlab help for interpreting the p-value. You might want to look at the kruskalwallis() function as well (a non-parametric version of the ANOVA).

Good luck!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us