# Uniform kernel estimator

For practice, I'm trying to provide an estimation for a nonparametric model on dataset BMACS from library (npmlda). I'm having trouble to set up a kernel estimator with Uniform(-1/2,1/2) kernel and bandwidth h = 0.5.

The outcome I'm interested in is CD4 over time, which I believe the initial set up should be:

fit.linear.1 <- loess(CD4 ~ Time , span =0.5 , degree=1, data=BMACS)

plot(CD4 ~ Time, data=BMACS,  xlab = "Time since infection (years)", ylab =
"CD4 percentage", ylim=c(0,65), cex=0.7, col='gray50', main="Local linear:
span=0.5")

lines(Time.int, predict(fit.linear.1 , data.frame(Time  = Time.int)),col=1,
lwd=2) mtext("A.", cex=1.3, side=3, line=0.7, font=2, at=-0.9)


I'm not very clear on what type of limit is represented by (-1/2, 1/2). If it is the limit for Time, then the smoothed curve will be too short to have any purpose for this analysis? If it is the range for the uniform kernel what function should I use for the setup that allows me to define a bandwidth?

Could anyone suggest a possible setup in R for the problem?

• i am quite confuse what is your issue, because you have not used the limit (-1/2, 1/2) in your code? – Angel Nov 3 '18 at 5:38
• If you want to use kernel by your own choice then other function allows this but not loess() – Angel Nov 3 '18 at 5:45
• @Angel I added xlim = c(-1/2,1/2) to my plot, but my question is actually not certain what (-1/2, 1/2) indicates. I want to have some confirmation that Uniform(-1/2, 1/2) is, in fact, referring to the x limit being (-1/2,1/2). – lydias Nov 3 '18 at 5:45
• @Angel what do you mean by my own choice? Can I express Uniform(-1/2, 1/2) in another way? Other than fitting with loess()? – lydias Nov 3 '18 at 5:47
• Uniform(-1/2, 1/2) tells the range of your variable and on the side xlim = c(-1/2,1/2) set the x-axis. Both are not same. – Angel Nov 3 '18 at 5:48

library(npmlda)
local_polynomial <- locpoly(y = readdata$$CD4, x = readdata$$Time, degree = 3, bandwidth = 0.5,        kernel = "Uniform")
plot(readdata$$CD4 ~ readdata$$Time, data= readdata,  xlab = "Time since infection (years)", ylab ="CD4 percentage",  xlim = c(-1/2,1/2), ylim=c(0,65), cex=0.7, col='gray50', main="Local linear: span=0.1")