File: spreadLevelPlot.Rd

package info (click to toggle)
car 3.1-3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,520 kB
  • sloc: makefile: 2
file content (120 lines) | stat: -rw-r--r-- 5,741 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
\name{spreadLevelPlot}
\alias{spreadLevelPlot}
\alias{slp}
\alias{spreadLevelPlot.formula}
\alias{spreadLevelPlot.default}
\alias{spreadLevelPlot.lm}
\alias{print.spreadLevelPlot}

\title{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{
spreadLevelPlot(x, ...)

slp(...)

\method{spreadLevelPlot}{formula}(x, data=NULL, subset, na.action, 
    main=paste("Spread-Level Plot for", varnames[response], 
    "by", varnames[-response]), ...)

\method{spreadLevelPlot}{default}(x, by, robust.line=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=carPalette()[1], col.lines=carPalette()[2],
    pch=1, lwd=2, grid=TRUE, ...)

\method{spreadLevelPlot}{lm}(x, robust.line=TRUE, 
	xlab="Fitted Values", ylab="Absolute Studentized Residuals", las=par("las"),
	main=paste("Spread-Level Plot for\n", deparse(substitute(x))),
	pch=1, col=carPalette()[1], col.lines=carPalette()[2:3], lwd=2, grid=TRUE, 
    id=FALSE, smooth=TRUE, ...)
	  
\method{print}{spreadLevelPlot}(x, ...)
}

\arguments{
  \item{x}{a formula of the form \code{y ~ x}, where \code{y} is a numeric vector
    and \code{x} is a factor, or an \code{lm} object to be plotted; alternatively a numeric vector.}
  \item{data}{an optional data frame containing the variables to be plotted. 
    By default the variables are taken from the environment from which 
    \code{spreadLevelPlot} is called.}
  \item{subset}{an optional vector specifying a subset of observations to be used.}
  \item{na.action}{a function that indicates what should happen when the data contain \code{NA}s. 
    The default is set by the \code{na.action} setting of \code{options}.}
  \item{by}{a factor, numeric vector, or character vector defining groups.}
  \item{robust.line}{if \code{TRUE} a robust line is fit using the \code{rlm} function in
    the \code{MASS} package; if \code{FALSE} a line is fit using \code{lm}.}
  \item{start}{add the constant \code{start} to each data value.}
  \item{main}{title for the plot.}
  \item{xlab}{label for horizontal axis.}
  \item{ylab}{label for vertical axis.}
  \item{point.labels}{if \code{TRUE} label the points in the plot with group names.}
  \item{las}{if \code{0}, ticks labels are drawn parallel to the
    axis; set to \code{1} for horizontal labels (see \code{\link{par}}).}
  \item{col}{color for points; the default is the first entry
    in the current \pkg{car} palette (see \code{\link{carPalette}}
    and \code{\link{par}}).}
  \item{col.lines}{for the default method, the line color, defaulting to the second entry in the \pkg{car} color palette; 
    for the \code{"lm"} method, a vector of two colors for, respectively, the fitted straight line and a nonparametric regression smooth line,
    default to the second and third entries in the \pkg{car} color palette.}
  \item{pch}{plotting character for points; default is \code{1} 
    (a circle, see \code{\link{par}}).}
  \item{lwd}{line width; default is \code{2} (see \code{\link{par}}).}
  \item{grid}{If TRUE, the default, a light-gray background grid is put on the
graph}
    \item{id}{controls point identification; if \code{FALSE} (the default), no points are identified;
        can be a list of named arguments to the \code{\link{showLabels}} function;
        \code{TRUE} is equivalent to \code{list(method=list("x", "y"), n=2, 
        cex=1, col=carPalette()[1], location="lr")},
        which identifies the 2 points the most extreme horizontal ("X", absolute studentized residual) values and the 2 points
        with the most extreme horizontal ("Y", fitted values) values.}
    \item{smooth}{specifies the smoother to be used along with its arguments; if \code{FALSE}, no smoother is shown;
        can be a list giving the smoother function and its named arguments; \code{TRUE}, the default, is equivalent to
        \code{list(smoother=loessLine)}. See \code{\link{ScatterplotSmoothers}} for the smoothers supplied by the
        \pkg{car} package and their arguments.}
  \item{\dots}{arguments passed to plotting functions.}
}
\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).  Point labeling was added in November, 2016.
  
  The function \code{slp} is an abbreviation for \code{spreadLevelPlot}.
}
\value{
  An object of class \code{spreadLevelPlot} containing:
  \item{Statistics}{a matrix with the lower-hinge, median, upper-hinge, and hinge-spread
    for each group. (Not for an \code{lm} object.)}
  \item{PowerTransformation}{spread-stabilizing power transformation, calculated as \eqn{1 - slope}
    of the line fit to the plot.}
}
\references{ 
  Fox, J. (2016)
  \emph{Applied Regression Analysis and Generalized Linear Models},
  Third Edition. Sage.  
  
  Fox, J. and Weisberg, S. (2019) 
  \emph{An R Companion to Applied Regression}, Third Edition, Sage.
  
  Hoaglin, D. C., Mosteller, F. and Tukey, J. W. (Eds.) (1983)
  \emph{Understanding Robust and Exploratory Data Analysis.} Wiley.
}
\author{John Fox \email{jfox@mcmaster.ca}}

\seealso{\code{\link{hccm}}, \code{\link{ncvTest}} }

\examples{
spreadLevelPlot(interlocks + 1 ~ nation, data=Ornstein)
slp(lm(interlocks + 1 ~ assets + sector + nation, data=Ornstein))
}

\keyword{hplot}
\keyword{regression}