I've got a question about if there are any equivalent functions that use the Epanechnikov kernel as an estimator. So for example, I have some code where I use the "dnorm" and "dunif" functions as kernels for the normal kernel and boxcar kernel respectively within r. Is there a similar function in base R or will I just have to create a function to handle the Epanechnikov kernel as I have not been able to find any functions?
My second question is since the Epanechnikov kernel is defined from -1 to 1 for k(u)=3/4(1-u^2), how would my function work for any u value and standardize it into a density such as the dnorm and dunif function? As ultimately I wish to run it through a dataset to try to find the optimal bandwidth using general cross-validation with a few loop statements. An example code using the dunif function is found below,
Data=read.table(paste0("http://www.stat.cmu.edu/%7Elarry","/all-of-nonpar/=data/lidar.dat"), header=TRUE)x=Data$rangey=Data$logration=length(x)fit=rep(0,n)L=rep(0,n)h=seq(1,40,0.1)nh=length(h)UniGCV=rep(0,nh)UniCV=rep(0,nh)for (k in 1:nh){ for (i in 1:n){ fit[i]=sum(dunif((x[i]-x)/h[k],min=-1, max=1)*y)/ sum(dunif((x[i]-x)/h[k],min=-1, max=1)) L[i]=dunif(0,min=-1, max=1)/sum(dunif((x[i]-x)/h[k],min=-1, max=1)) } v=sum(L) UniGCV[k]=sum((y-fit)^2)*n/((n-v)^2) UniCV[k]=sum((y-fit)^2/(1-L)^2)/n}UniGCVplot(h,UniGCV, type="p", lty=1, col="red")Unihgcv=h[UniGCV==min(UniGCV)]min(Unihgcv)
Now using this code I get that the general cross-validation optimal bandwidth using the uniform/boxcar kernel is 27. And this is the same thing I wish to do using the Epanechnikov kernel.
Note: I've already done this for a normal kernel using the dnorm function and I'm trying to avoid using any necessary packages. Also, anything with UniCv can be ignored for now.
Thanks ahead of time.