需要協助編寫從雙變量擬合中提取 R^2 和斜率的最佳程式碼全部,
我想請求社群將我推向正確的方向。
我需要從報告中提取 R^2 和斜率並將其顯示在繪圖本身上,如下所示:

我將透過解析顯示樹然後研究將圖形腳本新增至繪圖本身來完成此操作。
但是,由於這項任務在我看來非常標準和常規,因此在深入研究顯示樹之前我必須問幾個問題:
1. 有更直接的方法嗎?像是組合資料表(給出斜率但不給出 R^2)用於取得數字或像圖形產生器中的Line Of Fit( X, Y, Legend( 5 ), R²( 1 ), Equation( 1 ) ) (客戶想要使用二元擬合)
2. 也許有人已經準備好用於此任務的程式碼片段?
大規模客製化回复:需要幫助編寫最佳代碼以從雙變量擬合中提取 R^2 和斜率Names Default To Here(1);
dt=Open("$SAMPLE_DATA/Tablet Production.jmp");
biv=dt<<BIVARIATE></BIVARIATE>回复:需要幫助編寫最佳代碼以從雙變量擬合中提取 R^2 和斜率這是一個可以幫助您入門的示例。

Names Default To Here( 1 );
// Open Data Table: big class.jmp
// → Data Table( "big class" )
dt = Open( "$SAMPLE_DATA/big class.jmp" );
biv = Bivariate( Y( :height ), X( :weight ), Fit Line( {Line Color( {212, 73, 88} )} ) );
Report( biv )[framebox( 1 )] << add graphics script(
Text Color( {212, 73, 88} );
xMin = Current Report()[axisbox( 2 )] << get min;
yMin = Current Report()[axisbox( 1 )] << get min;
xMax = Current Report()[axisbox( 2 )] << get max;
yMax = Current Report()[axisbox( 1 )] << get max;
textList = {};
Insert Into( textList, xMin + (xMax - xMin) * .25 );
Insert Into( textList, yMax - (yMax - yMin) * .1 );
R2 = Current Report()["Summary of Fit"][Number Col Box( 1 )][1];
R2 = "R^2 = " || Format( R2, "Fixed Dec", 5, 3 );
Text( Right Justified, textList, R2 );
textList = {};
Insert Into( textList, xMin + (xMax - xMin) * .32 );
Insert Into( textList, yMax - (yMax - yMin) * .15 );
Slope = Current Report()["Parameter Estimates"][Number Col Box( 1 )][2];
Slope = "Slope = " || format(Slope,"Fixed Dec",9,5);
Text(Right Justified, textList, Slope);
);
report(biv)["Linear Fit"] << visibility("collapse");
report(biv)[PictureBox(2)] << visibility("collapse");
添加圖形和顯示樹操作的文檔可以在腳本指南和腳本索引中找到
回复:需要幫助編寫最佳代碼以從雙變量擬合中提取 R^2 和斜率我也需要圖形,它必須是雙變量擬合。 以前,客戶截取了下面報告的圖表和部分屏幕截圖,以包含斜率和 R^2(基本上是我最初問題中的圖像,沒有紅色標記)。 我正在自動化整個事情,我想擺脫報告,只在圖本身上寫下這兩個值(如我的屏幕截圖所示,圖上有紅色文本)。
回复:需要幫助編寫最佳代碼以從雙變量擬合中提取 R^2 和斜率是的,我已經編寫了腳本(正如我在最初的問題中提到的,通過添加很容易擬合線(X、Y、圖例(5)、R²(1)、方程(1))進入 Graph Builder 代碼),但是,客戶出於某種原因不喜歡 Graph Builder,並堅持使用 Bivariate Fit。
回复:需要幫助編寫最佳代碼以從雙變量擬合中提取 R^2 和斜率如果您只需要這些值,而不是圖表,您可以使用 Linear Regression() 函數,並從那裡獲取值
Names Default To Here( 1 );
// Open Data Table: big class.jmp
// → Data Table( "big class" )
dt = Open( "$SAMPLE_DATA/big class.jmp" );
/*Simple Linear Regression: y = intercept + beta * x + error*/
y = :height << get values;
X = :weight << get values;
{Estimates, Std_Error, Diagnostics} = Linear Regression( y, X, <<PRINTTOLOG></PRINTTOLOG>
rsquare = 0.502917160762804;
slope = 0.135507698709946;
回复:需要幫助編寫最佳代碼以從雙變量擬合中提取 R^2 和斜率您可以真正接近 Graph Builder
Equation includes the slope.Equation includes the slope.Equation includes the slope.方程包括斜率。
回复:需要幫助編寫最佳代碼以從雙變量擬合中提取 R^2 和斜率至少有三種不同的方法可以獲取這些值:
- 使用您選擇的方法從雙變量報告中獲取它們
- 使用 Make Into Data Table/Make Combined Data Table 獲取它們,並從創建的數據表中獲取它們
- 使用矩陣函數
在這種情況下,我會使用選項 1 或 2,因為無論如何您都必須創建 Bivariate