從二元圖中提取因子範圍如何有效地提取該曲線及其 95% CI 與任意 Y 值的交點。

dt = Open( "$sample_data/Growth.jmp" );
biv = Bivariate(
Y( :age ),
X( :ratio ),
Fit Line( {Line Color( {204, 121, 41} )}, save studentized residuals ),
SendToReport(
Dispatch(
{},
"Bivar Plot",
FrameBox,
{Grid Line Order( 3 ), Reference Line Order( 4 )}
)
)
);
biv << (Curve[1] << Save Studentized Residuals);
biv2 = Bivariate(
Y( :Studentized Residuals age ),
X( :ratio ),
Fit Polynomial( 2, {Confid Shaded Fit( 1 ), Line Color( {212, 73, 88} )} ),
SendToReport(
Dispatch(
{},
"ratio",
ScaleBox,
{Min( 0.2796875 ), Max( 1.2666259765625 ), Inc( 0.2 ), Minor Ticks( 1 )}
),
Dispatch(
{},
"Studentized Residuals age",
ScaleBox,
{Add Ref Line( 1.96, "Solid", "Black", "", 1 ),
Add Ref Line( -1.96, "Solid", "Black", "", 1 )}
)
)
);所以我想獲得曲線及其 95%CI 交叉 +/- 1.96 的比率值(總共 6 個值)。 有沒有比我能想到的蠻力更好的解決方案:將預測值和平均置信極限公式轉儲到表中,並將帶有值的行添加到表中以查看它何時超過限制?
高級統計建模數據存取數據探索和可視化大規模定制回复:從二元圖中提取因子範圍擴展於@Craige_Hales和@馬克貝利的代碼,您可以執行如下操作來找到總體最小值,然後將其用作每側後續搜索的界限,這樣您就不會那麼依賴初始值。另外,如果您使用平方而不是絕對值,則可以消除角點。 但在實踐中,我很幸運地使用了絕對值和其他函數,並在分析器的優化器中進行了步驟更改。
Names Default To Here( 1 );
// example data set
dt = Open( "$sample_data/Growth.jmp" );
// fit first-order polynomial model to response
biv = Bivariate(
Y( :age ),
X( :ratio ),
Fit Line
);
// save residuals for next step
biv << (Curve[1] << Save Studentized Residuals);
biv << Close Window();
// fit second-order polynomial model to residuals
biv = Bivariate(
Y( :Studentized Residuals age ),
X( :ratio ),
Fit Polynomial( 2, {Confid Shaded Fit( 1 ), Line Color( {212, 73, 88} )} )
);
// save formulas for lower / upper 95% confidence bound
biv << (Curve[1] << Mean Confidence Limit Formula);
// get formulas
fUpper = Column( dt, N Cols( dt ) ) << Get Formula;
fLower = Column( dt, N Cols( dt ) - 1 ) << Get Formula;
// replace predictor name with x
fsUpper = Substitute( Name Expr( fUpper ), Expr( :ratio ), Expr( x ) );
fsLower = Substitute( Name Expr( fLower ), Expr( :ratio ), Expr( x ) );
// initialize x, could get x that predicts mean residual = 0
x = 0.5;
// find the minimum of the whole expression, one solution will fall above and one below this value
fOverallMin = Name Expr( fsLower );
Minimize( fOverallMin, { x } );
xOverallMin = x;
// find where the value cross the x axis on each side of the overall min
x = xOverallMin - 1;
fMinCrossingTarget = Insert( Expr( Power() ), Insert( Expr( add(-1.96) ), Name Expr( fsLower ) ) );
Minimize( fMinCrossingTarget, { x(-1000, xOverallMin) } );
xMinLower = x;
x = xOverallMin + 1;
Minimize( fMinCrossingTarget, { x(xOverallMin, 1000) } );
xMinUpper = x;
x = xOverallMin - 1;
fMaxCrossingTarget = Insert( Expr( Power() ), Insert( Expr( add(-1.96) ), Name Expr( fsUpper ) ) );
Minimize( fMaxCrossingTarget, { x(-1000, xOverallMin) } );
xMaxLower = x;
x = xOverallMin + 1;
Minimize( fMaxCrossingTarget, { x(xOverallMin, 1000) } );
xMaxUpper = x;
show(xOverallMin, xMinLower, xMinUpper, xMaxLower, xMaxUpper);
回复:從二元圖中提取因子範圍您可以調整因子網格(從紅色三角形重置因子網格)以僅獲得一個限製或另一個限制。
回复:從二元圖中提取因子範圍我認為問題在於絕對值函數製作的曲線沒有很好的導數,使得最小化可能失敗。 我希望@ih這個想法會迫使最小化留在正確的鄰域,但也許不是。
我現在沒有時間去思考它;對於這個問題,似乎有一個標準的替代方案來解決這個問題......產生更平滑的功能。 (也許是平方?類似的東西。)
編輯:你的結果與我的一致,這就是為什麼我有關於目視檢查的評論。 abs 函數在函數中形成一個角以最小化,最小化函數使用該角附近的斜率,並且它期望答案的每一側都有一個連續(二階?)導數。 由於坡度即刻翻轉真實答案的每一面,令人驚訝的是有時會得到接近的答案。 我認為日誌中的消息可能是因為這個。
回复:從二元圖中提取因子範圍我拼命地嘗試想出一個起始點的算法,例如,我使用二次公式來計算與 1.96 交叉的預測曲線,即使你將該數字代入起始條件,你也會得到相當不可預測的行為:

因此,感謝您展示如何使用它,我確實從這個示例中學到了很多東西,但它還不夠強大。
回复:從二元圖中提取因子範圍@Craige_Hales ,為了解決初始值問題,如果您首先最小化整個函數,您可以使用該比率作為最小化搜索的限制,並保證找到每一側的值。 對於這個問題,可能是 0.8:
Minimize( fa, { x([very small number],[min ratio - found from minimizing the function]) } );
//For this example -10 is arbitrary (could use -1E6 or something), and 0.8 is
//roughly the overall function minimum
Minimize( fa, { x(-10,0.8) } );
回复:從二元圖中提取因子範圍微小變化
offset = 1.96;
// (I do not know how to pick these without a visual examination of the result.)
startingPoint = 1.1; // or 0.5 (trial and error. pick something close and check.)
// example data set
dt = Open( "$sample_data/Growth.jmp" );
// fit first-order polynomial model to response
biv = Bivariate( Y( :age ), X( :ratio ), Fit Line );
// save residuals for next step
biv << (Curve[1] << Save Studentized Residuals);
biv << Close Window();
// fit second-order polynomial model to residuals
biv = Bivariate( Y( :Studentized Residuals age ), X( :ratio ), Fit Polynomial( 2, {Confid Shaded Fit( 1 ), Line Color( {212, 73, 88} )} ) );
// save formulas for lower / upper 95% confidence bound
biv << (Curve[1] << save predicteds);
biv << (Curve[1] << Mean Confidence Limit Formula);
// get formulas, using order columns were saved
fupper = Column( dt, N Cols( dt ) ) << Get Formula;
flower = Column( dt, N Cols( dt ) - 1 ) << Get Formula;
fpredicted = Column( dt, N Cols( dt ) - 2 ) << Get Formula;
// replace predictor name with x
fsupper = Substitute( Name Expr( fupper ), Expr( :ratio ), Expr( x ) );
fslower = Substitute( Name Expr( flower ), Expr( :ratio ), Expr( x ) );
fspredicted = Substitute( Name Expr( fpredicted ), Expr( :ratio ), Expr( x ) );
fsupper2 = Substitute( Expr( a - offset ), Expr( a ), Name Expr( fsupper ) ); // find zero at offset
fslower2 = Substitute( Expr( a - offset ), Expr( a ), Name Expr( fslower ) ); // find zero at offset
fspredicted2 = Substitute( Expr( a - offset ), Expr( a ), Name Expr( fspredicted ) ); // find zero at offset
// initialize x, could get x that predicts mean residual = 0
x = startingPoint;
// minimize expression that is Abs( residual ), or mean = 0
faupper = Insert( Expr( Abs() ), Name Expr( fsupper2 ) );
Minimize( faupper, {x} );
xupper = x;
Show( xupper, Eval( faupper ) );
// initialize x, could get x that predicts mean residual = 0
x = startingPoint;
// minimize expression that is Abs( residual ), or mean = 0
falower = Insert( Expr( Abs() ), Name Expr( fslower2 ) );
Minimize( falower, {x} );
xlower = x;
Show( xlower, Eval( falower ) );
// initialize x, could get x that predicts mean residual = 0
x = startingPoint;
// minimize expression that is Abs( residual ), or mean = 0
fapredicted = Insert( Expr( Abs() ), Name Expr( fspredicted2 ) );
Minimize( fapredicted, {x} );
xpredicted = x;
Show( xpredicted, Eval( fapredicted ) );
// add lines on plot
Report( biv )[axisbox( 2 )] << {Add Ref Line( xpredicted, "Solid", "Black", "P", 1 ), Add Ref Line( xupper, "Solid", "Black", "U", 1 ),
Add Ref Line( xlower, "Solid", "Black", "L", 1 )};
Report( biv )[axisbox( 1 )] << {Add Ref Line( offset, "Solid", "Black", "", 1 )};
Report( biv )[framebox( 1 )] << Frame Size( 752, 513 );
Low sideLow side低側
High sideHigh side高端
回复:從二元圖中提取因子範圍您可以使用分析器中內置的優化器來執行此操作。設置響應限制以匹配目標,然後要查找上限和下限,只需使用重置因子網格來定義要搜索的值範圍(高於或低於最小值)。
Profiler(
Y( :Lower 95% Mean Studentized Residuals age ),
Profiler(
1,
Desirability Functions( 1 ),
Lower 95% Mean Studentized Residuals age <<
Response Limits(
{Lower( -0.04, 0.0183 ), Middle( 1.96, 1 ), Upper( 3.96, 0.0183 ),
Goal( "Match Target" ), Importance( 1 )}
),
Term Value( ratio( 0.8, Min( 0 ), Max( 0.8 ), Lock( 0 ), Show( 1 ) ) )
),
SendToReport(
Dispatch(
{"Prediction Profiler"},
"1",
ScaleBox,
{Min( 0 ), Max( 0.8 ), Inc( 0.2 ), Minor Ticks( 0 )}
)
)
) << Maximize Desirability;
Profiler(
Y( :Lower 95% Mean Studentized Residuals age ),
Profiler(
1,
Desirability Functions( 1 ),
Lower 95% Mean Studentized Residuals age <<
Response Limits(
{Lower( -0.04, 0.0183 ), Middle( 1.96, 1 ), Upper( 3.96, 0.0183 ),
Goal( "Match Target" ), Importance( 1 )}
),
Term Value( ratio( 1.52, Min( 0.8 ), Max( 2 ), Lock( 0 ), Show( 1 ) ) )
),
SendToReport(
Dispatch(
{"Prediction Profiler"},
"1",
ScaleBox,
{Min( 0.8 ), Max( 2 ), Inc( 0.2 ), Minor Ticks( 0 )}
)
)
) << Maximize Desirability;
您還應該能夠修改發送到最小化函數的表達式,只需減去 1.96 並最小化殘差即可獲得相同的結果。由於某種原因,即使在調整公差之後,我得到的值也略有不同(在探查器 v 1.03 中為 1.07,最小化)。
fa = Insert( Expr( Abs() ), parse( "abs( " || char( Name Expr( fs ) ) || " - 1.96 )" ) );
// find lower value
x = 0.2;
Minimize( fa, { x(0.2,0.8) } );
Show( x );
// find upper value
x = 1;
Minimize( fa, { x(0.8,1.5) } );
Show( x );
回复:從二元圖中提取因子範圍是的,這確實適用於找到局部最小值,但仍然很難從那裡到達下一個 1.96 的交叉點。 您仍然需要沿著曲線向上走,直到值超過 1.96。
為了暫時解決這個問題,我為其構建了一個函數,該函數只需要很少的步驟並在兩個方向上輸出,直到該值超過限制(或最大步驟數),但我預計 JMP 中有一個求解器函數可以實現更好的算法(就像非線性平台中內置的算法)。 我想現在我已經有了我需要的東西,但我總是願意尋求更好的方法來做到這一點。
回复:從二元圖中提取因子範圍是的,這個問題的問題在於,通常與目標值有多個交叉(一個在左側,一個在右側),並且使用意願最大化器,您會隨機獲得兩者之一。
我嘗試了擬合模型下的逆預測,但不支持二次項。
回复:從二元圖中提取因子範圍你的代碼有點亂。 我清理了它並完成了這個例子,儘管我可能仍然在追求錯誤的目標。
Names Default To Here( 1 );
// example data set
dt = Open( "$sample_data/Growth.jmp" );
// fit first-order polynomial model to response
biv = Bivariate(
Y( :age ),
X( :ratio ),
Fit Line
);
// save residuals for next step
biv << (Curve[1] << Save Studentized Residuals);
biv << Close Window();
// fit second-order polynomial model to residuals
biv = Bivariate(
Y( :Studentized Residuals age ),
X( :ratio ),
Fit Polynomial( 2, {Confid Shaded Fit( 1 ), Line Color( {212, 73, 88} )} )
);
// save formulas for lower / upper 95% confidence bound
biv << (Curve[1] << Mean Confidence Limit Formula);
// get upper formula
f = Column( dt, N Cols( dt ) ) << Get Formula;
// replace predictor name with x
fs = Substitute( Name Expr( f ), Expr( :ratio ), Expr( x ) );
// initialize x, could get x that predicts mean residual = 0
x = 0.5;
// minimize expression that is Abs( residual ), or mean = 0
fa = Insert( Expr( Abs() ), Name Expr( fs ) );
Minimize( fa, { x } );
Show( x );回复:從二元圖中提取因子範圍我想知道另一種方法。 如果您將預測刻畫器和匹配目標意願函數與目標響應結合使用會怎樣? 然後您可以選擇預測平均值和平均值的 95% 置信區間估計值。
我可能已經偏離了你最初的目標……
回复:從二元圖中提取因子範圍@馬克貝利謝謝,我嘗試了一下,但我不清楚語法。
這是我所得到的,但現在我需要弄清楚如何為其提供正確的優化約束:
Names Default To Here( 1 );
dt = Open( "$sample_data/Growth.jmp" );
biv = Bivariate(
Y( :age ),
X( :ratio ),
Fit Line( {Line Color( {204, 121, 41} )}, save studentized residuals ),
SendToReport(
Dispatch(
{},
"Bivar Plot",
FrameBox,
{Grid Line Order( 3 ), Reference Line Order( 4 )}
)
)
);
biv << (Curve[1] << Save Studentized Residuals);
biv << close window();
biv2 = Bivariate(
Y( :Studentized Residuals age ),
X( :ratio ),
Fit Polynomial( 2, {Confid Shaded Fit( 1 ), Line Color( {212, 73, 88} )} ),
SendToReport(
Dispatch(
{},
"ratio",
ScaleBox,
{Min( 0.2796875 ), Max( 1.2666259765625 ), Inc( 0.2 ), Minor Ticks( 1 )}
),
Dispatch(
{},
"Studentized Residuals age",
ScaleBox,
{Add Ref Line( 1.96, "Solid", "Black", "", 1 ),
Add Ref Line( -1.96, "Solid", "Black", "", 1 )}
)
)
);
biv << (Curve[1] << Mean Confidence Limit Formula);
f =column(dt, n cols(dt)) << Get Formula;
fs = substitute(name expr(f), expr(:ratio), expr(x1));
/*A = [1 5];
b = [-1.96, 1.96];
minFun = Constrained Maximize(
f,
{x1( 0, 5 )},
<<LESSTHANEQ></LESSTHANEQ>
minimize(name expr(f), {})最後一部分不起作用。 感謝您的幫助!
回复:從二元圖中提取因子範圍您也許可以使用 Minimize() 函數和置信邊界表達式。 請參閱幫助優化方法。
回复:從圖表中提取範圍我不知道直接的方法,但這裡有一些想法。有些需要編寫腳本,而且我懷疑對於小問題來說,沒有一個會更快。
- 通過從雙變量報告中的表中提取參數和標準誤差,然後使用適當的公式創建列,將每行的公式保存到數據表中。然後使用分析器中內置的優化器來解決每個問題。
- 使用蠻力法保存相對較少的點,然後使用擬合模型對它們擬合一條新曲線,並且然後保存預測公式並使用優化器求解。
- 使用擬合模型進行擬合,您應該能夠直接提取預測公式,但可能不能提取 CI。
- 使用強力方法並在最近的幾個點之間進行插值,或者在最後兩個點之間進行線性插值,或者對於該問題在最近的三個點之間進行二次插值。