1. Home
  2. RGRAPH procedure

RGRAPH procedure

Draws a graph to display the fit of a regression model (P.W. Lane).

Options

GRAPHICS = string token Type of graphics to produce (lineprinter, highresolution); default high
TITLE = text Title for the graph; default 'Fitted and observed relationship'
WINDOW = number Which high-resolution graphics window to use; default 4 (redefined if necessary to fill the frame)
SCREEN = string token Whether to clear the graphics screen before plotting (clear, keep); default clea
CIPLOT = string token Whether to plot confidence intervals (no, yes); default no
CIPROBABILITY = scalar Probability for confidence interval; default 0.95
BACKTRANSFORM = string token What back-transformation to make (link, none, axis); default link
SAVE = regression save structure Save structure of the model to display; default * uses the most recently fitted regression model

Parameters

INDEX = variate Which explanatory variate to display; default * if GROUPS is set, otherwise INDEX is set to the first variate in the fitted model (must be set for nonlinear models other than standard curves)
GROUPS = factor Which explanatory factor to display; default * if INDEX is set, otherwise GROUPS is set to the first factor in the fitted model (ignored for nonlinear models)

Description

Procedure RGRAPH displays the fit of either a linear regression, a generalized linear model, a generalized additive model, a standard curve or a nonlinear model.

For models other than the nonlinear models fitted by FITNONLINEAR or FIT with the CALCULATION option set, the graph shows the relationship between the response variate and either one explanatory variate or one explanatory factor or one of each. If no parameters are set, RGRAPH takes the first explanatory variate and the first factor in the model, and the predicted relationship is represented by a line for each level of the factor. The display represents the observed relationship as points, plotting the response (adjusted for further explanatory terms in the model, if any) against the chosen explanatory variate, with each point labelled according to the corresponding factor level. If no factor has been fitted, a single line is drawn, while if no variate has been fitted the graph simply shows the predicted mean for each level of the factor.

If a linear, generalized linear, or generalized additive model has been fitted, the INDEX and GROUPS parameters can be used to specify which explanatory variate and factor, respectively, should be used. If INDEX is set and GROUPS is not, a single line is drawn even if there are factors in the model; similarly if GROUPS is set and INDEX is not, the effect of the factor alone is shown. With generalized linear models, the relationship is usually plotted on the original scale, but you can set option BACKTRANSFORM to either none or axis, to plot on the scale of the linear predictor. These settings are useful, for example, if you want to check for potential non-linearity in the response. They differ in that the axis setting includes axis markings, back-transformed onto the natural scale, on the right-hand side of the y-axis. However, this is not available for log-ratio, power, reciprocal or calculated links.

For nonlinear models fitted by the FITNONLINEAR directive, a single line is drawn by joining the fitted values, and the response values are shown as points. Any setting of the GROUPS parameter is ignored. For curves fitted by the FITCURVE directive, settings of the INDEX and GROUPS parameters are ignored.

No graph can be drawn if the REG function has been used for any variate in the model. If the SSPLINE function has been used for any variate whose relationship with the response is not actually displayed, then the only adjustment for its effect will be the linear component of the fitted smooth curve. If the displayed variate itself is smoothed, then the curve is formed by interpolation between adjusted fitted values. The POL function is dealt with correctly.

The TITLE option can be used to supply a title for the graph. By default the graph is plotted on the current high-resolution device, but the GRAPHICS option can be set to line for a line printer plot. The WINDOW option can be used to select a pre-defined window for high-resolution plots; otherwise window 4 is used, and is redefined if necessary to fill the frame. The SCREEN option allows the graph to be added to an existing high-resolution plot. The colours and symbols used in the displays can be controlled by setting the attributes of the following pens with the PEN directive before calling the procedure:

    pen 1 labels for lines when drawn for each level of a factor,
    pen 2 fitted lines and means,
    pen 3 points, and
    pen 4 back-transformed axis marks and labels.

By default the current regression model is displayed, but option SAVE can be set to specify the save structure (from a MODEL statement) of some other model.

When there are no groups with a linear or generalized linear model, you can set option CIPLOT=yes to include confidence intervals for the fitted relationship. The CIPROBABILITY option sets the size of the interval. The default is 0.95 (i.e. 95%).

Options: GRAPHICS, TITLE, WINDOW, SCREEN, CIPLOT, CIPROBABILITY, BACKTRANSFORM, SAVE.

Parameters: INDEX, GROUPS.

Method

For a linear or generalized linear model, fitted lines are drawn by joining predicted values calculated by a PREDICT statement at 21 equally spaced values spanning the range of the explanatory variate. Alternatively, PREDICT provides adjusted means at each level of the factor, if the effect of the factor is to be displayed alone. If all the effects in the current model are displayed, the response is plotted against the explanatory variable (or against the factor level) as points. But if adjustment has to be made for some effects, adjusted response values (known as “partial residuals”) are calculated by adding the simple residuals to predictions produced for all observations.

For generalized additive models, no predictions are used if the explanatory variate is smoothed: the nonlinear component of the smooth is extracted using RKEEP. For curves and general nonlinear models no predictions are made, and fitted values are used.

If a linear or generalized linear model is constrained to pass through the origin, the display will extend the range of the explanatory if necessary to include the origin.

The back-transformed axis markings, given by BACKTRANSFORM=axis, are added by using AXIS to including an additional (oblique) axis alongside the y-axis.

Action with RESTRICT

Any restriction that was in force when the model was fitted will apply also to the graphs. Problems may occur, however, if the response variate is not restricted and an explanatory variate or factor is restricted.

See also

Procedures: RCHECK, RDESTIMATES, AGRAPH, DTABLE, VGRAPH.

Commands for: Regression analysis.

Example

CAPTION 'RGRAPH example',!t('Experiments on cauliflowers in 1957 and 1958',\
        'provided data on the mean number of florets in the plant and the',\
        'temperature during the growing season (expressed as accumulated',\
        'temperature above 0 deg C.).'); STYLE=meta,plain
FACTOR  [LEVELS=!(1957,1958); VALUES=7(1957,1958)] Year
VARIATE [NVALUES=14] MnCount,AccTemp
READ    MnCount,AccTemp
 3.8  2.5    6.2  4.2    7.2  5.3    8.7  5.8
10.2  7.2   13.5  8.9   15.0 10.0
 6.0  2.5    8.5  4.4    9.1  5.3   12.0  6.4
12.6  7.2   13.3  7.8   15.2  9.2 :
" Fit a linear regression model of the mean count of florets on
  accumulated temperature - first ignoring the division into two years."
MODEL  MnCount
TERMS  AccTemp*Year
FIT    AccTemp
" Display single fitted line."
RGRAPH
" Fit separate regressions for the two years."
ADD    Year+AccTemp.Year
" Display lines for each year."
RGRAPH
" Display means for each year, at average accumulated temperature."
RGRAPH [TITLE='Means adjusted for temperature'] INDEX=*; GROUPS=Year
Updated on March 5, 2019

Was this article helpful?