Learn R Programming

car (version 1.2-1)

spread.level.plot: Spread-Level Plots

Description

Creates plots for examining the possible dependence of spread on level, or an extension of these plots to the studentized residuals from linear models.

Usage

spread.level.plot(x, ...)

slp(x, ...)

## S3 method for class 'formula':
spread.level.plot(formula, data=NULL, subset, na.action, 
    main=paste("Spread-Level Plot for", varnames[response], 
    "by", varnames[-response]), ...)

## S3 method for class 'default':
spread.level.plot(x, by, 
  robust.line=any("MASS"==.packages(all=TRUE)), 
  start=0, xlab="Median", ylab="Hinge-Spread", point.labels=TRUE, las=par("las"),
  main=paste("Spread-Level Plot for", deparse(substitute(x)), 
  "by", deparse(substitute(by))), col=palette()[2], pch=1, lwd=2, ...)

## S3 method for class 'lm':
spread.level.plot(x, start=0, 
  robust.line=any("MASS"==.packages(all=TRUE)), 
  xlab="Fitted Values",
  ylab="Absolute Studentized Residuals", las=par("las"),
  main=paste("Spread-Level Plot for", deparse(substitute(x))),
  pch=1, col=palette()[2], lwd=2, ...)
  
## S3 method for class 'spread.level.plot':
print(x, ...)

Arguments

x
a formula or an lm object to be plotted; alternatively a numeric vector.
formula
a formula of the form y~x, where y is a numeric vector and x is a factor.
data
an optional data frame containing the variables to be plotted. By default the variables are taken from the environment from which spread.level.plot is called.
subset
an optional vector specifying a subset of observations to be used.
na.action
a function that indicates what should happen when the data contain NAs. The default is set by the na.action setting of options.
by
a factor, numeric or character vector defining groups.
robust.line
if TRUE a robust line is fit using the rlm function in the MASS package; if FALSE a line is fit using lm.
start
add the constant start to each data value.
main
title for the plot.
xlab
label for horizontal axis.
ylab
label for vertical axis.
point.labels
if TRUE label the points in the plot with group names.
las
if 0, ticks labels are drawn parallel to the axis; set to 1 for horizontal labels (see par).
col
color for points and lines; the default is the second entry in the current color palette (see palette and par).
pch
plotting character for points; default is 1 (a circle, see par).
lwd
line width; default is 2 (see par).
...
arguments passed to plotting functions.

Value

  • A list containing:
  • Statisticsa matrix with the lower-hinge, median, upper-hinge, and hinge-spread for each group. (Not for an lm object.)
  • PowerTransformationspread-stabilizing power transformation, calculated as 1 -- slope of the line fit to the plot.

Details

Except for linear models, computes the statistics for, and plots, a Tukey spread-level plot of log(hinge-spread) vs. log(median) for the groups; fits a line to the plot; and calculates a spread-stabilizing transformation from the slope of the line. For linear models, plots log(abs(studentized residuals) vs. log(fitted values). The function slp is an abbreviation for spread.level.plot.

References

Fox, J. (1997) Applied Regression, Linear Models, and Related Methods. Sage. Hoaglin, D. C., Mosteller, F. and Tukey, J. W. (Eds.) (1983) Understanding Robust and Exploratory Data Analysis. Wiley.

See Also

hccm, ncv.test

Examples

Run this code
spread.level.plot(interlocks+1~nation, data=Ornstein)
## Loading required package: MASS
##     LowerHinge Median UpperHinge Hinge-Spread
## US           2    6.0         13           11
## UK           4    9.0         14           10
## CAN          6   13.0         30           24
## OTH          4   15.5         24           20
##
## Suggested power transformation:  0.1534487 

slp(lm(interlocks ~ assets + sector + nation, data=Ornstein))
## Suggested power transformation:  0.3222165 
## Warning message:
## Start =  3 added to fitted values to avoid 0 or negative values. in: spread.level.plot.lm(x, ...)

Run the code above in your browser using DataLab