Repository navigation
Conversation
|
fails locally for older scipy because of sparse which seems to have no elementwise power |
c6db1fa to
269a75c
Compare
|
Do we still support old python? like 2.7? where's my Hoorah, one out of six is green. |
|
The latest commit allows endog to be 2-D. only exog is required to be 1-D in the sparse linear algebra version. (I haven't checked the other ones.) vectorized univariate or multivariate?currently the filter is designed as univariate, but because of the dot product, the alternatives:
|
|
some notes so I don't forget playing a bit with polynomial filters it looks like we can construct Dette, Munk and Wagner type filters directly from a polynomial fit. This also means we can extend DMK type filters to use longer windows than implied by order, i.e. separate order from window length. This would be closer to HKT. There are some strange features of even length windows, because they don't center on an observation. In HKT the spike point is even at the end of the window for even length windows > 3. (window length = order + 1 always?) |
|
Last commit adds also direct pinv computation for polynomial filter. |
|
another follow-up idea: terminology: I'm currently using kernel and windows as two words with the same meaning. pick one |
|
related see scipy's savitzky_golay for a more complete implementation of polynomial filter with equal spaced data https://github.com/scipy/scipy/blob/master/scipy/signal/_savitzky_golay.py This means using the residuals of savitzky_golay should also produce the same variance estimate as DMK except for the treatment of edge effects and the possibility of window_length > order + 1. possible bug or other problem: my poly coefficients when not normed are different from savitzky_golay |
|
another indexing bug in my code (I'm not writing enough code anymore) Note: poly_order is defined one-off: my |
|
another agreement HKT spike window is a special case of poly_window with order=2, i.e. linear trend (not constant as I argued above) and So this looks good, and all we would need is poly_window/savitsky_golay plus the optimial (tabulated) HKT. |
|
a "strange" feature, odd and even poly_order have the same coefficients. but it's not the case for even window length (no verification for this, so bug is possible) |
|
another puzzle shouldn't fitting a polynomial if the data is a polynomial have residual = 0? and with normed=True: |
|
it does, with the right order everything matches the theory (as I understand it), (The only thing not verified is when we have unequal spaced exog. And checking API. I haven't seen a reference package for this for the unit tests, except for the savitzky_golay part.) |
|
http://www.stata-journal.com/article.html?article=st0109 about sample size: footnote 1 looks like we need many observations. |
|
Yatchew, Andrew. n.d. “Differencing Methods in Nonparametric Regression: Simple Techniques for the Applied Econometrician.” http://homes.chass.utoronto.ca/~yatchew/DifferencingPaper.pdf. 96 pages p. 18 He mentions that HKT table of coefficients has minor errors, and has a table that looks pretty different from HKT to me, e.g. spike is always in first position. |
ab40dde to
8a9d383
Compare
|
close to stopping here: It has all the basic features that I wanted, more refinements and applications can wait. The last commit added a memory for storing windows is nobs * window_length which is currently stored several times. theoretically unclear: degrees of freedom correction for variance calculation with local regression. I'm mixing several things between local polynomial fitting and the estimating variance literature. If variance estimation is the target, then Not checked yet: Is behavior of basic k-th order differencing really good with unequal spaced x on compact support? All articles that I looked at so far, only use equal spaced x in the simulations. (edit: commit amended and force pushed to remove print statements and add var_differencing unit test) |
8a9d383 to
3ac0c7c
Compare
|
It seems large parts of what I have "discovered" here in extending window_length beyond order+1 is (based on partial reading) already in Instead of local polynomial regression, they use the iterative dot product construction of the differencing filter for equal spaced similar exog similar to (another thought: using Lag-polynomials in analogy to a k times integrated moving average filter might also work conveniently for creating the convolution or filter coefficients, at least in the equal spaced case.) |
3ac0c7c to
2e8aae8
Compare
|
This pull request introduces 1 alert when merging 2e8aae8 into 8962c7f - view on LGTM.com new alerts:
Heads-up: LGTM.com's PR analysis will be disabled on the 5th of December, and LGTM.com will be shut down ⏻ completely on the 16th of December 2022. It looks like GitHub code scanning with CodeQL is already set up for this repo, so no further action is needed 🚀. For more information, please check out our post on the GitHub blog. |
This sounded useful when I stumbled on it, so I had to give it a try. It seems to work pretty well and the approach is becoming a bit more popular in recent years, although citation numbers are not very high.
y = f(x) + e where e ~ (0, \sigma^2)
f(x) is an unknown function.
If we estimate f(x) nonparametrically with a optimal bandwidth, then the bias is too high to get a good variance estimate in small samples. The alternative is to smooth in such a way that we get a good estimate for the variance. One such estimator is based on differencing the series (ordered with respect to x).
implementation is based on description in
Dette, H., A. Munk, and T. Wagner. 1998. “Estimating the Variance in Nonparametric Regression—what Is a Reasonable Choice?” Journal of the Royal Statistical Society: Series B (Statistical Methodology) 60 (4): 751–64. doi:10.1111/1467-9868.00152.
but I read or skimmed also a few more articles.
This PR also provides the residual for the smoothed variance estimation, so we could use another nonparametric or semi-parametric estimator for estimating a variance function depending on x.
right now it's mainly 3 ways to calculate the same variance, the simplest and should be fastest is using convolve which assumes equal spaced x or sufficient smoothness. Unequal spaced x can be handled with a sparse window filter, where I took part of the sparse matrix handling from the current hp_filter.
unit tests: just compare 3 different implementation to produce exactly the same number. Estimated variance looks close to true, data generating variance.
Usage Recommendation based on Dette, Munk and Wagner:
small sample in Dette, Munk and Wagner is 25 observations, other small sample behavior for nobs <=100.
I think what this implies is that
not yet checked: references on using this for nonparametric test of the mean function. (might be just like an f_test comparing ssr with var based on differencing estimator.
Dette, Munk 1998?