sm.regression {sm}R Documentation

Nonparametric regression with one or two covariates.

Description

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.

Usage

 sm.regression(x, y, h, design.mat = NA, model = "none", weights =
                 NA, group = NA, ...)

Arguments

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.
model a character variable which defines a reference model. The values "none", "no effect", "linear" and "parallel" are possible.
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. The normal usage of this parameter is to associate observations with frequencies; if the weights are not integers, they are converted to integers, but in this case the standard errors and tests which are computed cannot be considered. This argument applies only to the case of one covariate. Use of this parameter is incompatible with binning; hence nbins must then be set to 0 or left at its default value NA.
group a vector of groups indicators (numeric or character values) or a factor
... other optional parameters are passed to the sm.options function, through a mechanism which limits their effect only to this call of the function; those relevant for this function are the following: display, hmult, h.weights, poly.index, band, add, ngrid, eval.points, xlab, ylab, zlab, hull, panel, lty, col; see the documentation of sm.options for their description.

Details

see Chapters 3, 4 and 5 of the reference below.

Value

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 TRUE, 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.

Side Effects

a plot on the current graphical device is produced, unless the option display="none" is set.

References

Bowman, A.W. and Azzalini, A. (1997). Applied Smoothing Techniques for Data Analysis: the Kernel Approach with S-Plus Illustrations. Oxford University Press, Oxford.

See Also

hcv, sm, sm.ancova, sm.binomial, sm.poisson, sm.regression.autocor, sm.survival, sm.options

Examples

#  An example with one covariate
x <- runif(100,-2, 2)
y <- x^2 + 2*x^3 + rnorm(50)/3
sm.regression(x, y, h=0.5)
sm.regression(x, y, col=2, add=TRUE)
#
u <-  sm.regression(x, y, h=h.select(x,y,method="cv"), display="none")
print(u$h)
#
#  An example with two covariates
x <- cbind(runif(100,-2, 2), runif(100,-2, 2))
y <- x[,1]^2 + x[,2]^2 + 0.7*x[,1]*x[,2] + rnorm(50)/3
sm.regression(x, y, h=c(1,1))
sm.regression(x, y, display="slice")

[Package sm version 2.1-0 Index]