[R] Local linear regression

Dimitris.Kapetanakis dimitrios.kapetanakis at gmail.com
Wed Mar 28 17:16:47 CEST 2012


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 double-check 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 <- X-matrix(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


--
View this message in context: http://r.789695.n4.nabble.com/Local-linear-regression-tp4512566p4512566.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list