sm.regression {sm} | R Documentation |
This function creates a nonparametric regression estimate from data consisting of a single response variable and one or two covariates. With one covariate, an interactive panel can be activated to control the smoothing parameter. In two dimensions a perspective plot of the estimated regression surface is produced. A number of other features of the construction of the estimate, and of its display, can be controlled.
sm.regression(x, y, h, design.mat=NA, hmult=1, h.weights=NA, poly.index=1, model="none", band=T, test=T, display="lines", add=F, ngrid=NA, eval.points=NA, weights=rep(1, n), xlab=NA, ylab=NA, zlab=NA, hull=T, panel=F, lty=1, col=1, eye.mult=c(-6, -8, 5), ...)
x |
a vector, or two-column matrix, of covariate values. |
y |
a vector of reponses. |
h |
a vector of length 1 or 2 giving the smoothing parameter. A normal kernel
function is used and h is its standard deviation.
|
design.mat |
the design matrix used to produce y when these are assumed to be the residuals
from a linear model.
|
hmult |
a factor which can be used to multiply the smoothing parameter before construction of the nonparametric regression estimate. |
h.weights |
a vector of weights which multiply the smoothing parameter used in the kernel function at each observation. |
poly.index |
an integer defining local constant (0) or local linear (1) smoothing. |
model |
a character variable which defines a reference model. The values
"none" , "no effect" and "linear" are possible.
|
band |
a logical flag controlling the production of a reference band for the reference model. A band will be produced only when there is a single covariate and two groups. |
test |
a logical flag controlling the production of a formal test, using the reference model as the null hypothesis. |
display |
The setting "none" will prevent any graphical output from being produced.
With one covariate, the default setting "lines" will produce the density
estimate, while the setting "se" will in addition produce a variability
band, showing the variability, but not the bias, of the estimate. In two
dimensions, the default setting "persp" will produce a perspective plot
of the estimate.
|
add |
a logical value which controls whether the estimate is added to the current plot. Its default value is F, which creates a new plot. This argument applies only with one covariate. |
ngrid |
the number of points in the regular grid used to plot the estimate.
With two covariates, ngrid refers to the number of points
along the axis in each dimension.
|
eval.points |
the points at which the estimate should be evaluated, for the values returned in the result of the function. This should be a vector for one covariate and a two-column matrix for two covariates. |
weights |
a vector which allows the kernel functions associated with the observations to take different weights. This is useful, in particular, when different observations have different precisions. This argument applies only to the case of one covariate. |
xlab |
the label attached to the x-axis. |
ylab |
the label attached to the y-axis. |
zlab |
the label attached to the z-axis (two covariate case only). |
hull |
a logical value which controls whether the estimate is evaluated and plotted only on grid points which fall within the convex hull of the data. When this argument is set to F, evaluation and plotting take place at all grid points where the contribution from at least one kernel function is non-negligible. Both of these settings ensure that the estimate is not evaluated at points where there are no observations nearby. This argument applies only to the case of two covariates. |
panel |
a logical value which controls the appearance of a panel display, in the case of one covariate. The panel can be used to alter the value of the smoothing parameter and in particular it can launch an animation. |
lty |
the line type used to plot the estimate. This argument applies only with one covariate. |
col |
an integer defining the colour used to plot the estimate. This argument applies only with one covariate. |
eye.mult |
a vector of length 3 defining the eye position for the perspective plot
in the two covariate case. The interpretation of this argument is similar
to the argument eye in the persp function. Here the argument
is automatically scaled to adjust for the different axis scalings.
|
... |
additional graphical parameters. |
see Chapters 3, 4 and 5 of the reference below.
a list containing the values of the estimate at the evaluation points,
the smoothing parameter and the smoothing parameter weights. If a reference
model has been specified and test
set to T, then the p-value of the test
is also returned. When there is only one covariate, the weights associated
with different obserations, an estimate of the error standard deviation and
the standard error of the estimate are also returned. If a reference model
has been specified, this standard error refers to the comparison between
the estimate and the reference model, and the values defining the reference
model are also returned.
none.
Bowman, A.W. and Azzalini, A. (1997). Applied Smoothing Techniques for Data Analysis: the Kernel Approach with S-Plus Illustrations. Oxford University Press, Oxford.
hcv
, sm.ancova
, sm.logit
, sm.poisson
, 'sm.regression.autocor',
sm.survival
# An example with one covariate x <- runif(100,-2, 2) y <- x^2 + rnorm(50) sm.regression(x, y, h=0.5) # An example with one covariate x <- cbind(runif(100,-2, 2), runif(100,-2, 2)) y <- x[,1]^2 + x[,2]^2 + rnorm(50) sm.regression(x, y, h=c(1,1))