Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 487
ToNoY Avatar asked Mar 28 '14 16:03

ToNoY


People also ask

How do you calculate confidence interval and prediction interval in R?

To find the confidence interval in R, create a new data. frame with the desired value to predict. The prediction is made with the predict() function. The interval argument is set to 'confidence' to output the mean interval.

What is a fitted confidence interval?

The confidence interval tells you how tightly you have determined these values. If a confidence interval is very wide, your data don't define that parameter very well. Confidence intervals are computed from the standard errors of the parameters.

What is confidence interval in forecasting?

Confidence Intervals are estimates that are calculated from sample data to determine ranges likely to contain the population parameter(mean, standard deviation)of interest. For example, if our population is (2,6), a confidence interval of the mean suggests that the population mean is likely between 2 and 6.

What is the difference between loess and Lowess?

lowess is for adding a smooth curve to a scatterplot, i.e., for univariate smoothing. loess is for fitting a smooth surface to multivariate data. Both algorithms use locally-weighted polynomial regression, usually with robustifying iterations.


1 Answers

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

like image 141
Henry David Thorough Avatar answered Sep 18 '22 18:09

Henry David Thorough