LOESS Utility for Excel
by Jon Peltier
Wednesday, June 24th, 2009
Peltier Technical Services, Inc., Copyright © 2010.
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
In LOESS Smoothing in Excel I described a technique for smoothing data, which essentially runs a moving weighted regression on the data set. The amount of smoothing that can be achieved without washing out the data is remarkable. In that post I showed a screen shot of a dialog of a working LOESS utility.
The LOESS utility for Excel has been updated, and the interface made more flexible. The new version is described in LOESS Utility – Awesome Update, where there is a link to download the new utility.
I’ve used this utility in-house for a while, adding little enhancements here and there. I’ve come up with three main ways to use it, illustrated in the dialog screen shots below. Based on the option selected in the top of the dialog, the mode of operation is changed.
Here the data is arranged simply, with the input X and Y in two adjacent columns, and the output Y, calculated using the input X values, placed into the third adjacent column.

Here the input X and Y are in two columns, and the output Y is calculated using the input X values, but is located in another column. This is handy if you are calculating smoothed values for different values of alpha or N and placing the calculations in different columns.

Finally, the input X and Y values are in two adjacent columns, and the output X and Y are in two other adjacent columns, not adjacent to the input columns. Here the output X values need not be the same as the input X values.

When installed, the utility places a control on the PTS Charts menu. If you haven’t installed other PTS Chart Utilities, this menu will be created first.

Compare my weight over the past three years, smoothed using a seven-day moving average…

… and using the LOESS utility. The main trends are plainly visible, while the short term fluctuations have been removed.

The utility is a regular old Excel add-in, which can be downloaded in the zip file LOESS.zip (see the update below for a new version of the utility). Install this add-in using the protocol in Installing an Excel Add-In or Installing an Add-In in Excel 2007.
Try it out, and tell me what you hate about it.
Update 8 October 2009
The LOESS utility for Excel has been updated, and the interface made more flexible. It is described in LOESS Utility – Awesome Update, where there is a link to download the new utility.
Related Posts:
Posted: Wednesday, June 24th, 2009 under Utilities.
Comments: 17
Comments
Comment from derek
Time: Wednesday, June 24, 2009, 8:34 am
Jon, it looks very nice, but I have a couple of problems installing it. First it objects it “can’t find project or library”, then demands a password. Fortunately cancelling the password prompt results in an installation.
Then I had a problem understanding the instructions, and seeing where the LOESS series was going to be inserted. I think I got it right when I selected the third radio button, Separate XY input and output. Finally, I seem to have lost the ability to Cancel, OK. or Close the application; it responds to mouse clicks by depressing the buttons, but not by closing anything. So I can’t tell what happens in the final stage.
Okay, I killed Excel and restarted. Same password problem on install, but this time the radio button responded with a new range dialog box for the output range. That makes more sense, because I wasn’t sure what was going to happen when I filled in the range input box.
But when I filled the input box and went to fill the output box, something went wrong and I’m back to a stuck Excel. (the output range dialog box has disappeared, which probably happened the first time, but I didn’t notice it)
I’m using Excel 2000 SP3 in XP 5.1 SP3.
Comment from Jon Peltier
Time: Wednesday, June 24, 2009, 11:33 am
Sounds like a mishmash of this post and the previous one. I should have followed my own advice and saved the utility in Excel 2000 before posting it.
When I first opened the xla in Excel 2000, I experienced the same issues you’ve described. I unchecked the reference to the RefEdit control and saved the add-in. When I reopened it in 2000, it worked fine. When I reopened it in 2003 in turn, again all was fine.
Try the download again.
Comment from David
Time: Thursday, June 25, 2009, 8:19 am
Jon,
That’s a nice little add-in. I installed it and had it working in Excel 2007 in less than 5 minutes. I tried a basic curve using your default settings and it looks great. I tried tweaking the smoothing parameter up and down, but settled on the default values as the cleanest representation.
Thanks for the tool and the great tips in the blog.
David
Pingback from Mile Wide… Inch Deep… » LOESS in Excel: Big deal?
Time: Tuesday, June 30, 2009, 9:00 pm
[...] its simplicity and power. Take the LOESS function, for example. It’s built in to R. Excel needs a plug-in. Wow. Gotta love R. Used to love Excel, then I grew up (just a [...]
Comment from Brigt E
Time: Tuesday, July 7, 2009, 4:54 pm
Thanks for this one. Used this function today for a wage analysis at my company. By the way I’ve been rather fan of this blog, so keep up the good work. Hopefully my skills will evolve so that I one day can contribute to this community.
Best regards from Norway
Comment from Richard Berthelsdorf
Time: Wednesday, July 29, 2009, 7:43 pm
LOESS is a very neat and useful utility!
I discovered that it refuses to work if the spreadsheet is set to use the R1C1 reference style (I’m using Excel 2003).
Comment from Jon Peltier
Time: Wednesday, July 29, 2009, 10:24 pm
Richard -
I rarely use R1C1 notation, so I never noticed the error. Thanks for pointing it out. I’ll have to check into it.
Comment from Jon Peltier
Time: Friday, July 31, 2009, 6:09 pm
I think I’ve fixed the R1C1 problem. Try it again: LOESS Utility.
Comment from jeff weir
Time: Monday, September 21, 2009, 4:53 am
Hi Jon. I’ve been playing with this utility today, and found that while it does a great job of smoothing fairly small datasets, it doesn’t do so well with the large datasets with fairly regular cyclical swings that I’ve been feeding it today.
I’m guessing this is an artifact of who the LOESS technique works, rather than due to your fine utility.
In your original LOESS post, you say “For each X value where a Y value is to be calculated, the LOESS technique performs a regression on points in a moving range around the X value, where the values in the moving range are weighted according to their distance from this X value.” I’m guessing that the larger your dataset, the larger the moving range around the X value.
I was using it on some half-hourly electricity metering data. When I used the LOESS utility to smooth a week’s worth of data (336 points), I get a great looking curve compared to the rather ‘jagged’ appearance of the raw data. But when I use it to smooth the whole year (17520 points), I get a flat line. I was expecting to get a similar effect for the whole year’s worth of data as I did with a week’s worth…that is I thought I’d still see some swings etc.
Is this how you’d expect LOESS to work with such a large dataset?
Regards
Jeff
Comment from Jon Peltier
Time: Monday, September 21, 2009, 7:11 am
Jeff -
Since alpha is a fraction, the number of points in a LOESS analysis of larger data sets is larger than that for a smaller data set, given a constant alpha. If you get a reasonable smoothing for a week of data for a given alpha, note the number of points used for smoothing. Then carry out LOESS smoothing on the larger data set, using the same number of points (and a correspondingly smaller alpha).
Comment from Jeff Weir
Time: Monday, September 21, 2009, 7:37 pm
Ahhh…I didn’t realise you could overwrite the number of points. This utility rocks. I like how it retains the last range you used it on…handy if you want to rerun the function on the same range but just change a setting.
Some thoughts on improvement:
1. One thing that would be better is if when selecting a range you could use Shift + Cntl + Down to select really long ranges rather than having to drag down with the mouse. Is this possible? I see that Name Manager doesn’t let you do this either – so maybe it’s an artifact of constructing such addins?
2. In excel 2007, the PTS menu disappears from the addins ‘menu commands’ if you select the chart. For a moment, I thought it was suddenly uninstalled from my machine.
3. The function can also give a misleading match at each end of the series, because it has less data points with which to perform a regression on points in a moving range around the X value than it does everywhere else (and it might be substituting zero values for any missing data here, but I’m not sure). For an example of how a sine wave is affected, see my uploaded speadsheet at http://cid-f380a394764ef31f.skydrive.live.com/self.aspx/.Public/LOESS%20on%20SineWave.xls
To counter this, you could amend the function so that either:
- if it goes to perform a regression with say a moving range of 6 points then it doesn’t return data for the first 3 or the last 3 values; or
- in the above case, it substitutes any missing data from data it does have. For instance, in the above case, for the first point it would use the first 3 numbers twice instead of a moving range that has missing data points.
Alternately, the user could simply amend their range so that they use a subset of the LOESS function output that doesn’t include end values. But they might not be aware of this.
Regardless, this is staying on my ribbon! THanks Jon
Comment from Jon Peltier
Time: Tuesday, September 22, 2009, 6:49 am
Jeff -
1. The utility is constrained by how the RefEdit control works. You can select one cell, then use the mouse and scroll bars to find the opposite cell, nhold Shift, and click on the last cell.
1A. The latest version improves on this. If you only select the top cell of a column, the program uses the whole column, down to the first blank cell.
2. I didn’t add the command to the Chart menu bar, because I figured it was really a data kind of utility. You’ve convinced me otherwise. This will go into the newest edition, and I’ll post it sometime soon.
3. The utility uses the same number of points, but it is a one-sided fit, with points further away given a lower weighting. It’s not perfect, but it beats simple moving averages. Statisticians use this methodology, with the knowledge that there may be end effects.
Comment from DaleW
Time: Monday, October 5, 2009, 11:23 pm
Nice utility, Jon. Am I right that it needs at least 15 input points to avoid generating an overflow error, or am I doing something it wasn’t expecting?
Comment from jeff weir
Time: Monday, October 5, 2009, 11:29 pm
I got an overflow error one time when I didn’t select one of the output ranges properly. Maybe this is what’s going on for you, Dale?
Comment from DaleW
Time: Tuesday, October 6, 2009, 12:26 am
Well, Jeff, I got the overflow error roughly 20 for 20 times when I selected 14 pairs or less, and 0 for 8 times when I selected 15 pairs or more. Looks systematic to me. I even duplicated it from scratch with a new workbook.
Each time I was using the contiguous range option. It can accept fewer input points for separate I/O ranges without the overflow error, but with small N the output still isn’t right.
Since you aren’t having this problem, I’ll try again tomorrow with Excel 2003 on a different PC.
Comment from Jeff Weir
Time: Tuesday, October 6, 2009, 1:50 am
Interesting…if you do a pass with say 12 points using the default N (i.e. Number of points for the moving regression) of 5, then it bombs out. If you try again with N of 6, then it works. And then if you try again with N of 5, it works.
Comment from Jon Peltier
Time: Tuesday, October 6, 2009, 7:00 am
Dale & Jeff -
I’ve found the LOESS algorithm to be pretty robust. In the back of my head, the number of 4 points for the moving regression sounds familiar as a limit I’ve encountered, though most of my data sets are at least dozens of points, and I don’t think I’ve routinely gone below a double-digit N.
Stay tuned. I’ve made some enhancements to the utility that make range selection much easier. I’ll be posting the new version in a few days.



















Write a comment
I welcome comments from my readers. If you have an opinion on this post, if you have a question or if there is anything to add, I want to hear from you. Whether you agree or disagree, please join the discussion.
If you want to include an image in your comment, post it on your own site or on one of the many free image sharing sites, and include a link in your comment. I'll download your image and insert the necessary html to display the image inline.
Read the PTS Blog Comment Policy.