scatterplot
, scatterplotMatrix
and other car
functions.
The functions aren't meant to
be called directly by the user, although the user can supply options via the smoother.args
argument,
the contents of which vary by the smoother (see Details below). The gamLine
smoother uses the
gam
function in the loessLine
smoother uses the
loess
function in the quantregLine
smoother uses the
rqss
function in the gamLine(x, y, col, log.x, log.y, spread=FALSE, smoother.args, draw=TRUE)
loessLine(x, y, col, log.x, log.y, spread=FALSE, smoother.args, draw=TRUE)
quantregLine(x, y, col, log.x, log.y, spread=FALSE, smoother.args, draw=TRUE)
TRUE
if the $x$-axis is logged.TRUE
if the $y$-axis is logged.x
and y
for the points
that make up the smooth and if requested x.pos, y.pos, x.neg, y.neg
foloessLine
is a reimplementation of the loess
smoother
that was used in car
prior to September 2012. The only enhancement is the ability to
set more arguments through the smoother.args
argument.
The function gamLine
is new and more general than the loess
fitting
because it allows fitting a generalized additive model using splines. You can specify an error
distribution and link function.
The function quantregLine
fits an additive model using splines with estimation
based on L1 regression and quantile regression if you ask for the spread. It is
likely to be more robust than the other smoothers.
The argument smoother.args
is a list of named elements used to pass
additional arguments to the smoother.
For loessLine
the default value is
smoother.args=list(lty=1, lwd=2, lty.spread=2, lwd.spread=1, span=0.5,
degree=2, family="symmetric", iterations=4)
.
The arguments lty
and lwd
are the type and width
respectively of the mean or median smooth, smooth.lty
and smooth.lwd
are the type and color of the spread smooths if requested.
The arguments span
, degree
and family
are
passed to the loess
function, iterations=0
by default
specifies no robustness iterations.
For gamLine
the default is
smoother.args=list(lty=1, lwd=2, lty.spread=2, lwd.spread=1,
k=-1, bs="tp", family="gaussian", link=NULL, weights=NULL)
The first four arguments are as for loessLine
. The next two
arguments are passed to the gam
function to control the smoothing:
k=-1
allows gam
to choose the number of splines in the basis
function; bs="tp"
provides the type of spline basis to be used with "tp"
for the default thin-plate splines. The last three arguments allow providing
a family, link and weights as in generalized linear models. See examples
below. The spread argument is ignored unless family="gaussian" and link=NULL.
For quantregLine
the default is
smoother.args=list(lty=1, lwd=2, lty.spread=2, lwd.spread=1,
lambda=IQR(x)
. The first four
arguments are as for loessLine
. The last argument is passed to the
qss
function in quantreg
. It is a smoothing
parameter, here a robust estimate of the scale of the horizontal axis variable.
This is an arbitrary choice, and may not work well in all circumstances.scatterplot
, scatterplotMatrix
, gam
,
loess
, and rqss
.scatterplot(prestige ~ income, data=Prestige)
scatterplot(prestige ~ income, data=Prestige, smoother=gamLine)
scatterplot(prestige ~ income, data=Prestige, smoother=quantregLine)
scatterplot(prestige ~ income | type, data=Prestige)
scatterplot(prestige ~ income | type, data=Prestige, smoother=gamLine)
scatterplot(prestige ~ income | type, data=Prestige, smoother=quantregLine)
scatterplot(prestige ~ income | type, data=Prestige, smoother=NULL)
scatterplot(prestige ~ income | type, data=Prestige, spread=TRUE)
scatterplot(prestige ~ income | type, data=Prestige, smoother=gamLine, spread=TRUE)
scatterplot(prestige ~ income | type, data=Prestige, smoother=quantregLine, spread=TRUE)
scatterplot(weight ~ repwt | sex, spread=TRUE, data=Davis, smoother=loessLine)
scatterplot(weight ~ repwt | sex, spread=TRUE, data=Davis, smoother=gamLine) # messes up
scatterplot(weight ~ repwt | sex, spread=TRUE, data=Davis, smoother=quantregLine) # robust
set.seed(12345)
w <- 1 + rpois(100, 5)
x <- rnorm(100)
p <- 1/(1 + exp(-(x + 0.5*x^2)))
s <- rbinom(100, w, p)
scatterplot(s/w ~ x, smoother=gamLine,
smoother.args=list(family="binomial", weights=w))
scatterplot(s/w ~ x, smoother=gamLine,
smoother.args=list(family=binomial, link="probit", weights=w))
scatterplot(s/w ~ x, smoother=gamLine,
smoother.args=list(family=binomial, link="probit", weights=w))
scatterplot(s/w ~ x, smoother=loessLine, reg=FALSE)
y <- rbinom(100, 1, p)
scatterplot(y ~ x, smoother=gamLine, smoother.args=list(family=binomial))
Run the code above in your browser using DataLab