[JSL] 對大量指標進行雙邊 T 檢定的腳本大家好,
我想編寫一個 JSL 腳本來自動對大量指標(500+)進行 TOST(雙向 T 測試)。
TOST 透過一對「等級」工作,因此使用 2x 等級很容易,因為每個「對」只需要 1x 行。
我已經編寫了一個適用於 2x 層級的腳本,透過產生「組合資料表」並向其中添加更多帶有公式的列,最終得到結果:「等效」或「不等效」。
當我想要處理超過 2 個級別時,問題會變得更加嚴重,它需要找到所有可能的唯一“級別”對,然後對度量 + 級別對的每個組合運行 TOST 數學。
我找到了一種方法(在此論壇上)從列表中查找所有可能的唯一對,並將它們放入表或嵌套列表中(NchooseKmatrix())。
但我被困在那裡。我需要的是:
1- 使用所有可能的指標組合(Column1)和所有可能的等級對(Column2 和 Column3)填入新表。
2-然後在每行中添加每對級別的統計數據
從現在開始,我將能夠計算出最終確定 TOST 的數學公式。
我附加了一個腳本,該腳本生成一個虛擬表,然後是來自單向分析的組合數據表,然後是我嘗試使用指標+唯一級別對的所有組合創建第三個表的失敗嘗試
預先感謝您的幫助
Names Default To Here( 1 );
clear symbols();
Deletesymbols();
//Create table with random distribution (table 1)
dt = New Table( "tabletest",
Add Rows( 500 ),
New Column( "Product", Character, "Nominal", formula("Product " ||char( Random Integer( 1, 4 )))),
New Column( "Metric1", Numeric, "Continuous", formula( Random Normal( 10, 1 ) ) ),
New Column( "Metric2", Numeric, "Continuous", formula( Random Gamma( 10, 1 ) ) ),
New Column( "Metric3", Numeric, "Continuous", formula( Random Gamma( 10, 2 ) ) )
);
Column( dt, "Metric1" ) << set property( "spec limits", {LSL( 5 ), USL( 25 ), Show Limits( 0 )} );
Column( dt, "Metric2" ) << set property( "spec limits", {LSL( 0 ), USL( 40 ), Show Limits( 0 )} );
Column( dt, "Metric3" ) << set property( "spec limits", {LSL( 5 ), USL( 40 ), Show Limits( 0 )} );
dt << save( "$Desktop\tabletest.jmp" );
//Get a list from all unique Product
SplitBy = "Product";
summarize(ColumnSplitBy=by(Column (SplitBy)));
show(ColumnSplitBy);
For( i = N Items( ColumnSplitBy ), i > 0, i--,
If( ColumnSplitBy[i] == "",
Remove From( ColumnSplitBy, i, 1 );
)
);
//Get Column name
MetricCols = dt << Get Column Names( numeric, continuous, "string" );
//Get all unique combo of 2 Products
ColumnSplitByCombo = aslist( nchoosekMatrix(nitems(ColumnSplitBy), 2));
show (ColumnSplitByCombo);
//Create a combinaed datatable with stats (Table 2)
ow = dt << Oneway(
Y(Eval(MetricCols)),
X(Eval(SplitBy)),
Means and Std Dev(1),
SendToReport(
Dispatch(
{"Means and Std Deviations"},
"Std Dev Lower 95%",
NumberColBox,
{Visibility("Visible")}
),
Dispatch(
{"Means and Std Deviations"},
"Std Dev Upper 95%",
NumberColBox,
{Visibility("Visible")}
)
),
Invisible
);
tb = Report(ow[1])[Outline Box("Means and Std Deviations"), Table Box(1)];
dt2 = tb << Make Combined Data Table;
tb << close window;
//Create new table for the result, each row has a unique pair of Levels
dt3 = astable( nchoosekMatrix(nitems(ColumnSplitBy), 2), << column names({"x", "y"}) );
dt3 << new column ("first", character, << set values ( ColumnSplitBy[dt3:x << get values]));
dt3 << new column ("second", character, << set values ( ColumnSplitBy[dt3:y << get values]));
dt3 << delete columns (1::2);
//Create a nested list with each pair of levels
Listdt3 = aslist( nchoosekMatrix(nitems(ColumnSplitBy), 2));
show (Listdt3);
// I tried to use associate array() to match the level and name but couldn't make it work- 傳教士
自動化和腳本編寫回覆:[JSL] 對大量指標進行雙邊 T 測試的腳本我附上了一份帶有螢幕截圖的文件“Untitled.png”,以(希望)更好地解釋我的請求。
謝謝!
回覆:[JSL] 對大量指標進行雙邊 T 測試的腳本例如,您可以先堆疊組列,用結果更新它,然後再次拆分它。
這個例子沒有考慮到可以有多個Metrics
// Loop over Metrics and perform these for each of them
// Concatenate results into single table
dt3 = As Table(NChooseK Matrix(N Items(ColumnSplitBy), 2), <<COLUMN names=""></COLUMN>// Metrics should be taken into account here OR stacked table should contain them
dt4 << Update(
With(dt2),
Match Columns(:Data = :Level)
);
或者沒有最終的分割,很可能看起來像這樣

回覆:[JSL] 對大量指標進行雙邊 T 測試的腳本@Voizingu您好:TOST 只是檢查 100(1-2alpha)% 置信區間是否完全包含在某些等價限制內;那麼,也許一個適當的解決方法是使用 Fit Y by X 多重比較過程來為您進行所有組合?
回覆:[JSL] 對大量指標進行雙邊 T 測試的腳本是否有原因無法使用 Oneway 平台中的內建等價測試?
回覆:[JSL] 對大量指標進行雙邊 T 測試的腳本你好,賈莫,
堆疊>更新>拆分是個好主意!
我已經能夠成功實現它,但我的程式碼有點髒(很多 For() 循環、中間步驟...)。
而不是:
- 多次連接表
- 然後從重複指標清單中填入一列
我想在優化我的程式碼方面變得更好。
有沒有辦法以更乾淨/優化的方式填充 dt5? (也許使用本機 JMP 指令?)
我很想聽聽你對此的建議
但無論如何,非常感謝您在這方面幫助我:D
- 傳教士
Names Default To Here( 1 );
clear symbols();
Deletesymbols();
//Create table with random distribution (table 1)
dt = New Table( "tabletest",
Add Rows( 5000 ),
New Column( "Product", Character, "Nominal", formula("Product " ||char( Random Integer( 1, 4 )))),
New Column( "Metric1", Numeric, "Continuous", formula( Random Normal( 10, 1 ) ) ),
New Column( "Metric2", Numeric, "Continuous", formula( Random Gamma( 10, 1 ) ) ),
New Column( "Metric3", Numeric, "Continuous", formula( Random Gamma( 10, 2 ) ) ),
);
Column( dt, "Metric1" ) << set property( "spec limits", {LSL( 5 ), USL( 25 ), Show Limits( 0 )} );
Column( dt, "Metric2" ) << set property( "spec limits", {LSL( 0 ), USL( 40 ), Show Limits( 0 )} );
Column( dt, "Metric3" ) << set property( "spec limits", {LSL( 5 ), USL( 40 ), Show Limits( 0 )} );
dt << save( "$Desktop\tabletest.jmp" );
//Get a list from all unique Product
SplitBy = "Product";
summarize(ColumnSplitBy=by(Column (SplitBy)));
show(ColumnSplitBy);
For( i = N Items( ColumnSplitBy ), i > 0, i--,
If( ColumnSplitBy[i] == "",
Remove From( ColumnSplitBy, i, 1 );
)
);
//Get Column name
MetricCols = dt << Get Column Names( numeric, continuous, "string" );
show(MetricCols);
//Get all unique combo of 2 Products
ColumnSplitByCombo = aslist( nchoosekMatrix(nitems(ColumnSplitBy), 2));
show (ColumnSplitByCombo);
//Create a combinaed datatable with stats (Table 2)
ow = dt << Oneway(
Y(Eval(MetricCols)),
X(Eval(SplitBy)),
Means and Std Dev(1),
SendToReport(
Dispatch(
{"Means and Std Deviations"},
"Std Dev Lower 95%",
NumberColBox,
{Visibility("Visible")}
),
Dispatch(
{"Means and Std Deviations"},
"Std Dev Upper 95%",
NumberColBox,
{Visibility("Visible")}
)
),
Invisible
);
tb = Report(ow[1])[Outline Box("Means and Std Deviations"), Table Box(1)];
dt2 = tb << Make Combined Data Table;
tb << close window;
//Create new table for the result, each row has a unique pair of Levels
dt3 = astable( nchoosekMatrix(nitems(ColumnSplitBy), 2), << column names({"x", "y"}) );
dt3 << new column ("first", character, << set values ( ColumnSplitBy[dt3:x << get values]));
dt3 << new column ("second", character, << set values ( ColumnSplitBy[dt3:y << get values]));
dt3 << delete columns (1::2);
//Create a nested list with each pair of levels
Listdt3 = aslist( nchoosekMatrix(nitems(ColumnSplitBy), 2));
show (Listdt3);
// I tried to use associate array() to match the level and name but couldn't make it work
// Loop over Metrics and perform these for each of them
// Concatenate results into single table
dt3 = As Table(NChooseK Matrix(N Items(ColumnSplitBy), 2), <<COLUMN names=""></COLUMN>回覆:[JSL] 對大量指標進行雙邊 T 測試的腳本你好,MRB3855,
你說得很好,我不想在第一條訊息中放入太多資訊來關注我的腳本問題,但在我的初始程式碼(適用於 2 個層級)中,我將等價限制設為 5%範圍[LSL;USL]。
這當然是一個任意值,如有必要我可以更改。
它允許我篩選數百個指標,並從該標準中標記「不等效」指標,通常有十幾個。
然後從這個清單中我可以進行徹底的分析:
- 變異數分析
- TOST 具有適當的範圍
- ETC...
對於第二點,如果我理解得很好,您建議為每個指標運行 TOST 平台並選擇資料並透過 Display Box() 放入表格中?如果是這樣,這確實是一個可能的解決方案,但我更喜歡自己運行數學來理解 TOST 原理並節省一些處理時間。
希望這是有道理的:)
感謝您的協助
- 傳教士
回覆:[JSL] 對大量指標進行雙邊 T 測試的腳本你好馬克,
是的,一開始我想到使用 TOST 平台並使用 Display Box() 選擇統計數據,但我更喜歡使用不同的方法來單獨計算每個參數,以獲得與平台給出的相同結果。
事實上,這可能是比重新發明輪子更快的方法,但我現在已經投入了很多時間,而且我已經非常接近實現它,所以我不妨完成我開始的事情(艱難的方式),哈哈!
這樣做的一個好處是我現在了解了 TOST 方法的每一步。
謝謝
- 傳教士
回覆:[JSL] 對大量指標進行雙邊 T 測試的腳本我很可能會自己使用循環,但您可以通過一些矩陣運算來完成。在我看來,該腳本需要重寫以使其更易於閱讀(更好地命名變數、利用輸出表名稱、關閉不必要的表和常規清理)
看更多...
Names Default To Here(1);
//Create table with random distribution (table 1)
dt = New Table("tabletest",
Add Rows(5000),
New Column("Product",
Character,
"Nominal",
formula("Product " || Char(Random Integer(1, 4)))
),
New Column("Metric1", Numeric, "Continuous", formula(Random Normal(10, 1))),
New Column("Metric2", Numeric, "Continuous", formula(Random Gamma(10, 1))),
New Column("Metric3", Numeric, "Continuous", formula(Random Gamma(10, 2))),
);
Column(dt, "Metric1") << set property("spec limits", {LSL(5), USL(25), Show Limits(0)});
Column(dt, "Metric2") << set property("spec limits", {LSL(0), USL(40), Show Limits(0)});
Column(dt, "Metric3") << set property("spec limits", {LSL(5), USL(40), Show Limits(0)});
SplitBy = "Product";
Summarize(ColumnSplitBy = by(Column(SplitBy)));
MetricCols = dt << Get Column Names(numeric, continuous, "string");
ColumnSplitByCombo = As List(NChooseK Matrix(N Items(ColumnSplitBy), 2));
//Create a combinaed datatable with stats (Table 2)
ow = dt << Oneway(
Y(Eval(MetricCols)),
X(Eval(SplitBy)),
Means and Std Dev(1),
SendToReport(
Dispatch({"Means and Std Deviations"}, "Std Dev Lower 95%", NumberColBox,
{Visibility("Visible")}
),
Dispatch({"Means and Std Deviations"}, "Std Dev Upper 95%", NumberColBox,
{Visibility("Visible")}
)
),
Invisible
);
tb = Report(ow[1])[Outline Box("Means and Std Deviations"), Table Box(1)];
dt2 = tb << Make Combined Data Table;
tb << close window;
//Create a nested list with each pair of levels
Listdt3 = As List(NChooseK Matrix(N Items(ColumnSplitBy), 2));
mcols = N Items(MetricCols);
l = Repeat(Listdt3, mcols);
m = J(N Items(l) / mcols, mcols) :*</img> (1::mcols);
mfinal = Sort Ascending(Shape(m, 1, N Items(l)));
dt3 = As Table(Matrix(l), <<COLUMN names=""></COLUMN>
</CODE><NOSCRIPT><CODE class=" language-jsl"><DIV class="lia-spoiler-noscript-container"><DIV class="lia-spoiler-noscript-content">名稱預設為此處(1); //建立隨機分佈表(表1) dt = New Table("tabletest", Add Rows(5000), New Column("Product", Character, "Nominal", Formula("Product " || Char(Random Integer) (1, 4))) ),新列("Metric1",數值,"連續",公式(隨機常態(10, 1)))),新列("Metric2",數值,"連續",公式(隨機Gamma(10, 1))), 新列("Metric3", Numeric, "連續", 公式(隨機 Gamma(10, 2))), ); Column(dt, "Metric1") << set property("規格限制", {LSL(5), USL(25), 顯示限制(0)}); Column(dt, "Metric2") << set property("規格限制", {LSL(0), USL(40), 顯示限制(0)}); Column(dt, "Metric3") << set property("規格限制", {LSL(5), USL(40), 顯示限制(0)});分割依據=「產品」; Summarize(ColumnSplitBy = by(Column(SplitBy))); MetricCols = dt << 取得列名稱(數字、連續、「字串」); ColumnSplitByCombo = As List(NChooseK Matrix(N Items(ColumnSplitBy), 2)); //建立包含統計資料的組合資料表(表2) ow = dt << Oneway( Y(Eval(MetricCols)), X(Eval(SplitBy)), Means and Std Dev(1), SendToReport( Dispatch({ "Means)與標準差"}, "標準差下限95%", NumberColBox, {Visibility("Visible")} ), Dispatch({"平均值與標準差"}, "標準差上限95%", NumberColBox, {Visibility( "可見")} ) ), 不可見 ); tb = Report(ow[1])[大綱框(“平均值與標準差”),表格框(1)]; dt2 = tb << 製作組合資料表; tb << 關閉視窗; //建立一個包含每對層級的巢狀清單 Listdt3 = As List(NChooseK Matrix(N Items(ColumnSplitBy), 2)); mcols = N 項(MetricCols); l = 重複(Listdt3, mcols); m = J(N 項(l) / mcols, mcols) (1::mcols); mfinal = 升序排序(形狀(m, 1, N 項(l))); dt3 = 作為表(矩陣(l), < <COLUMN names=""></COLUMN></DIV></DIV>
<P><SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1724774273332.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_1-1724774273332.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_1-1724774273332.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_1-1724774273332.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_1-1724774273332.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_1-1724774273332.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_1-1724774273332.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_1-1724774273332.png" style="width: 400px;"><span class="lia-inline-image-display-wrapper" image-alt="jthi_1-1724774273332.png" style="width: 400px;"><img src="https://us.v-cdn.net/6038925/uploads/images/67576i7A33F8F17FEAD03D/jthi_1-1724774273332.png" role="button" title="jthi_1-1724774273332.png" alt="jthi_1-1724774273332.png" /></span></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></P>
<P><SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_2-1724774284315.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_2-1724774284315.png" style="width: 304px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_2-1724774284315.png" style="width: 304px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_2-1724774284315.png" style="width: 304px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_2-1724774284315.png" style="width: 304px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_2-1724774284315.png" style="width: 304px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_2-1724774284315.png" style="width: 304px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_2-1724774284315.png" style="width: 304px;"><span class="lia-inline-image-display-wrapper" image-alt="jthi_2-1724774284315.png" style="width: 304px;"><img src="https://us.v-cdn.net/6038925/uploads/images/67577i906F6E675ADD899F/jthi_2-1724774284315.png" role="button" title="jthi_2-1724774284315.png" alt="jthi_2-1724774284315.png" /></span></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></P>
<P><SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1724774190734.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_0-1724774190734.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_0-1724774190734.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_0-1724774190734.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_0-1724774190734.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_0-1724774190734.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_0-1724774190734.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_0-1724774190734.png" style="width: 400px;"><span class="lia-inline-image-display-wrapper" image-alt="jthi_0-1724774190734.png" style="width: 400px;"><img src="https://us.v-cdn.net/6038925/uploads/images/67575i9361F045B1E7C693/jthi_0-1724774190734.png" role="button" title="jthi_0-1724774190734.png" alt="jthi_0-1724774190734.png" /></span></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></P>
<P> </P> 回覆:[JSL] 對大量指標進行雙邊 T 測試的腳本嘿,賈莫,
感謝您的快速回覆。
這條線失敗了
m = J(N Items(l) / mcols, mcols) (1::mcols);
您能解釋一下它的用途嗎?
我通常不使用矩陣,我嘗試自己調試但無法...
感謝您的協助
回覆:[JSL] 對大量指標進行雙邊 T 測試的腳本由於某種原因它丟失了:*
m = J(N Items(l) / mcols, mcols) :*</img> (1 :: mcols);
目的是創建一個像這樣的矩陣

然後您將其轉換為

使用形狀。
也要使用循環,它們通常比奇怪的矩陣「技巧」更容易閱讀和理解。
回覆:[JSL] 對大量指標進行雙邊 T 測試的腳本嗨,賈莫,
我測試了該行的幾個版本,添加了翻譯中可能丟失的特殊字符,但沒有...
這條線對我來說不起作用(我使用的是 JMP Pro 17)

沒關係,使用 Matrix 的這種優化真的很好。正如你所說,使用循環也可以,所以我會這樣做:)
再次感謝您花時間幫助我(再次)!

- 傳教士
回覆:[JSL] 對大量指標進行雙邊 T 測試的腳本我已附上社區中中斷的程式碼部分作為螢幕截圖

它是矩陣的逐元素乘法E Mult()
@Ryan_Gilmore JMP 社群正在吃飯:*(: * 此處新增了空格)
JSL程式碼區塊:
m = J(N Items(l) / mcols, mcols) :*</img> (1::mcols);
文字:
m = J(N 項(l) / mcols, mcols):* (1::mcols);
編輯時的截圖

預覽截圖

回覆:[JSL] 對大量指標進行雙邊 T 測試的腳本嗨@Voizingu大家都說,看來您有一個適合您的解決方案。出色的!但是,為了避免遺失,信賴區間應為 100(1-2alpha)% 區間。即,如果您希望 1 類錯誤率為 5%,那麼用於判斷等效性的區間應該是 90% 信賴區間(而不是 95%)。這是一項兩側測試…每一側都在 alpha = 0.05 下進行測試。見附件,