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

I tried to use the least squares method to regress, but it is 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!
回复: 如何用脚本计算出最符合的值?Hi Lala
我的理解是你需要一个值,这个值得取值范围为所有数据的最小值到最大值这个范围。这个值需要和11个组的两个端点进行条件判断。
我的思路是既然是一根水平线,因此f(x)=b。换个方法就是取一个值b,让b距离11个组最近的那个点的值的求和最小。
即,假设结果为b。那么整体的函数就是求, Y=min(abs(y1max-b),(y1min-b))+min(abs(y2max-b),(y2min-b))+...min(abs(y11max-b),(y11min-b))。对Y求最小。
你可以尝试整理这个函数然后求Y最小值时b的值,然后带入函数f(x)=b。应该就可以了。
Re: How to use script to calculate the most suitable value?thank you very much!
If there are more than one hundred groups of such data, should I edit the formula like this?
I still haven't thought of a good way.
Thanks again!
回复: 如何用脚本计算出最符合的值?x = Round( Beta[1] + 5 * Beta[2], 0 );