Linear fit with Math.NET: error in data and error

2019-08-14 15:53发布

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?

1条回答
ゆ 、 Hurt°
2楼-- · 2019-08-14 16:20

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:

http://numerics.mathdotnet.com/docs/Regression.html#Simple-Regression-Fit-to-a-Line

查看更多
登录 后发表回答