Example Program and Statement Details

Example Graph

The following graph was generated by the Example Program:
Example Loess Fit Plot

Example Program

proc template;
  define statgraph loessplot;
    begingraph;
      entrytitle "Loess Fit Plot";
      layout overlay;
        scatterplot x=weight y=mpg_highway /
          datatransparency=.7;
        loessplot x=weight y=mpg_highway / name="fitline"
          alpha=.05 legendlabel="Loess Fit";
        discretelegend "fitline";
      endlayout;
    endgraph;
  end;
run;

proc sgrender data=sashelp.cars template=loessplot;
run;

Statement Summary

The LOESSPLOT statement only supports statistical models of one independent and one dependent variable. For more information about the fitting methodology, see the LOESS procedure in the SAS/STAT user’s guide.
In addition to the loess curve, the LOESSPLOT statement can compute confidence levels for the fitted line. To display the confidence levels,
  1. use the CLM= option to declare a name for the confidence level of the mean
  2. use a MODELBAND statement to refer this name. This statement draws a confidence band from this information. See MODELBAND Statement for information about how to control the appearance of the confidence band.

Required Arguments

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

Loess Regression Options

ALPHA= positive-number
specifies the confidence level to compute.
Default: .05
Range: 0 < number < 1
Range: ALPHA=.05 represents a 95% confidence level.
CLM= "name"
produces confidence limits for a mean predicted value for each observation. The confidence level is set by the ALPHA= option.
Default: no default
Interaction: "name" is a unique name within the template that is case sensitive and cannot contain spaces. It must be assigned in order for the confidence limits to be computed. To display confidence limits, you must use this name as the required argument of a MODELBAND statement.
DEGREE=1 | 2
specifies the degree of the local polynomials to use for each local regression. The valid values are 1 for local linear fitting or 2 for local quadratic fitting.
Default: 1
INTERPOLATION=LINEAR | CUBIC
specifies the degree of the interpolating polynomials used for blending local polynomial fits at the kd tree vertices.
Default: LINEAR
CUBIC
cubic polynomials
LINEAR
linear polynomials
MAXPOINTS= positive-integer
specifies the maximum number of predicted points generated for the loess curve as well as confidence limits.
Default: 201
SMOOTH=AUTO | positive-number
specifies a regression parameter value.
Default: AUTO
REWEIGHT=NONE | positive-integer
specifies the number of iterative re-weighting steps to be done. Such iterations are appropriate when there are outliers in the data or when the error distribution is a symmetric long-tailed distribution.
Default: NONE
WEIGHT= numeric-column
specifies a variable in the input data set that contains values to be used as a priori weights for a loess fit. The values of the weight variable must be nonnegative. If an observation’s weight is zero, negative, or missing, the observation is deleted from the analysis.
Default: no default

Options

Statement Option
Description
Specifies the label of the loess curve.
Specifies the color and font attributes of the curve label.
Specifies the location of the curve label relative to the plot area.
Specifies the position of the curve label relative to the curve line.
Specifies the degree of the transparency of the loess curve.
Creates a distinct set of curves from just the observations that correspond to each unique group value of the specified column.
Specifies whether missing values of the group variable are included in the plot.
Specifies indices for mapping line attributes (color and pattern) to one of the GraphData1 - GranphDataN style elements.
Specifies a label for a legend.
Specifies the properties of the loess curve.
Assigns a name to a plot statement for reference in other template statements.
Specifies that the data columns for this plot be used for determining default axis features.
Specifies display formats for information defined by roles.
Specifies display labels for information defined by roles.
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.
CURVELABEL="string"
specifies a label for the loess curve.
Default: no curve label is displayed
Interaction: If the GROUP= option is specified, this option is ignored.
The font and color attributes for the label are specified by the CURVELABELATTRS= option.
CURVELABELATTRS=style-element | style-element (text-options) | (text-options)
specifies the color and font attributes of the curve labels. See General Syntax for Attribute Options for the syntax on using a style-element and Text Options for available text-options.
Default: The GraphValueText style element.
Interaction: For this option to take effect, the CURVELABEL= option must also be specified.
Interaction: If the GROUP= option is specified, this option is ignored.
CURVELABELLOCATION=INSIDE | OUTSIDE
specifies the location of the curve label relative to the plot area.
Default: INSIDE
INSIDE
inside the plot area
OUTSIDE
outside the plot area
Restriction: OUTSIDE cannot be used when the LOESSPLOT is used in multicell layouts such as LATTICE, DATAPANEL, or DATALATTICE, where axes might be external to the grid.
Interaction: For this option to take effect, the CURVELABEL= option must also be specified.
Interaction: This option is used in conjunction with the CURVELABELPOSITION= option to determine where the curve labels appear. For more information, see Location and Position of Curve Labels.
CURVELABELPOSITION=AUTO | MAX | MIN | START | END
specifies the position of the curve label relative to the curve line.
Default: AUTO when CUVELABELLOCATION=OUTSIDE, and END when CURVELABELLOCATION=INSIDE
AUTO
Only used when CURVELABELPOSITION=OUTSIDE. The curve label is positioned automatically near the curve boundary along unused axes whenever possible (typically Y2 and X2) to avoid collision with tick values.
MAX
Forces the curve label to appear near maximum curve values (typically, upper right).
MIN
Forces the curve label to appear near minimum curve values (typically, lower left).
START
Only used when CURVELABELLOCATION=INSIDE. Forces the curve label to appear near the beginning of the curve. Particularly useful when the curve line has a spiral shape.
END
Only used when CURVELABELLOCATION=INSIDE. Forces the curve label to appear near the end of the curve. Particularly useful when the curve line has a spiral shape.
Interaction: For this option to take effect, the CURVELABEL= option must also be specified.
Interaction: The AUTO setting is ignored if CURVELABELLOCATION=INSIDE is specified. The START and END settings are ignored if CURVELABELLOCATION=OUTSIDE is specified.
Interaction: This option is used in conjunction with the CURVELABELLOCATION= option to determine where the curve label appears. For more information, see Location and Position of Curve Labels.
DATATRANSPARENCY=number
specifies the degree of the transparency of the loess curve.
Default: 0
Range: 0 (opaque) to 1 (entirely transparent)
GROUP=column | discrete-attr-var | expression
creates a distinct set of curves from just the observations that correspond to each unique group value of the specified column.
discrete-attr-var
specifies a discrete attribute variable that is defined in a DISCRETEATTRVAR statement.
Restriction: A discrete attribute variable specification must be a direct reference to the attribute variable. It cannot be set by a dynamic variable.
Default: Each distinct group value might be represented in the graph by a different combination of color and line pattern. Line colors vary according to the GraphData1:ContrastColor - GraphDataN:ContrastColor style references, and line patterns vary according to the GraphData1:LineStyle - GraphDataN:LineStyle style references.
Restriction: The input data must be sorted by the GROUP= column.
Interaction: The group values are mapped in the order of the data, unless the INDEX= option is used to alter the default sequence of line colors and line patterns.
Interaction: The INCLUDEMISSINGGROUP option controls whether missing group values are considered a distinct group value.
Tip: The LINEATTRS= option can be used to override the representations that are used to identify the groups. For example, LINEATTRS=(PATTERN=SOLID) can be used to assign the same pattern to all of the loess curves, letting the line color distinguish group values. Likewise, LINEATTRS=(COLOR=BLACK) can be used to assign the same color to all of the curves, letting the line pattern distinguish group values.
INCLUDEMISSINGGROUP=boolean
specifies whether missing values of the group variable are included in the plot.
Default: TRUE
Interaction: For this option to take effect, the GROUP= option must also be specified.
Tip: Unless a discrete attribute map is in effect or the INDEX= option is used, the attributes of the missing group value are determined by the GraphMissing style element except when the MISSING= system option is used to specify a non-default missing character or when a user-defined format is applied to the missing group value. In those cases, the attributes of the missing group value are determined by a GraphData1–GraphDataN style element.
INDEX=numeric-column | expression
specifies indices for mapping line attributes (color and pattern) to one of the GraphData1 - GranphDataN style elements.
Default no default
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.
Interaction: For this option to take effect, the GROUP= option must also be specified.
Interaction: All of the indexes for a specific group value must be the same. Otherwise, the results are unpredictable.
Interaction: If this option is not used, then the group values are mapped in the order of the data.
Interaction: The index values are 1-based indices. For the style elements in GraphData1 - GraphDataN, if the index value is greater than N, then a modulo operation remaps that index value to a number less than N to determine which style element to use.
Discussion: Indexing can be used to collapse the number of groups that are represented in a graph. For more information, see Remapping Groups for Grouped Data.
LEGENDLABEL= "string"
specifies a label for the legend item that is associated with this plot.
Default: The string specified on the NAME= option.
Restriction: This option applies only to an associated DISCRETELEGEND statement.
Interaction: If the GROUP= option is specified, this option is ignored.
LINEATTRS=style-element | style-element (line-options) | (line-options)
specifies the attributes of the loess curve. See General Syntax for Attribute Options for the syntax on using a style-element and Line Options for available line-options.
Default: The GraphFit style element.
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.
PRIMARY=boolean
specifies that the data columns for this plot and the plot type be used for determining default axis features.
Default: FALSE
Restriction: This option is ignored if the plot is placed under a GRIDDED or LATTICE layout block.
Details: This option is needed only when two or more plots within an overlay-type layout contribute to a common axis. For more information, see When Plots Share Data and a Common Axis.
TIPFORMAT=(role-format-list)
specifies display formats for tip columns.
Default: The column format of the variable assigned to the role or BEST6. if no format is assigned to a numeric column.
(role-format-list)
a list of role-name = format pairs separated by blanks.
TIPFORMAT=(Y=6.2)
Requirement: To generate tooltips, you must include an ODS GRAPHICS ON statement that has the IMAGEMAP option specified, and write the graphs to the ODS HTML destination.
The columns assigned to the X, Y, and GROUP (if assigned) roles are automatically included in the tooltip information.
TIPLABEL=(role-label-list)
specifies display labels for tip columns.
Default: The column label or column name of the variable assigned to the role.
(role-label-list)
a list of role-name = "string" pairs separated by blanks.
   TIPLABEL=(Y="Loess Fit")
Requirement: To generate tooltips, you must include an ODS GRAPHICS ON statement that has the IMAGEMAP option specified, and write the graphs to the ODS HTML destination.
The columns assigned to the X, Y, and GROUP (if assigned) roles are automatically included in the tooltip information.
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 the specified axis. 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 the specified axis. For more information, see How Axis Features Are Determined.