Question: I want to use a [Savitzky-Golay](https://en.wikipedia.org/wiki/Savitzky%E2%80%93Golay_filter) filter to smooth some data. There is a right width to use based on the data that it is smoothing. A number of papers basically use "eyeball norm" on the parameters but that feels like voodoo.

How do I get a measure like AIC to tell me which implementation is the proper one to use?

When I think about AIC, I do so in terms of RSS, number parameters, and number of degrees of freedom. I can measure RSS for the smoothed data, but I don't know how to think about parameter count or number of degrees of freedom in this context. Hints or pointers would be appreciated. Clear explanation would be delightful.

I'm personally using either R, or LabVIEW, but the actual software package isn't important. 

Work so far: 

* [This post](http://www.mdpi.com/2072-4292/6/3/2024/pdf) says "k is 2 parameters, n is samples, use RSS"
without providing references or derivation.
* [This reference](http://www2.uaem.mx/r-mirror/web/packages/PoMoS/PoMoS.pdf) is about the 'PoMoS' library which claimes to use genetic algorithms and information criteria to find optimal polynomial structure of time-series.

References: 

* (R lib) <http://www.inside-r.org/packages/cran/pracma/docs/savgol>
* (NI lib) <http://zone.ni.com/reference/en-XX/help/371361H-01/lvanls/sgfil/>

Answer: 
Economists have some rules of thumb they use ... but they don't call it Savitzky-Golay (who wrote their paper in 1964), they call it [Hodrick-Prescott](https://en.wikipedia.org/wiki/Hodrick%E2%80%93Prescott_filter) (1997). [Actuaries call it Whittaker-Henderson graduation (the usual reference for Whittaker being his 1923 book, and for Henderson, papers in 1916 and 1924), so they do somewhat better at naming it for the right people. But it's basically just discrete smoothing splines, where derivatives of some order are replaced with differences of some order.]

However, those rules that are used for Hodrick-Prescott filtering are based on some assumptions and approximations and don't necessarily compare well with smoothing parameters chosen in other ways.

One thing you might do to choose a smoothing parameter is some form of crossvalidation (if you have an implementation that deals with missingness); if your primary aim is to forecast you could substitute mean square one-step ahead prediction error.

However, it's not hard to estimate degrees of freedom consumed by the fit; taking the approach in Ye (1998) [1] of summing the partial derivatives of the fit with respect to the observations $\sum\_i \frac{\partial \hat{y}\_i}{\partial {y}\_i}$ to obtain model d.f. (a definition which is consistent with our usual notions when we apply that to cases where our usual notions work).

In this particular case, this calculation is easily written as the trace of a matrix. If you can write $\hat{Y} = HY$ - which is easy in this case - then model df is the trace of $H$.

(You could argue for it from more basic considerations but this is a fairly intuitive way to look at it to my mind, and generalizes to a very wide array of methods for getting a some fit.)

[1] Ye, J. (1998),  

"On measuring and correcting the effects of data mining and model selection."  

*J Am Statist Assoc.*, **93**, pp120–31.
I don't think you can really avoid some subjectivity here. The whole concept of smoothing is based on the idea that there is some slowly-varying signal that will be more apparent or meaningful if you remove variation around it, and bandwidth is the parameter that determines where in frequency terms the line is drawn between signal and noise. That means that the ideal bandwidth is not simply a property of the data, but also of what you want to achieve.

If you can make explicit your objective for smoothing it may help to determine a sensible bandwith. For example if you just want "to make the chart look smooth" then eyeballing a selection and picking the one you like best does exactly what you want! Or perhaps you could pick a function to maximise such as at association between the smoothed series and some other series, but while this adds an objective element to the process you have still chosen both the series and measure of association.