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

后端 未结 1 1815
终归单人心
终归单人心 2021-02-02 15:46

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(car         


        
相关标签:
1条回答
  • 2021-02-02 15:59

    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)
    

    lowess example

    0 讨论(0)
提交回复
热议问题