2

I am trying to use Math.NET to perform a simple linear fit through a small set of datapoints. Using Fit.Line I am very easily able to perform the linear fit and obtain the slope and intercept:

Tuple<double, double> result = Fit.Line(xdata, ydata);
var intercept = result.Item1;
var slope = result.Item2;

This is very simple, but what about errors?

Errors in y-data

My y-data might contain error bars, can Math.NET take these errors into account? There are no errors in x-data, just in y-data.

Errors in fit parameters

What about the error in the resulting fit parameters? The slope and intercept should have an error or at least some way for me to tell how good these parameters fit. Typically I think you'd use the covariance matrix and its diagonal elements would give the error in the parameters. I don't see any option to use that. Is Math.NET able to give me the fit parameter errors?

Piotr Leniartek
  • 1,177
  • 2
  • 14
  • 33
Nick Thissen
  • 1,802
  • 4
  • 27
  • 38

1 Answers1

2

I supouse you can use this line to measure the fit error:

GoodnessOfFit.RSquared(xdata.Select(x => a+b*x), ydata); // == 1.0

where 1 means PERFECT (exactly on the line) and 0 means POOR.

it is described in Math.NET documentation on that page:

Math.net - Curve Fitting: Linear Regression

MarkusEgle
  • 2,795
  • 4
  • 41
  • 61
Piotr Leniartek
  • 1,177
  • 2
  • 14
  • 33
  • Yes, but that gives me the overall goodness of the fit. What I want to know is the goodness of each of the fit parameters. In this case the slope and the intercept. They should each have their own uncertainty / error. – Nick Thissen Jan 23 '15 at 23:48
  • 1
    @NickThissen i don't understand how you want to measure `error` on each parameter? In my opinion such goodness have only sense and can be measured only on complete set of parameters as I described in answer. – Piotr Leniartek Feb 22 '15 at 21:37