kreg                package:KernGPLM                R Documentation

_K_e_r_n_e_l _r_e_g_r_e_s_s_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     Calculates a kernel regression estimate (univariate or
     multivariate).

_U_s_a_g_e:

     kreg(x, y, bandwidth = NULL, grid = TRUE, p = 2, q = 2,
          product = TRUE, sort = TRUE)

_A_r_g_u_m_e_n_t_s:

       x: n x d matrix, data

       y: n x 1 vector, responses

bandwidth: scalar or 1 x d, bandwidth(s)

    grid: logical or m x d matrix (where to calculate the regression)

       p: integer or text, see 'kernel.function'

       q: integer, see 'kernel.function'

 product: (if d>1) product or spherical kernel

    sort: sort the data, necessary to use the DLL code

_D_e_t_a_i_l_s:

     The estimator is calculated by Nadaraya-Watson kernel regression.
     Future extension to local linear (d>1) or polynomial (d=1)
     estimates is planned.

_V_a_l_u_e:

     List with components: 

       x: m x d matrix, where regression has been calculated

       y: m x 1 vector, regression estimates

bandwidth: bandwidth used for calculation

df.residual: approximate degrees of freedom (residuals)

rearrange: if sort=TRUE, index to rearrange x and y to its original
          order.

_A_u_t_h_o_r(_s):

     Marlene Mueller

_S_e_e _A_l_s_o:

     'kernel.function', 'convol', 'kde'

_E_x_a_m_p_l_e_s:

       n <- 1000
       x <- rnorm(n)
       m <- sin(x)
       y <- m + rnorm(n)
       plot(x,y,col="gray")
       o <- order(x); lines(x[o],m[o],col="green")
       lines(kreg(x,y),lwd=2)

       ## two-dimensional
       n <- 100
       x <- 6*cbind(runif(n), runif(n))-3
       m <- function(x1,x2){ 4*sin(x1) + x2 }
       y <- m(x[,1],x[,2]) + rnorm(n)
       mh <- kreg(x,y)##,bandwidth=1)

       grid1 <- unique(mh$x[,1])
       grid2 <- unique(mh$x[,2])
       biv.reg <- t(matrix(mh$y,length(grid1),length(grid2)))
       orig.m <- outer(grid1,grid2,m)
       par(mfrow=c(1,2))
       persp(grid1,grid2,orig.m,main="Original Function",
             theta=30,phi=30,expand=0.5,col="lightblue",shade=0.5)
       persp(grid1,grid2,biv.reg,main="Estimated Function",
             theta=30,phi=30,expand=0.5,col="lightblue",shade=0.5)
       par(mfrow=c(1,1))
       
       ## now with normal x, note the boundary problem,
       ## which can be somewhat reduced by a gaussian kernel
       n <- 1000
       x <- cbind(rnorm(n), rnorm(n))
       m <- function(x1,x2){ 4*sin(x1) + x2 }
       y <- m(x[,1],x[,2]) + rnorm(n)
       mh <- kreg(x,y)##,p="gaussian")

       grid1 <- unique(mh$x[,1])
       grid2 <- unique(mh$x[,2])
       biv.reg <- t(matrix(mh$y,length(grid1),length(grid2)))
       orig.m <- outer(grid1,grid2,m)
       par(mfrow=c(1,2))
       persp(grid1,grid2,orig.m,main="Original Function",
             theta=30,phi=30,expand=0.5,col="lightblue",shade=0.5)
       persp(grid1,grid2,biv.reg,main="Estimated Function",
             theta=30,phi=30,expand=0.5,col="lightblue",shade=0.5)
       par(mfrow=c(1,1))

