问题描述
对于R的统计"数据包的LOWESS回归线的置信区间(CI),我找不到任何令人满意的答案:
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)
但是我不确定如何围绕它绘制95%的CI?但是,我知道我可以从中获取估计的差异
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)
其中,s2 =估计误差方差,w =应用于X的权重.因此,95%CI应该是
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))
我知道有一种方法可以使黄土适合CI,但是我更喜欢LOWESS,因为它很坚固.感谢您的建议.
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.
推荐答案
您可以使用predict()
和loess()
进行此操作. lowess
比loess
更旧,并且功能较少,但速度更快.但是在这种情况下,我将按以下方式使用loess
.
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)
这篇关于如何使用R获得LOWESS拟合的置信区间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!