Learn R Programming

NonpModelCheck (version 1.0)

plot3d.localpoly.reg: 3d plot from a local polynomial fit

Description

Create a 3d plot from a local polynomial fit of two covariates and a response variable.

Usage

plot3d.localpoly.reg(X,Y, bandwidth = 0, gridsize = 30, degree.pol = 0,
   kernel.type = "epanech", gridsurface = 30, xlab=expression(X_1),
   ylab=expression(X_2), zlab=expression(Y), theta = 30, phi = 30, 
   expand = 0.5, col = "lightblue", ltheta = 120, shade = 0.75, 
   ticktype = "detailed", pch = 16,...)

Arguments

X
n by 2 matrix with observations, rows corresponding to data points and columns correspond to covariates.
Y
vector of observed responses.
bandwidth
bandwidth, vector or matrix. If 0, leave-one-out cross validation with criterion of minimum MSE is performed to select a unique bandwidth that will be used for all dimensions of X; if -1, Generalized Cross Validation is performed to select a unique bandwi
gridsize
number of possible bandwidths to be searched in cross-validation. If left as default 0, gridsize is taken to be 5+as.integer(100/d^3). If cross-validation is not performed, it is ignored.
degree.pol
degree of the polynomial to be used in the local fit.
kernel.type
kernel type, options are "box", "trun.normal", "gaussian", "epanech", "biweight", "triweight" and "triangular". "trun.normal" is a gaussian kernel truncated between -3 and 3.
gridsurface
number of points on each axis at which to estimate the local polynomial surface.
xlab
parameter for persp
ylab
parameter for persp
zlab
parameter for persp
theta
parameter for persp
phi
parameter for persp
expand
parameter for persp
col
parameter for persp
ltheta
parameter for persp
shade
parameter for persp
ticktype
parameter for persp
pch
parameter for persp
...
further parameters for plotting persp

Value

  • Xthe same input matrix
  • Ythe same input response vector
  • pointspoints at which to get smoothed values
  • bandwidthbandwidth used for the polynomial fit
  • predictedmatrix with the predicted values at grid points

Details

Uses function "persp" to plot the estimated surface of a local polynomial fit in a nonparametric model with two covariates. The surface is estimated at points of a grid with size "gridsurface", which are evenly distributed between the minimum and maximum of the observed predictors. It also adds the observed points to the plot.

See Also

localpoly.reg

Examples

Run this code
X = matrix(0,50,2)
X[,1] = runif(50,-2,2)
X[,2] = runif(50,-2,2)
Y = 4*sin(pi*X[,1]) + X[,2] + rnorm(50)

plot3d.localpoly.reg(X,Y, bandwidth=-2, gridsize = 15, degree.pol = 0, gridsurface=20)

Run the code above in your browser using DataLab