There's more...
The ggplot2 package includes an embedded method to calculate the LOESS curve. This is done using the geom_smooth() function, where we need to specify method="loess". The beauty of this method is that it can also plot the standard errors for the prediction. The two disadvantages of this, with respect to what we did previously, is that we can't use this approach to predict new observations, nor tune the parameters as much we want to (bandwidth, kernel type, and polynomial order). The bands will be wider (more imprecision), the fewer observations we have in an area or the more vertical dispersion we have. In this case, it is clear that the bands are wider at the start and at the end of the plot, as shown in the following example: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access