Using MathNet.Numerics to fit regression line through origin

时间:2018-02-01 18:22:13

标签: c# linear-regression mathnet

I have two double arrays (double[] XValues, YValues) which contain physiological data.

On these data I currently perform an 'unconstrained' linear regression using:

Tuple<double, double> r = Fit.Line(XValues, YValues);
double YIntercept = r.Item1;
double Slope = r.Item2;

There are sound (physiological) reasons for allowing the user to examine the line of best fit when regression through the origin is enforced.

How can this be done using MathNet?

1 个答案:

答案 0 :(得分:1)

除了Fit.Line之外,还有一个更通用的Fit.LinearCombination函数。由于前者基本上试图在p0中找到p1y : x -> p0 * 1.0 + p1 * x,因此它也可以写为Fit.LinearCombination(XValues, YValues, x => 1.0, x => x)

您正在寻找原点的一条线,其中p0被强制为零。因此,我们的等式简化为y : x -> p1 * x,可以使用Fit.LinearCombination(XValues, YValues, x => x)计算。