Forcing robustfit to return an intercept
Hi,
I have datasets where I am plotting variance as a function of mean. The datasets have substantial heteroscedasticity but don’t really have high leverage outliers, as they are symmetric and n is large. I have Python code which uses HuberRegressor from sklearn.linear_model to fit a straight line. This works and I attach example below (from Python).
I am seeking to replicate this fit in MATLAB but have failed to get an intercept. I began with robustfit with the huber parameter. Whilst I get a line, the intercept is returned as zero with an SE of zero. So it is refusing to fit this parameter. In Python I get an intercept value. I tried various ways to get an intercept in MATLAB but all failed:
Adding a column of zeros to X and disabling the intercept in the CLI options of robustfit.
All the different fit types in robustfit.
Weighting the points in way similar to that in my short Python function. (https://github.com/datajoint/anscombe-numcodecs/blob/main/src/anscombe_numcodecs/estimate.py around line 63)
I tried fitlm both with and without the robust fit option.
All of the above result in a zero intercept. The only thing that gives me an intercept value is centering the X values around their mean. However, the fit fails badly on some datasets when I do this so I would like to avoid it. I have had no fit failures on the same data in Python.
I suspect what is happening is that the extreme heteroscedasticity makes the in SE of the intercept value very unreliable and MATLAB is somehow then choosing to avoid returning a value for it and sets it to zero. I don’t really care about the SE and significance, but I do need the intercept because I go on to use that value. Any idea how to force MATLAB to return it?Hi,
I have datasets where I am plotting variance as a function of mean. The datasets have substantial heteroscedasticity but don’t really have high leverage outliers, as they are symmetric and n is large. I have Python code which uses HuberRegressor from sklearn.linear_model to fit a straight line. This works and I attach example below (from Python).
I am seeking to replicate this fit in MATLAB but have failed to get an intercept. I began with robustfit with the huber parameter. Whilst I get a line, the intercept is returned as zero with an SE of zero. So it is refusing to fit this parameter. In Python I get an intercept value. I tried various ways to get an intercept in MATLAB but all failed:
Adding a column of zeros to X and disabling the intercept in the CLI options of robustfit.
All the different fit types in robustfit.
Weighting the points in way similar to that in my short Python function. (https://github.com/datajoint/anscombe-numcodecs/blob/main/src/anscombe_numcodecs/estimate.py around line 63)
I tried fitlm both with and without the robust fit option.
All of the above result in a zero intercept. The only thing that gives me an intercept value is centering the X values around their mean. However, the fit fails badly on some datasets when I do this so I would like to avoid it. I have had no fit failures on the same data in Python.
I suspect what is happening is that the extreme heteroscedasticity makes the in SE of the intercept value very unreliable and MATLAB is somehow then choosing to avoid returning a value for it and sets it to zero. I don’t really care about the SE and significance, but I do need the intercept because I go on to use that value. Any idea how to force MATLAB to return it? Hi,
I have datasets where I am plotting variance as a function of mean. The datasets have substantial heteroscedasticity but don’t really have high leverage outliers, as they are symmetric and n is large. I have Python code which uses HuberRegressor from sklearn.linear_model to fit a straight line. This works and I attach example below (from Python).
I am seeking to replicate this fit in MATLAB but have failed to get an intercept. I began with robustfit with the huber parameter. Whilst I get a line, the intercept is returned as zero with an SE of zero. So it is refusing to fit this parameter. In Python I get an intercept value. I tried various ways to get an intercept in MATLAB but all failed:
Adding a column of zeros to X and disabling the intercept in the CLI options of robustfit.
All the different fit types in robustfit.
Weighting the points in way similar to that in my short Python function. (https://github.com/datajoint/anscombe-numcodecs/blob/main/src/anscombe_numcodecs/estimate.py around line 63)
I tried fitlm both with and without the robust fit option.
All of the above result in a zero intercept. The only thing that gives me an intercept value is centering the X values around their mean. However, the fit fails badly on some datasets when I do this so I would like to avoid it. I have had no fit failures on the same data in Python.
I suspect what is happening is that the extreme heteroscedasticity makes the in SE of the intercept value very unreliable and MATLAB is somehow then choosing to avoid returning a value for it and sets it to zero. I don’t really care about the SE and significance, but I do need the intercept because I go on to use that value. Any idea how to force MATLAB to return it? curve fitting, robust fit, python MATLAB Answers — New Questions