我第一次嘗試使用應用程式生成器開發 JMP 插件,但陷入了 JSL 腳本編寫的困境,如下所述:
一些背景:
該介面是在“對話框”選項卡下建立的。
共有三個面板框,標題分別為Columns、Roles 和Action,變數名稱分別為ColumnsPanel、RolesPanel 和ActionPanel。
在「列」面板下,我新增了一個 Col 列錶框(全部),其變數名稱為 ColList,它將拉入開啟的資料表中的所有欄位。
在「角色」面板下,我新增了三個列列錶框和三個按鈕框:
第一、第二和第三列列錶框的變數名稱分別是ResponseColList、FactorColList和BlockColList。
第一個、第二個和第三個按鈕框的變數名稱分別是 ResponseButton、FactorButton 和 BlockButton。
第一個、第二個和第三個按鈕框的標題分別是「回應」、「因子」和「區塊」。
在“操作”面板下,我新增了三個按鈕框,標題分別為“確定”、“刪除”和“取消”,變數名稱分別為“確定按鈕”、“刪除按鈕”和“取消按鈕”。
當我點擊「回應」按鈕時,它會從 ColList 新增屬性「A」、「B」、「C」、「D」和「E」列。
類似地,當我單擊“因素和區塊”按鈕時,它添加了 ColList 中的“網站”和“人員”列。

腳本:
//Part I
//Places selected columns into Role panel
On Response = Function({},
ResponseColList << Append( AllColList << Get Selected)
);
//Places selected columns into Factor panel
On Factor = Function({},
FactorColList << Append( AllColList << Get Selected)
);
//Places selected columns into Block panel
On Block = Function({},
BlockColList << Append( AllColList << Get Selected)
);
// Program the OK Button
On OK = Function({},
Response = ResponseColList << Get Items;
Factor = FactorColList << Get Items;
Block = BlockColList << Get Items;
// Get the current data table
dt = Current Data Table();
// Perform principal component analysis
pca = dt << Principal Components(
Y( Eval List( Response ) ),
Estimation Method( "NIPALS" ),
Standardize( "Standardized" )
);
pca << Save Principal Component Values( 3 );
pca << Close Window();
// Create a subset and delete columns "Prin1", "Prin2" and ""Prin3" in "dt"
dt << Subset(
Output Table("MET"),
All rows,
columns(Eval List(Block), Eval List(Factor), :Prin1, :Prin2, :Prin3)
);
dt << Delete Columns( "Prin1" ) << Delete Columns( "Prin2" ) << Delete Columns( "Prin3" );
// Standardize column attributes and create a data table "MET"
Current Data Table(Data Table("MET"));
For Each({col, index}, {:Prin1, :Prin2, :Prin3},
col << Format("Fixed Dec", 12, 2)
);
MET = Data Table( "MET" );
//Part II
//Get the levels in the Factor column
factorLevels = Associative Array(MET, Column(Eval List(Factor))) << Get Keys;
level1 = factorlevels[1];
level2 = factorlevels[2];
// Create two subsets named "Group1" and "Group2"
MET << Select Where( Column(Eval List(Factor)) == level1 ) << Subset( Output Table( "Group1" ), Selected Rows( 1 ), Selected columns only( 0 ) );
MET << Select Where( Column(Eval List(Factor)) == level2 ) << Subset( Output Table( "Group2" ), Selected Rows( 1 ), Selected columns only( 0 ) );
Group1 = Data Table( "Group1" );
Group2 = Data Table( "Group2" );
// Access the Site levels in "Group1" and "Group2"
Site_level1 = Column( Group1, "Site" ) << Get Values;
Site_level2 = Column( Group2 "Site" ) << Get Values;
);我可以成功運行第一部分腳本,但在第二部分中不斷出現錯誤,因此非常感謝一些偵錯程式碼的幫助。
這裡的另一個目標是處理具有不同屬性名稱(例如屬性“F”、“G”等)的資料集,我想確保腳本動態使用選定的列名稱而不是硬編碼特定名稱。
謝謝你!
關聯數組 - 以資料表作為第一個參數?
Names Default to Here(1);
MET = Open( "$SAMPLE_DATA/Big Class.jmp" );
Factor={"height", "weight"};
Associative Array(MET, Column(Eval List(Factor)))