1

I have some data where I need to perform a simple linear regression. The problem is that there are outliers that I need to eliminate so I use cftool and remove them from the regression. I have the following code

cftool(avg_strain_values,avg_stress_values);

When cftool loads up the standard equation is a polynomial which I have to manually change to y=ax+b. My question is this: is there a way to call cftool and change the equation automatically? Or do I have to do it manually every time? In the documentation and around the web there is mention of fit and that can do it but when I tried it, I can't eliminate outliers.

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
enea19
  • 113
  • 1
  • 11
  • I think it might be simpler to come up with a criterion for what are considered "outliers" and just do this process automatically. You can also try robust regression using e.g. [**bisquare** weights](https://www.mathworks.com/matlabcentral/answers/183690), [`robustfit`](https://www.mathworks.com/help/stats/robustfit.html). – Dev-iL May 24 '18 at 08:10
  • Everything you can do in `cftool` is possible using `fit`. `cftool` is essentially just a GUI around the `fit`. Think what exactly do you do in `cftool`, and put that in `fit`, and that should solve your problem how to do it programmatically. To eliminate outliers, fit(..., 'robust', 'Bisquare') should generally do it. But to really help you further, you should put sample data and fits and what you do in cftool. As for the "call `cftool` and change equation automatically" - it might be possible, but I don't know how. I always stick to `fit` and play with the stuff there. – Zizy Archer May 24 '18 at 08:13

1 Answers1

1

No.

There is no simple way to control cftool programatically, but there's also no reason to do so, since the same can be achieved using the various fitting/regression functions.

  • If, when fitting, you have a criterion you can evaluate to know which points are the outliers, you can specify them (or the criterion itself, see docs) to the fitting algorithm using

      fit(..., 'Exclude', [1,3,7])
    

    See other options for Exclude in the documentation.

  • If you don't know a priori which points are outliers, you can use some form of robust regression (as mentioned in the comments: robustfit, fit(..., 'Robust', 'Bisquare')), which weights apparent outliers more weakly.

See also: Robust Regression — Reduce Outlier Effects, Remove Outliers Programmatically.

Community
  • 1
  • 1
Dev-iL
  • 23,742
  • 7
  • 57
  • 99
  • Robust regression is an excellent suggestion. You might also get a better fit with orthogonal regression which is worth a try. – James Phillips May 24 '18 at 14:59