问题
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:
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
来源:https://stackoverflow.com/questions/27940868/linear-fit-with-math-net-error-in-data-and-error-in-fit-parameters