Site icon R-bloggers

Smoothing time series with R

[This article was first published on Revolutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Smoothing is a statistical technique that helps you to spot trends in noisy data, and especially to compare trends between two or more fluctuating time series. It’s a useful visualization tool that I’m pleased to see cropping up more and more in statistical graphics on the Web — it’s now a staple in econometric charts and is heavily used in polling analysis. For example, here’s smoothing used to combine data from various polls over time on Obama’s job approval (from pollster.com).

The S language was, to the best of my knowledge, the first software that made statistical smoothing a core part of the graphics system: first with the lowess function and later with other more powerful alternatives. These days in R (S’s successor), loess (local polynomrial regression fitting) is the usual go-to alternative for smoothing. With just a couple of lines of code, you can take a noisy time series in R and overlay a smooth trend line to guide the eye. Nathan Yau at FlowingData shows us how to take data like this:


and, with just a few lines of R code and some touching-up in Illustrator, create a chart like this:


FlowingData: How to: make a scatterplot with a smooth fitted line

To leave a comment for the author, please follow the link and comment on their blog: Revolutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.