hadley/ggplot2 — Issue #298: stat_smooth: level has no effect with loess
Author: wch
Created: 2011-12-14 20:17:18+00:00
State: open

I think this is a bug, or at the very least a problem with documentation. Someone emailed me asking about confidence intervals for loess fits. He was only able to get 68% confidence intervals.

These look the same:

```R
ggplot(cars, aes(x=speed, y=dist)) + geom_point() + stat_smooth()

ggplot(cars, aes(x=speed, y=dist)) + geom_point() + stat_smooth(level=.2)
```

According to the docs for `predict.loess()`, it doesn't actually support the `level` argument.

In `stat-smooth-methods.r`, it looks like it's trying to make predictions with the `level` and `interval` arguments, even though they're not supported by `predict.loess`.

```R
predictdf.loess <- function(model, xseq, se, level) {
pred <- stats::predict(model, newdata = data.frame(x = xseq), se = se,
level = level, interval = if(se) "confidence" else "none")
...
```

The docs for stat_smooth say that you can change the level -- if this isn't actually possible for loess, then it should probably be noted.

Also, it looks like `predict.loess` isn't exported from `stats`, even though other predict functions are. I wonder if that's a bug.

```R
> stats::predict.loess
Error: 'predict.loess' is not an exported object from 'namespace:stats'

> stats::predict.lm
function (object, newdata, se.fit = FALSE, scale = NULL, df = Inf,
interval = c("none", "confidence", "prediction"), level = 0.95,
...
...
```