How to calculate the best fit value with script?Hello everyone!
As shown in the figure: There are several sets of data, and their data are relatively close.
Each set of data has two values, large and small.
How to use scripts to find the optimal value of the red horizontal line in the figure:
It is required that this horizontal line is close to one of the endpoints that can hold the most data, and this line is required to be horizontal.

I tried using least squares for regression, but still not ideal.
Thank you experts!
ScriptingWindows回复: 如何用脚本计算出最符合的值?dt = Current Data Table();
m = Mean( dt[0, 2 :: 3] );
Column( "S" ) << Formula( If( Abs( H - m ) > Abs( L - m ), L, H ) );
dt << run formulas;
Column( "S" ) << deleteFormula;
ar = dt << GetAsMatrix( {4, 1} );
{Beta, VarBeta} = Least Squares Solve( ar[0, 1], ar[0, 2] );
x = round(Beta[1],0);Thanks Experts!