locpol {locpol}R Documentation

Local Polynomial estimation.

Description

Formula interface for the local polynomial estimation.

Usage

    locpol(formula,data,weig=rep(1,nrow(data)),bw=NULL,kernel=EpaK,deg=1,
            xeval=NULL,xevalLen=100)
    confInterval(x)
    ## S3 method for class 'locpol'
residuals(object,...)
    ## S3 method for class 'locpol'
fitted(object,deg=0,...)
    ## S3 method for class 'locpol'
summary(object,...)
    ## S3 method for class 'locpol'
print(x,...)
    ## S3 method for class 'locpol'
plot(x,...)

Arguments

formula

formula as in lm, only first covariate is used.

data

data frame with data.

weig

Vector of weights for each observations.

bw

Smoothing parameter, bandwidth.

kernel

Kernel used to perform the estimation, see Kernels

deg

Local polynomial estimation degree (p).

xeval

Vector of evaluation points. By default xevalLen points between the min. and the max. of the regressors.

xevalLen

Length of xeval if it is NULL

x

A locpol object.

object

A locpol object.

...

Any other required argument.

Details

This is an interface to the local polynomial estimation function that provides basic lm functionality. summary and print methods shows very basic information about the fit, fitted return the estimation of the derivatives if deg is larger than 0, and plot provides a plot of data, local polynomial estimation and the variance estimation.

Variance estimation is carried out by means of the local constant regression estimation of the squared residuals.

confInterval provides confidence intervals for all points in x$lpFit$[,x$X], say those in xeval.

Value

A list containing among other components:

mf

Model frame for data and formula.

data

data frame with data.

weig

Vector of weight for each observations.

xeval

Vector of evaluation points.

bw

Smoothing parameter, bandwidth.

kernel

Kernel used, see Kernels

KName

Kernel name, a string with the name of kernel.

deg

Local polynomial estimation degree (p).

X, Y

Names in data of the response and covariate. They are also used in lpFit to name the fitted data.

residuals

Residuals of the local polynomial fit.

lpFit

Data frame with the local polynomial fit. It contains covariate, response, derivatives estimation, X density estimation, and variance estimation.

Author(s)

Jorge Luis Ojeda Cabrera.

References

Fan, J. and Gijbels, I. Local polynomial modelling and its applications\/. Chapman & Hall, London (1996).

Wand, M.~P. and Jones, M.~C. Kernel smoothing\/. Chapman and Hall Ltd., London (1995).

Crist'obal, J. A. and Alcal\'a, J. T. (2000). Nonparametric regression estimators for length biased data\/. J. Statist. Plann. Inference, 89, pp. 145-168.

Ahmad, Ibrahim A. (1995) On multivariate kernel estimation for samples from weighted distributions\/. Statistics & Probability Letters, 22, num. 2, pp. 121-129

See Also

locpoly from package KernSmooth, ksmooth and loess in stats (but from earlier package modreg).

Examples

    N <- 250
    xeval <- 0:100/100
    ##  ex1
    d <- data.frame(x = runif(N))
    d$y <- d$x^2 - d$x + 1 + rnorm(N, sd = 0.1)
    r <- locpol(y~x,d)
    plot(r)
    ##  ex2
    d <- data.frame(x = runif(N))
    d$y <- d$x^2 - d$x + 1 + (1+d$x)*rnorm(N, sd = 0.1)
    r <- locpol(y~x,d)
    plot(r)
    ## notice:
    rr <- locpol(y~x,d,xeval=runif(50,-1,1))
    ## notice x has null dens. outside (0,1)
    ## plot(rr) raises an error, no conf. bands outside (0,1).
    ## length biased data !!
    d <- data.frame(x = runif(10*N))
    d$y <- d$x^2 - d$x + 1 + (rexp(10*N,rate=4)-.25)
    posy <- d$y[ whichYPos <- which(d$y>0) ];
    d <- d[sample(whichYPos, N,prob=posy,replace=FALSE),]
    rBiased <- locpol(y~x,d)
    r <- locpol(y~x,d,weig=1/d$y)
    plot(d)
    points(r$lpFit[,r$X],r$lpFit[,r$Y],type="l",col="blue")
    points(rBiased$lpFit[,rBiased$X],rBiased$lpFit[,rBiased$Y],type="l")
    curve(x^2 - x + 1,add=TRUE,col="red")


[Package locpol version 0.8.0 Index]