0
$\begingroup$

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?

$\endgroup$
10
  • $\begingroup$ i am quite confuse what is your issue, because you have not used the limit (-1/2, 1/2) in your code? $\endgroup$ – Angel Nov 3 '18 at 5:38
  • $\begingroup$ If you want to use kernel by your own choice then other function allows this but not loess() $\endgroup$ – Angel Nov 3 '18 at 5:45
  • $\begingroup$ @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). $\endgroup$ – lydias Nov 3 '18 at 5:45
  • $\begingroup$ @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()? $\endgroup$ – lydias Nov 3 '18 at 5:47
  • $\begingroup$ 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. $\endgroup$ – Angel Nov 3 '18 at 5:48
0
$\begingroup$
library(npmlda)
library(KernSmooth)

readdata=BMACS
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") 
$\endgroup$
2
  • $\begingroup$ I'm not sure that is what I'm looking for. I do not understand the need for using a degree 3 model? And I think you missed the lines() function that graphs the curve. The set up still used x-lim as (-1/2, 1/2) and the old y-lim... $\endgroup$ – lydias Nov 3 '18 at 6:18
  • $\begingroup$ But you said that limit is not your issue, you want to use uniform Kernel. That's why I have used your provided info with uniform kernel. $\endgroup$ – Angel Nov 5 '18 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.