Library: | smoother |
See also: | regxci regxcb regest regxbwsel lpregxest regxestp |
Quantlet: | regxest | |
Description: | computes the Nadaraya-Watson estimator for univariate regression. |
Usage: | mh = regxest(x {,h {,K} {,v} }) | |
Input: | ||
x | n x 2 matrix, the data. The first column contains the independent and the second column the dependent variable. | |
h | optional scalar, bandwidth. If not given, 20% of the range of x[,1] is used as default. | |
K | optional string, kernel function on [-1,1] or Gaussian kernel "gau". If not given, the Quartic kernel "qua" is used as default. | |
v | optional m x 1 vector, values of the independent variable on which to compute the regression. If not given, the (sorted) x is used as default. | |
Output: | ||
mh | n x 2 or m x 2 matrix, the first column represents the sorted first column of x or the sorted v and the second column contains the regression estimate on the values of the first column. |
library("smoother") library("plot") ; x = 4.*pi.*(uniform(200)-0.5) ; independent variable m = cos(x) ; true function e = uniform(200)-0.5 ; error term x = x~(m+e) ; mh = regxest(x,1) ; estimate function ; mh = setmask(mh, "line","blue") m = setmask(sort(x[,1]~m) , "line","black","thin") plot(x,mh,m)
The Nadaraya-Watson regession estimate (blue line) using Quartic kernel and bandwidth h = 1 and the true regression function (thin black line) are pictured.
library("smoother") library("plot") ; x = read("motcyc") ; read motorcycle data mhe = regxest(x,3,"epa") ; estimate function mhu = regxest(x,2,"uni") ; estimate function ; mhe= setmask(mhe,"line","green") mhu= setmask(mhu,"line","red") plot(x,mhe,mhu) ; graph functions
The Nadaraya-Watson regession estimates using Epanechnikov kernel (green line) and Uniform kernel (red line) are pictured.