


Hello
 
I've written previously about my problem with the Nadaraya-Watson kernel estimator
this is a copy of my message
-------------------------------------------------------------------------------------------------------------------
 Hello
 
i want to compute the Nadaraya-Watson kernel estimation when the kernel function is Epanchincov kernel
i use the command
ksmooth(x, y, kernel="normal", bandwidth ,....)
 
the argmunt ( kernel="normal" ) accept normal and box kernels
i want to compute it if the kerenl = Epanchincov
 
 
thank you
---------------------------------------------------------------------------------------------------------------------
I thought that programing the NW formula, but i did not get a results equal to the command's results
This is my trying
please help me and correct to me
 #ksmooth command
 n=100   #sample size
set.seed(123)
E<-rnorm(n,mean=0,sd=0.1)    #the random error
X<-runif(n, min = 0, max = 1)  #the explanatory variable
mx=1-X+exp(-200*(X-0.5)^2)   #the regression function
Y <- mx+E                               #the observations # Edit on the range of the bandwidth (bw.ucv)
hmax <- 2 * sqrt(var(X)) * n^(-1/5) 
lower = 0.01 * hmax              
h<- bw.ucv(X,nb = 1000, lower=lower, upper=hmax, tol=0.1*lower);h    #the bandwidth
  
estnw<- ksmooth(X, Y, kernel = "normal", bandwidth = h, x.points = X)
plot(X,Y)    #the scatter plot
lines(estnw, col=2)   #the fitted curve
plot(estnw$x,estnw$y)      #Successive points   # my program    NW=sum(W*Y)   ;where W=k((xi-x)/h) / sum(k((xi-x)/h))      and sum(W)=1
set.seed(90)
xgrid <- seq(min(X)-1,max(X)+1,length=100)K <- function(x) 1/sqrt(2*pi)*exp(-(x^2)/2)      #normal kernel function
W_1 <- sapply(X, function(x) K((xgrid - x)/h))    
W <- colSums(W_1)/sum(W_1)      #the weight function Wsum(W)            #the sum of the wehigths =1NW <- W*Y
plot(X,NW)      #un-successive points   
 
 
RegardsK. Hamed

 		 	   		  
	[[alternative HTML version deleted]]

