| Statistics Toolbox | Search  Help Desk |
| anova1 | Examples |
One-way Analysis of Variance (ANOVA).
Syntax
p = anova1(X) p = anova1(x,group)
Description
anova1(X) performs a balanced one-way ANOVA for comparing the means of two or more columns of data on the sample in X. It returns the p-value for the null hypothesis that the means of the columns of X are equal. If the p-value is near zero, this casts doubt on the null hypothesis and suggests that the means of the columns are, in fact, different. anova1(x,group) performs a one-way ANOVA for comparing the means of two or more samples of data in x indexed by the vector, group. The input, group, identifies the group of the corresponding element of the vector x. The values of group are integers with minimum equal to one and maximum equal to the number of different groups to compare. There must be at least one element in each group. This two-input form of anova1 does not require equal numbers of elements in each group, so it is appropriate for unbalanced data. The choice of a limit for the p-value to determine whether the result is "statistically significant" is left to the researcher. It is common to declare a result significant if the p-value is less than 0.05 or 0.01. anova1 also displays two figures. The first figure is the standard ANOVA table, which divides the variability of the data in X into two parts:Examples
The five columns of x are the constants one through five plus a random normal disturbance with mean zero and standard deviation one. The ANOVA procedure detects the difference in the column means with great assurance. The probability (p) of observing the sample x by chance given that there is no difference in the column means is less than 6 in 100,000.x = meshgrid(1:5) x = 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 x = x + normrnd(0,1,5,5) x = 2.1650 3.6961 1.5538 3.6400 4.9551 1.6268 2.0591 2.2988 3.8644 4.2011 1.0751 3.7971 4.2460 2.6507 4.2348 1.3516 2.2641 2.3610 2.7296 5.8617 0.3035 2.8717 3.5774 4.9846 4.9438 p = anova1(x) p = 5.9952e-05
The following example comes from a study of material strength in structural beams Hogg (1987). The vector, strength, measures the deflection of a beam in thousandths of an inch under 3,000 pounds of force. Stronger beams deflect less. The civil engineer performing the study wanted to determine whether the strength of steel beams was equal to the strength of two more expensive alloys. Steel is coded 1 in the vector, alloy. The other materials are coded 2 and 3.
![]()
strength = [82 86 79 83 84 85 86 87 74 82 78 75 76 77 79 ... 79 77 78 82 79]; alloy =[1 1 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3];Though alloy is sorted in this example, you do not need to sort the grouping variable.
p = anova1(strength,alloy) p = 1.5264e-04The p-value indicates that the three alloys are significantly different. The box plot confirms this graphically and shows that the steel beams deflect more than the more expensive alloys.
![]()
![]()
References
Hogg, R. V., and J. Ledolter. Engineering Statistics. MacMillan Publishing Company, 1987.