• Print  |
  • Feedback  |

TEMPLATE Procedure: Plot Statements (Experimental)

DENSITY Statement


Displays a univariate probability density curve computed from input data, and typically is used to add normal density curves and non-parametric kernel density curves to a histogram.
DENSITY numeric-column | expression < / <distribution-option> <option(s)>> ;


Usage Information

Density Histogram

[Density Histogram]

Tip:

A typical DENSITY statement specifies either the NORMAL or the KERNEL distribution option. Thus, one common plot syntax would be one of the following statements.

DENSITY numeric-column / NORMAL()

Another common plot syntax would be:

DENSITY numeric-column / KERNEL()

Tip:

If no distribution option is specified, then NORMAL is assumed.

Tip:

If more than one distribution option is specified, then the last distribution option specified is used.


Required Arguments

numeric-column

specifies a numeric column of data values that are used to calculated the parameters for the probability distribution.

expression

specifies a selective, relational, or logical program structure that calculates values when those values are not stored in the data.


Distribution Options

KERNEL ( < C= number > <, WEIGHT= NORMAL | TRIANGULAR | QUADRATIC > )

specifies a non-parametric kernel density estimate. The general form of the kernel density estimator is as follows.

[untitled graphic]

In the equation, K0 (.) is the weight function, [lambda] is the bandwidth, n is the sample size, and xi is the ith observation. You can use the C= sub-option to specify the bandwith and the WEIGHT= sub-option to specify the weight function K0 (.).

For more information, see the discussion of Kernel Density Estimates for the UNIVARIATE procedure in the Base SAS Procedures Guide, Volume 3.

C

specifies the number that represents the standardized bandwidth.

Default: Calculated from the data as the bandwidth that minimizes the approximate mean integrated square error (MISE).

The value of [lambda], referred to as the bandwidth parameter, determines the degree of smoothness in the estimated density function. You specify [lambda] indirectly by specifying a standardized bandwidth c with the C= kernel-option. If Q is the interquartile range, and n is the sample size, then c is related to by the following formula.

[untitled graphic]

WEIGHT

specifies a weight function.

Default: NORMAL
Tip: The formulas for the weight functions are as follows.

[untitled graphic]

NORMAL ( < MU= number > < , SIGMA= number > )

specifies a normal density estimate, with mean and standard deviation. The fitted density function equation is as follows.

[untitled graphic]

In the equation, [mu] is the mean, and [sigma] is the standard deviation ([sigma] > 0). You can specify [mu] with the MU= sub-option and [sigma] with the SIGMA= sub-option. By default, ODS estimates [mu] with the sample mean and [sigma] with the sample standard deviation.

For more information, see the discussion of Kernel Density Estimates for the UNIVARIATE procedure in the Base SAS Procedures Guide, Volume 3.

Tip: If mean and standard deviation are not specified, then they are calculated from the data.
MU

specifies the mean.

SIGMA

specifies the standard deviation.


Options

DENSITY Options
Option Description
BACKGROUND= color | style-reference Specifies the background color of the graph.
BACKTRANSPARENCY= number Specifies the degree of the transparency of the background color.
DATATRANSPARENCY=number
Specifies the degree of the transparency of the density curve.
LEGENDLABEL= 'string' Specifies the label of the legend.
LINECOLOR= color | style-reference Specifies the color of the density curve line.
LINEPATTERN= line | style-reference Specifies the pattern of the density curve line.
LINETHICKNESS= dimension | style-reference Specifies the thickness of the density curve line.
NAME= 'string' Assigns a name to a plot statement for reference in other template statements.
TRANSPARENCY= number Specifies the degree of the transparency of the density curve, background, and axis elements, if displayed in a graph.
XAXIS= X| X2 Specifies whether the curve is mapped to the primary X axis or to the secondary X (X2) axis.
XMAX= number Specifies the maximum X data value to use in the display of the curve .
XMIN= number Specifies the minimum X data value to use in the display of the curve.
YAXIS= Y | Y2 Specifies whether the curve is mapped to the primary Y axis or to the secondary Y (Y2) axis.
YMAX =number Specifies the maximum Y data value to use in the display of the curve.
YMIN= number Specifies the minimum Y data value to use in the display of the curve.

BACKGROUND= color | style-reference

specifies the background color of the graph.

Default: Specified by the GraphBackground:Background style reference.
Interaction: Ignored in a LAYOUT OVERLAY block. For information, see Ignored Plot Options in a LAYOUT OVERLAY Block.
BACKTRANSPARENCY= number

specifies the degree of the transparency of the background color.

Default: 0
Range: 0 (opaque) to 1 (entirely transparent)
Interaction: The BACKTRANSPARENCY= option overrides the TRANSPARENCY= option for the background.
Interaction: Ignored in a LAYOUT OVERLAY block. For information, see Ignored Plot Options in a LAYOUT OVERLAY Block.
See also: TRANSPARENCY= option
DATATRANSPARENCY= number

specifies the degree of the transparency of the density curve.

Default: 0
Range: 0 (opaque) to 1 (entirely transparent)
Interaction: The DATATRANSPARENCY= option overrides the TRANSPARENCY= option for the density curve.
See also: TRANSPARENCY= option
LEGENDLABEL= 'string'

specifies the label of the legend.

Default: No label
LINECOLOR= color | style-reference

specifies the color of the density curve line.

Default: Specified by the GraphDataDefault:ContrastColor style reference.
LINEPATTERN= line | style-reference

specifies the pattern of the density curve line.

Default: SOLID
LINETHICKNESS= dimension | style-reference

specifies the thickness of the density curve line.

Default: 1 px
NAME= 'string'

assigns a name to a plot statement for reference in other template statements.

Restriction: The string specified by the NAME= option must be unique within the template.
Restriction: The string specified by the NAME= option cannot contain embedded spaces.
Tip: The NAME= option is used mostly in the DISCRETELEGEND statement in order to coordinate the use of colors, marker symbols, and line patterns between the graph and the legend.
Tip: string is case sensitive.
TRANSPARENCY= number

specifies the degree of the transparency of the density curve, background, and axis elements, if displayed in a graph.

Default: 0
Range: 0 (opaque) to 1 (entirely transparent)
Interaction: The transparency for the density curve and background can be set individually with the BACKTRANSPARENCY= and DATATRANSPARENCY= options. If you specify the TRANSPARENCY= option for a graph, then the individual transparency options can be specified to override it for individual features. The settings remain in effect for other features that are not individually overridden.
Interaction: In an OVERLAY LAYOUT block, the TRANSPARENCY= option only affects the density curve. The LAYOUT OVERLAY statement settings control the transparency of the background and axis elements.
XAXIS= X | X2

specifies whether the curve is mapped to the primary X axis or to the secondary X (X2) axis.

Default: X
Interaction: Within a LAYOUT OVERLAY block, multiple plots can share both a primary and a secondary axis. The primary and secondary axes can have different scales, and the XAXIS= option for a particular plot can map data to either axis. The XAXISOPTS= and X2AXISOPTS= options of a LAYOUT OVERLAY statement determine whether the axes are displayed and set their axis characteristics.
XMAX= number

specifies the maximum X data value to use in the display of the curve.

Default: The default value is the maximum X value in the curve.
Restriction: If the curve contains values greater than the number specified for the XMAX= option, then the values are excluded from the plot.
XMIN= number

specifies the minimum X data value to use in the display of the curve.

Default: The default value is the minimum X value in the curve.
Restriction: If the curve contains values that are less than the number specified for the XMIN= option, then the values are excluded from the plot.
YAXIS= Y | Y2

specifies whether the curve is mapped to the primary Y axis or to the secondary Y (Y2) axis.

Default: Y
Interaction: Within a LAYOUT OVERLAY block, multiple plots can share both a primary and a secondary axis. The primary and secondary axes can have different scales, and the YAXIS= option for a particular plot can map data to either axis. The YAXISOPTS= and Y2AXISOPTS= options of a LAYOUT OVERLAY statement determine whether the axes are displayed and set their axis characteristics.
YMAX= number

specifies the maximum Y data value to use in the display of the curve.

Default: The default value is the maximum Y value in the curve.
Restriction: If the data contains values that are greater than the number specified for the YMAX= option, then the values are excluded from the plot.
YMIN= number

specifies the minimum Y data value to use in the display of the curve.

Default: The default value is the minimum Y value in the curve.
Restriction: If the data contains values that are less than the number specified for the YMIN= option, then the values are excluded from the plot.


Previous Page | Next Page | Top of Page