www.gusucode.com > stats 源码程序 matlab案例代码 > stats/ANOVAWithMultipleResponsesExample.m

    %% ANOVA with Multiple Responses
%% Load Sample Data
% Load the sample data.

% Copyright 2015 The MathWorks, Inc.

load carsmall
whos
%% Grouped plot matrix of four variables
% Create a grouped plot matrix of these variables using the gplotmatrix
% function.
x = [MPG Horsepower Displacement Weight];
gplotmatrix(x,[],Model_Year,[],'+xo')
%% Perform MANOVA
[d,p,stats] = manova1(x,Model_Year)
%% Perform canonical analysis using stats.canon
c1 = stats.canon(:,1);
c2 = stats.canon(:,2);
%% Plot the grouped scatter plot of the first two canonical variables 
figure()
gscatter(c2,c1,Model_Year,[],'oxs')
%% Find the largest distance from the group mean
max(stats.mdist)
%% Find the point that has the largest distance from the group mean
find(stats.mdist == ans)
%% Find car model that corresponds to the largest distance from group mean
Model(20,:)
%% Examine the group means using grpstats
grpstats(x, Model_Year)
%% Find the distances between each pair of group means
stats.gmdist