There seems to be two different interpretations of what LOWESS really means: one from R (also used by python-statsmodels), and one from MATLAB (also used by biopython), see comparison below.
Could someone enlighten me as to which of these is "correct", or "preferable" (for some unspecified meaning of "correct" or "preferable", of course...)?
R
> lowess(c(rep(0, 10), rep(1, 10)), iter=1)
$x
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
$y
[1] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
[7] 0.00000000 0.03796574 0.29511209 0.44982749 0.55017251 0.70488791
[13] 0.96203426 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000
[19] 1.00000000 1.00000000
statsmodels
In [1]: sm.nonparametric.lowess([0] * 10 + [1] * 10, range(20), it=1)
Out[1]:
array([[ 0. , 0. ],
[ 1. , 0. ],
[ 2. , 0. ],
[ 3. , 0. ],
[ 4. , 0. ],
[ 5. , 0. ],
[ 6. , 0. ],
[ 7. , 0.03796574],
[ 8. , 0.29511209],
[ 9. , 0.44982749],
[ 10. , 0.55017251],
[ 11. , 0.70488791],
[ 12. , 0.96203426],
[ 13. , 1. ],
[ 14. , 1. ],
[ 15. , 1. ],
[ 16. , 1. ],
[ 17. , 1. ],
[ 18. , 1. ],
[ 19. , 1. ]])
MATLAB
>> smooth([zeros(1, 10), ones(1, 10)], 2/3, 'lowess')
ans =
-0.1025
-0.0727
-0.0389
-0.0006
0.0426
0.0905
0.1423
0.2009
0.3159
0.4383
0.5617
0.6841
0.7991
0.8577
0.9095
0.9574
1.0006
1.0389
1.0727
1.1025
biopython
In [1]: Bio.Statistics.lowess.lowess(np.arange(20), [0] * 10 + [1] * 10, iter=1)
Out[1]:
array([ -1.02539957e-01, -7.27167655e-02, -3.88897911e-02,
-5.58395479e-04, 4.25959843e-02, 9.05430839e-02,
1.42295872e-01, 2.00914331e-01, 3.15916819e-01,
4.38280105e-01, 5.61719895e-01, 6.84083181e-01,
7.99085669e-01, 8.57704128e-01, 9.09456916e-01,
9.57404016e-01, 1.00055840e+00, 1.03888979e+00,
1.07271677e+00, 1.10253996e+00])
lowess
implementation is based are given in the documentation. Seehelp("lowess")
, which also points to a file in the stats package source code, which includes a test case. $\endgroup$R
actually has (at least) two lowess implementations (lowess
andloess
), both of which are controlled with several parameters. Unless you consult the documentation for all your software and carefully make sure you are matching parameters correctly, any differences you are observing could be attributed to differences in default settings. Moreover, because these are exploratory smooths, "correct" and "preferable" have no meaning; what is important is understanding how to control your software to achieve the degree of smoothing you want. $\endgroup$lowess
are iter (iter=0 gives yet another another value), frac (which defaults to 2/3) and delta (setting delta=0 doesn't seem to make a difference). For MATLAB, the only parameter isfrac
(which I set to 2/3 for these comparisons). So I believe there isn't any difference there... $\endgroup$