Example Program and Statement Details

Example Graph

The following graph was generated by the Example Program:
Example Prediction Ellipse

Example Program

This example overlays two ELLIPSE statements on a SCATTERPLOT of the same data.
  • Both ELLIPSE statements use TYPE=PREDICTED.
  • One ELLIPSE statement uses ALPHA=.2 and the other uses ALPHA=.05.
proc template;
  define statgraph ellipse;
    begingraph;    
      entrytitle "Prediction Ellipses";
      layout overlayequated / equatetype=equate;
        scatterplot x=petallength y=petalwidth /
          datatransparency=.5;
        ellipse x=petallength y=petalwidth /
          type=predicted  alpha=.2
          name="p80" legendlabel="80%"
          outlineattrs=graphconfidence;
        ellipse x=petallength y=petalwidth /
          type=predicted  alpha=.05
          name="p95" legendlabel="95%"
          outlineattrs=graphconfidence2;
        discretelegend "p80" "p95" /
          location=inside autoalign=(topleft);
      endlayout;	
      entryfootnote halign=left "Fisher's Iris Data";
    endgraph;
  end;
run;
proc sgrender data=sashelp.iris template=ellipse; 
run;

Statement Summary

The ELLIPSE statement can be used only within 2-D overlay-type layouts. It computes an ellipse for a set of points specified by the X and Y columns and a confidence level specified by the ALPHA= option. Use the TYPE= option to control whether a predicted or confidence ellipse is generated.

Confidence and Prediction Ellipses

Two types of ellipses can be computed for the input data (where observations correspond to points in a scatter plot). One is a confidence ellipse for the population mean (TYPE=MEAN), and the other is a prediction ellipse for a new observation (TYPE=PREDICT). Both assume a bivariate normal distribution.
Let and be the sample mean and sample covariance matrix of a random sample of size n from a bivariate normal distribution with mean and covariance matrix . The variable is distributed as a bivariate normal variate with mean zero and covariance , and it is independent of . Using Hotelling’s statistic, which is defined as
a confidence ellipse for is computed from the equation
where is the critical value of an distribution with degrees of freedom 2 and .
A prediction ellipse is a region for predicting a new observation in the population. It also approximates a region containing a specified percentage of the population.
Denote a new observation as the bivariate random variable . The variable
is distributed as a bivariate normal variate with mean zero (the zero vector) and covariance , and it is independent of . A prediction ellipse is then given by the equation
The family of ellipses generated by different critical values of the distribution has a common center (the sample mean) and common major and minor axis directions.
The shape of an ellipse depends on the aspect ratio of the plot. The ellipse indicates the correlation between the two variables if the variables are standardized (by dividing the variables by their respective standard deviations). In this situation, the ratio between the major and minor axis lengths is
In particular, if , the ratio is 1, which corresponds to a circular confidence contour and indicates that the variables are uncorrelated. A larger value of the ratio indicates a larger positive or negative correlation between the variables.

Required Arguments

X=numeric-column | expression
specifies the numeric column for the X values.
Y=numeric-column | expression
specifies the numeric column for the Y values.

Options

Statement Option
Description
Sets a significance value for the confidence level to compute for the ellipse.
Specifies whether the data for the ellipse are considered when determining the data ranges for the axes.
Specifies the degree of the transparency of the ellipse fill color and outline.
Specifies whether to display an outlined ellipse, a filled ellipse, or an outlined and filled ellipse.
Specifies the appearance of the interior fill of the ellipse.
Specifies a numeric column that provides frequencies for each observation read.
Specifies the legend label.
Assigns a name to a plot statement for reference in other template statements.
Specifies the properties of the ellipse outline.
Specifies the type of ellipse.
Specifies whether data are mapped to the primary X (bottom) axis or the secondary X2 (top) axis.
Specifies whether data are mapped to the primary Y (left) axis or the secondary Y2 (right) axis.
ALPHA=positive-number
sets a significance value for the confidence level to compute for the ellipse.
Default: .05
Range: 0 < number < 1
ALPHA=.05 represents a 95% confidence level.
See also: TYPE= option
CLIP=boolean
specifies whether the data for the ellipse are considered when determining the data ranges for the axes.
Default: FALSE
FALSE
The data for the ellipse contribute to the data range for each axis. Each axis might be extended to force the display of the entire ellipse.
TRUE
The data for the ellipse are ignored when establishing axis scales. Each axis scale is determined by the other plots in the parent layout. This might result in the ellipse not being entirely displayed (clipped) if its data range is not within the data ranges of the other plots.
DATATRANSPARENCY=number
specifies the degree of the transparency of the ellipse fill color and outline.
Default: 0
Range: 0 (opaque) to 1 (entirely transparent)
DISPLAY=STANDARD | ALL | ( display-options )
specifies whether to display an outlined ellipse, a filled ellipse, or an outlined and filled ellipse.
Default: GraphEllipse:DisplayOpts style reference.
STANDARD
displays an outlined, unfilled ellipse
ALL
displays an outlined, filled ellipse
(display-options)
a list of features to be displayed. The list must be enclosed in parentheses and must include one of the following:
OUTLINE—displays an outlined ellipse
FILL—displays a filled ellipse
Use FILLATTRS= and OUTLINEATTRS= to control the appearance of the ellipse.
FILLATTRS=style-element | style-element (fill-options) | (fill-options)
specifies the appearance of the interior fill area of the ellipse. See General Syntax for Attribute Options for the syntax on using a style-element and Fill Options for available fill-options.
Default: The GraphDataDefault style element.
Interaction: For this option to have any effect, the fill must be enabled by the ODS style or the DISPLAY= option.
FREQ=numeric-column | expression
Specifies a numeric column that provides frequencies for each observation read. If n is the value of the FREQ variable for a given observation, then that observation is counted n times in computing the ellipse.
Default: Each observation is counted once.
Restriction: If the value of the numeric-column is missing or is less than 1, the observation is not used in the analysis. If the value is not an integer, only the integer portion is used.
LEGENDLABEL= "string"
specifies the legend label.
Default: The string specified on the NAME= option.
NAME="string"
assigns a name to a plot statement for reference in other template statements.
Default: no default
Restriction: The string is case sensitive, cannot contain spaces, and must define a unique name within the template.
Interaction: The string is used as the default legend label if the LEGENDLABEL= option is not used.
The specified name is used primarily in legend statements to coordinate the use of colors and line patterns between the graph and the legend.
OUTLINEATTRS=style-element | style-element (line-options) | (line-options)
specifies the attributes of the ellipse outline. See General Syntax for Attribute Options for the syntax on using a style-element and Line Options for available line-options.
Default: The GraphDataDefault style element.
Interaction: For this option to have any effect, the outlines must be enabled by the ODS style or the DISPLAY= option.
TYPE=MEAN | PREDICTED
specifies the type of ellipse.
Default: MEAN
MEAN
specifies a confidence ellipse of the mean
PREDICTED
specifies a prediction ellipse for a new observation
See also: ALPHA= option for specifying a confidence level.
See also: For statistical details about how the ellipse is calculated, see Confidence and Prediction Ellipses .
XAXIS=X | X2
specifies whether data are mapped to the primary X (bottom) axis or to the secondary X2 (top) axis.
Default: X
Interaction: The overall plot specification and the layout type determine the axis display. For more information, see How Axis Features are Determined.
YAXIS=Y | Y2
specifies whether data are mapped to the primary Y (left) axis or to the secondary Y2 (right) axis.
Default: Y
Interaction: The overall plot specification and the layout type determine the axis display. For more information, see How Axis Features are Determined.