groupmeans
Description
Examples
Load the sample data.
load carbig.matCreate a table that has variables for acceleration and horsepower category. Obtain the horsepower categories by sorting the variable Horsepower into three horsepower ranges.
tbl = table(Acceleration); tbl.HorsepowerCats = discretize(Horsepower,[0 100 200 300])
tbl=406×2 table
Acceleration HorsepowerCats
____________ ______________
12 2
11.5 2
11 2
12 2
10.5 2
10 2
9 3
8.5 3
10 3
8.5 2
17.5 2
11.5 2
11 2
10.5 2
11 2
10 2
⋮
Perform a one-way ANOVA to test the null hypothesis that the mean acceleration time is the same across the three horsepower ranges.
aov = anova(tbl,"Acceleration")aov =
1-way anova, constrained (Type III) sums of squares.
Acceleration ~ 1 + HorsepowerCats
SumOfSquares DF MeanSquares F pValue
____________ ___ ___________ ______ __________
HorsepowerCats 975.93 2 487.96 89.571 7.8471e-33
Error 2162.8 397 5.4478
Total 3138.7 399
Properties, Methods
The small p-value indicates that the mean acceleration time is different for at least one of the horsepower categories. Investigate which horsepower ranges have different mean acceleration times by inspecting the means of the horsepower categories.
means = groupmeans(aov)
means=3×5 table
HorsepowerCats Mean SE MeanLower MeanUpper
______________ ______ _______ _________ _________
1 16.804 0.15526 16.498 17.11
2 13.969 0.18282 13.608 14.33
3 11.136 0.70374 9.5683 12.704
The table means shows that each category has a mean that is outside the 95% confidence intervals of the mean estimates for the other categories. Therefore, the mean acceleration time is significantly different for all three horsepower categories.
Load the car mileage sample data.
load mileage.matThe columns of the 6-by-3 matrix mileage contain mileage data for three car models. The first three rows contain data for cars built at one factory, and the last three rows contain data for cars built at another factory.
Convert mileage to a vector.
mileage = mileage(:);
Create string arrays of factor values for the factory and car model factors using the function repmat.
factory = repmat(["factory1";"factory1";"factory1";... "factory2";"factory2";"factory2"], [3, 1]); model = [repmat("model1",6,1);... repmat("model2",6,1);repmat("model3",6,1)]; factors = {factory,model};
Perform a two-way ANOVA to test the null hypothesis that car mileage is not affected by the factory or car model factors.
aov = anova(factors,mileage,FactorNames=["Factory","Model"])
aov =
2-way anova, constrained (Type III) sums of squares.
Y ~ 1 + Factory + Model
SumOfSquares DF MeanSquares F pValue
____________ __ ___________ ______ __________
Factory 1.445 1 1.445 14.382 0.0019807
Model 53.351 2 26.676 265.49 7.3827e-12
Error 1.4067 14 0.10048
Total 56.203 17
Properties, Methods
The small p-values indicate that the model of a car has a more significant effect on car mileage than the factory in which the car was manufactured.
To investigate which car models have different mileages at the 99% confidence level, inspect the group means.
means = groupmeans(aov,"Model",Alpha=0.01)means=3×5 table
Model Mean SE MeanLower MeanUpper
________ ______ _______ _________ _________
"model1" 32.95 0.12941 32.428 33.472
"model2" 34.017 0.12941 33.495 34.538
"model3" 37.017 0.12941 36.495 37.538
The table shows that the 99% confidence intervals of all car models do not overlap. Therefore, all three models have statistically significant differences in mean car mileage at the 99% confidence level.
Input Arguments
ANOVA results, specified as an anova object.
The properties of aov contain the factors and response data used by
groupmeans to compute the mean responses.
Factors used to group the response data, specified as a string vector or cell array of
character vectors. The groupmeans function groups the response
data by the combinations of values for the factors in factors. The
factors argument must be one or more of the names in
aov.FactorNames.
Example: ["g1","g2"]
Data Types: string | cell
Significance level for the estimates, specified as a scalar value in the range (0,1).
The confidence level of the confidence intervals is . The default value for alpha is
0.05, which returns 95% confidence intervals for the
estimates.
Example: Alpha=0.01
Data Types: single | double
Output Arguments
Mean response estimates, standard errors, and confidence intervals, returned as a
table. The table means has one row per unique combination of factor
values. If aov is a one-way anova object,
means has a column corresponding to the single factor. If
aov is a two- or N-way anova object,
means contains a column for each factor specified in
factors. In addition to the factor columns,
means contains the following:
Mean— Estimate of the mean response of the factor valueSE— Standard error of the mean estimateMeanLower— 95% lower confidence bound of the mean estimateMeanUpper— 95% upper confidence bound of the mean estimate
Version History
Introduced in R2022b
See Also
multcompare | plotComparisons | anova | One-Way ANOVA | Two-Way ANOVA | N-Way ANOVA
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)