How to get the confidence intervals for LOWESS fit using R?

╄→гoц情女王★ 提交于 2019-12-20 10:30:58

问题


I didn't find any satisfactory answer to the confidence intervals (CIs) for LOWESS regression line of the 'stats' package of R:

plot(cars, main = "lowess(cars)")
lines(lowess(cars), col = 2)

But I'm unsure how to draw a 95% CI around it?? However, I know I could get the estimated variance from

V = s^2*sum(w^2)

where, s2= estimated error variance, and w=weights applied to the X. Therefore, the 95% CIs should be

Y plus/minus 2*sqrt(V(Y))

I know there's a way of getting the CIs from loess fit, but I'd rather prefer LOWESS because it is robust. Thanks for your suggestions.


回答1:


You can do this with predict() and loess(). lowess is older than loess and has fewer features, though it is a bit faster. But in this context, I'd use loess as follows.

plot(cars)
plx<-predict(loess(cars$dist ~ cars$speed), se=T)

lines(cars$speed,plx$fit)
lines(cars$speed,plx$fit - qt(0.975,plx$df)*plx$se, lty=2)
lines(cars$speed,plx$fit + qt(0.975,plx$df)*plx$se, lty=2)



来源:https://stackoverflow.com/questions/22717930/how-to-get-the-confidence-intervals-for-lowess-fit-using-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!