In this example we have five different ropes, ropes A through E, and each rope was tested
four different times to determine its breaking strength. We wanna use MATLAB and an Analysis
of Variance to figure out if the mean breaking strength from any of the five ropes differs.
The first thing that you will always want to do before making a test like this is to
graph your data. So here I've graphed rope types A through E, and for each of the ropes
we have four different measurements, and here I am plotting the breaking strength in pounds
on the vertical axis. So we can look at this and what we're ultimately trying to figure
out is if the mean breaking strength of one of the ropes is different from the others.
When we run an analysis of variance what we're trying to figure out is if the data points
measured for each rope come from a normal population in which the mean value, mu(A),
mu(B), for rope C, and D and E, the mean for the distributions, whether or not they are equal.
It is possible that all of the means are equal, it's unlikely though. It is possible that
we could gather four data points at this end of the distribution, it's unlikely. This would
also be a little bit more unlikely, a data point down here, and now we've collected data
points at the high end of these two distributions here, so it is possible, but it will be unlikely,
and by looking at it this way I suspect right off the bat that we'll get a low p-value from
the analysis of variance, and that low p-value provides evidence that we could reject the
null hypothesis, that the population means for all five ropes are the same, and instead
go with the alternative hypothesis in which at least one of the population means differs
from one another. So to begin doing this analysis in MATLAB I've written a script in which I
first clear all the variables and close any open plots, and then I make a matrix, and
I then make a matrix, I called it y, and in the vertical each column of the matrix represents
the four measurements conducted on each of the five ropes, so each column contains four
measurements, and each rope contains data from the five ropes, and I've also made a
saliency called ropes in which I've labeled each rope A through E. The function that we'll
want to use in MATLAB for a one way variance analysis of variance is called anova1, and
provided I've got each of the treatments, or each of the five ropes arranged in columns
in that matrix y, and each of the four measurements in rows, I can call anova1 with my matrix
y, and then the groups of ropes A through E as the second variable, or the second input
to that function, and when I run that script I've stored my p-value as a variable p and
on the command line I enter the letter p and I come up with a p-value that is much less
than 0.05. So there is very strong evidence that at least one of the breaking strength,
one mean breaking strength for one of the ropes differs from the other. In addition
to the p-value, the function anova1 will also return our analysis of variance table, and
it will return a figure that looks something like the following. This figure is a little
bit difficult to interpret, but for each of the five ropes I've got a red value, and that
represents the median value for each of the four measurements, for each of the ropes,
so the median for the ropes. The whiskers represent the maximum values and the minimum
values for each of these,sometimes it's hard to see the whiskers. The ends, or the flat
lines here represent the 75th percentile of the data, and the lower flat part of it represents
the 25th percentile. In these figures this is known as a notch, these angled lines, and
the top and the bottom of the angled lines also have significance, and they represent
the upper confidence limit and the lower confidence limit, so the 95th percent confidence interval
of the median, so we're 95 percent confident that the true median value for the breaking
strength for rope B ranges from this upper circle to the lower circle. Maybe a little
bit clearer if I zoom in on rope, the data presentation for rope D. So here we have the
maximum value, the minimum value, this is our inter-quartile range of the 25th percentile
and the 75th percentile. The median is in the red, and the upper confidence limit, 95
percent upper confidence limit of the median is at that angle, and the lower 95 percent
lower confidence limit of the median is at that location. I usually find that this is
just too much information to digest easily. If you want you can reproduce this box plot
using the command box plot, and we'll input y and ropes for the labels. And if you
want to you could completely reproduce it by including the notches, so I use the keyword
notch and on. When I run that script it generates a figure shown on the right, and note that
this figure doesn't have any labels for the x axis and the y axis, there's no units, and
more subtly the bottom of the y axis is at 250, or a little less than 250, and what that
does is exaggerate visually the difference between the difference between the breaking
strength of rope D and the breaking strength of rope A or B for example, so what we really
want to do is include axis labels, and we want to set the y axis limit to zero so we can get
a more fair visual comparison of the breaking strength of the ropes. To make that happen
I've used the y limit command, I set the lower limit at zero and the upper limit 10 percent
higher than the maximum value that we see in our data sets. I've also included the x
label and the y label, along with some font size, and I've made it bold to make it a little
easier to read. To get rid of the notches I can either select notch, I can turn it off,
or by default the notches aren't there in the first place with a box plot, so I get
rid of those, and when I run it I get traditional box plots. The whiskers represent the minimum
and the maximum values, and the lower and upper part of the box represents the 25th
and the 75th percentile, and the red lines represent the median for each of the five
ropes. Side by side comparison of the two box plots shows that it's a little bit easier
to interpret the box plot on the right. Everything else is a variance, our p-value, p was equal
to 0.0076, which is much, much less than 0.05, or our alpha of five percent, which allows
us to conclude with a great deal of confidence that at least one of the sample mean breaking
strength differs from the other, and upon visual inspection of the data it certainly
looks like ropes C and D are substantially weaker than ropes A, B, and E.