1

I am currently trying to use the robust version of a smoothing spline fit as suggested in Matlabs robust fit page. But when I plot the results(see below) it doesn't seem like the line fits the trend.

I am using smoothing splines to fit with a smoothing parameter of 1e-7 since I aim for a line with just a faint bend(just as you see in the picture, but it should actually fit the data).

Anyone that have an idea why the line does not fit the data better? Or is this simply how "bad" smoothing splines is at fitting?

EDIT: Thought I had checked the code well enough but turns out there was still an error in the plotting.

Data in .mat format. Isamples is ydata, and runorder_sample is xdata.

Here is a snipplet of my code:

%First pre fit
xdata = runorder;
ydata = I(i,:)';
fit1 = fit(xdata, ydata, 'smoothingspline','SmoothingParam', smoothingParam);
fdata = feval(fit1, xdata); %data points in fited curve
idx = abs(fdata-ydata) > 1.5*std(ydata); %index without outliers
outliers{i} = excludedata(xdata, ydata, 'indices', idx);
%real fit
[f{i}, ~, out] = fit(xdata, ydata, 'smoothingspline',...
    'SmoothingParam', smoothingParam, 'exclude', outliers{i});

(I am doing it in a loop for all rows of a matrix, hence the "i"s to save data for plotting).

  • Without data it is not that easy to help. Could you provide some? – Cleb Apr 10 '17 at 15:00
  • 1
    Yes of course, added the data used for the plot in .mat format, is that ok? – NewPerspective5 Apr 10 '17 at 15:11
  • Just for comparison ( as the manual states "p = 0 produces a least-squares straight-line fit to the data"): what does a standard straight-line fit give you? – mikuszefski Apr 11 '17 at 05:47
  • Oh gosh darn it it was a coding error in the plotting. The trend plot is not for the data plotted *facepalm*. Found the error and the problems is underlying subgroups in the data. Now I can handle it. – NewPerspective5 Apr 11 '17 at 08:11

0 Answers0