
Dear all,
I wrote a code which supposedly should create a function which performs a local linear regression at point x (lower case).
The issue is that I have no reference to check if indeed my code performs correctly a local linear regression. Is there any function in R that performs a local linear regression (to give conditional expectation which I am interested in and not graph) in order to doublecheck the results?
By the way the code that I wrote is the following (based on the equation 2.50 of Li & Racine book's page 81):
#x should be a 1xq matrix, X is a Nxq matrix of the q regressors, Y is the response variable Nx1 matrix,
#bw should the 1xq matrix of bandwidths
LL.reg < function(Y, X, x, bw){
N < nrow(Y)
q < ncol(X)
dX < Xmatrix(x, N, q, T)
kx < dnorm(dX/matrix(bw, N, q, T))
K < as.vector(apply(kx, 1, function(z) prod(z)))
cX < cbind(1, dX)
solve(t(cX)%*%diag(K)%*%cX)%*%t(cX)%*%diag(K)%*%Y
}
Thank you all
Dimitris
