canplot Canonical discriminant structure plot canplot

SAS Macro Programs: canplot

$Version: 1.6-5 (22 May 2007)
Michael Friendly
York University

The canplot macro ( [download] get

Canonical discriminant structure plot

The canplot macro constructs a canonical discriminant structure plot. The plot shows class means on the two largest canonical variables, confidence circles for those means, and variable vectors showing the correlations of variables with the canonical variates.


Discriminant scores and coefficients are extracted from PROC CANDISC and plotted.

Other designs may be handled either by (a) coding factor combinations 'interactively', so, e.g., the combinations of A*B are represented by a GROUP variable, or (b) by applying the method to adjusted response vectors (residuals) with some other predictor (class or continuous) partialled out. The latter method is equivalent to analysis of the residuals from an initial PROC GLM step, with the effects to be controlled or adjusted for as predictors.

e.g., to examine Treatment, controlling for Block and Sex,

   proc glm data=..;
    model Y1-Y5 = block sex;
    output out=resids
  %canplot(data=resids, var=E1-E5, class=Treat, ... );


canplot is a macro program. Values must be supplied for the CLASS= and VAR= parameters.

The interpretation of the angles betweeen variable vectors relies on the units for the horizontal and vertical axes being made equal (so that 1 data unit measures the same length on both axes. The axes should be equated either by using the GOPTIONS HSIZE= VSIZE= options, or using the macro HAXIS= and VAXIS= parameters and AXIS statements which specify the LENGTH= value for both axes.

The current version now uses the equate macro if the HAXIS= and VAXIS= arguments are not supplied.

The arguments may be listed within parentheses in any order, separated by commas. For example:

   %canplot(data=inputdataset, var=predictors, class=groupvariable..., )


The current version now provides many more parameters; see the program header.
The name of the input dataset. If not specified, the most recently created dataset is used.
The name of one class (group) variable
List of classification (predictor) variables
Scale factor for variable vectors in plot. The variable vectors are multiplied by the SCALE= value, which should be specified (perhaps by trial and error) to make the vectors and observations fill the same plot region. If SCALE=AUTO or SCALE=0, the program estimates a scale factor from the ratio of the maximum distance to the origin in the observations relative to the variables.
Confidence probability for canonical means
The name of the output data set containing discriminant scores
Output data set containing annotations
YES to produce the plot, or NO to suppress the plot
The name of an optional AXIS statement for the horizontal axis. The HAXIS= and VAXIS= arguments may be used to equate the axes in the plot so that the units are the same on the horizontal and vertical axes.
The name of an optional AXIS statement for the vertical axis.
name for graphic catalog entry
List of colors to be used for groups
List of symbols to be used for the various groups (levels of the CLASS= variable).


The example below plots the canonical structure of the Iris data. The graphic options HSIZE and VSIZE are used to scale the plot so that 1 unit on the horizontal and vertical axes are approximately the same size.
goptions vsize=3.2 in hsize=7.5in  htext=2;
%include data(iris);
title h=2.5 'Iris Data - Canonical Discriminant Plot';
axis1 order=(-10 to 10 by 2);
legend1 value=(h=2);
     data=iris, class=species,
     var=sepallen sepalwid petallen petalwid,
     haxis=axis1, vaxis=axis2, legend=legend1, hsym=1.5,
     colors=red blue black, scale=3.5);

See also

boxglm Power transformations by Box-Cox method for GLM
equate Creates AXIS statements for a GPLOT with equated axes
hemat HE plots for all pairs of response variables
heplot Plot Hypothesis and Error matrices for a bivariate MANOVA effect
meanplot Plot means for factorial designs
outlier Robust multivariate outlier detection