腳本自動化:檢索預測變數並設定 sigma 水平你好,
我接到一個項目,需要寫一個建模流程。所有預測變數和響應都是連續數值型的,並且響應分別進行擬合。在進行了一些初始資料準備之後…
- 逐步 K 折驗證<--自動化
- 步驟 1 的模型在 SLS 中運作<--自動化
- SLS 預測分析器:
- 初始化模擬器<--自動化
- 將所有因素類型變更為隨機<--非自動化
- 將每列的所有 SD 變更為 3 sigma 值 <-- 非自動化
此流程將使用 for 迴圈。在每次迭代中,它將對單一響應變數進行一系列分析。 3.2 的腳本很容易取得,但將標準差值改為 3 西格瑪值卻不容易。使用 for 迴圈時,如何自動修改 3.2 的標準差值?有沒有更好的方法?我查看了“首選項”>“平台”>“擬合模型”>“FIR 最小二乘法”,但沒有找到將標準差值從 1 標準差更改為 3 標準差的選項。
最新更新至 JMP 17,如果有幫助的話。
數據探索與視覺化回复:腳本自動化:檢索預測變量和設置西格瑪水平是這樣的嗎?
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Tiretread.jmp");
obj = Profiler(
Y(
:Pred Formula ABRASION, :Pred Formula MODULUS, :Pred Formula ELONG,
:Pred Formula HARDNESS
)
);
val = 3;
obj << Simulator(
1,
Factors(
SILICA << Random(Normal(1.25, 0.3266)), SILANE << Random(Normal weighted(50, 6.532)),
SULFUR << Fixed(2.25)
),
Responses(
Pred Formula ABRASION << Add Random Noise(1), Pred Formula MODULUS << Add Random Noise(2),
Pred Formula ELONG << Add Random Noise(val), Pred Formula HARDNESS << Add Random Noise(val*2)
)
);
根據腳本索引中的示例修改

回复:腳本自動化:檢索預測變量和設置西格瑪水平你好@jthi ,
不完全的。 下面是我所擁有的代碼片段,稍後我會解釋更多。
// Iterating through responses - JMP 17
mymodel_sw = Fit Model( Y( response[i] ),
Effects( Factorial to degree( eval( predict ) ), Response Surface( eval( predict ) ) ),
Personality("Stepwise"),
Run( "K-Fold Crossvalidation"n(5) )
);
// Runs modeling
mymodel_sw << Go;
// Finishes predictor selection before proceeding
mymodel_sw << Finish;
// Makes model
mymodel_sls = mymodel_sw << Make Model;
// Runs SLS model
mymodel_sls << Run;
// Finishes modeling before proceeding
mymodel_sls << Finish;
// Gets list of predictors
param_SLS = mymodel_sls << Get Parameter Names;一旦我 << 獲取參數名稱,param_SLS 錯誤與已刪除的對象引用。但是,我需要這個參數列表來構建 << Simulate to table 中的參數,我將通過創建一個自定義函數來處理這個問題。
這段代碼位於一個 for 循環中,循環遍歷響應列表,一次一個。這有意義嗎?
回复:腳本自動化:檢索預測變量和設置西格瑪水平或者有沒有一種方法可以從探查器工具中檢索參數名稱,這樣我就不會得到所有的交互項並且必須對所有這些進行排序? 我想要一個我可以使用的參數名稱的唯一列表。 我必須假設適合的參數數量因模型而異。
回复:腳本自動化:檢索預測變量和設置西格瑪水平這是一個更深入的示例腳本。請注意,這不起作用!
Names default to here(1);
dt = open( "$SAMPLE_DATA/Body Fat.jmp" );
/////////////////////////// Custom function - Help!
mysim = function( {list, iteration, stddev, step},
// New list placeholder
unique_factors = {};
// Adds only unique factors to new list, uses "*" as identifier
for( i = 1, i <= N items( list ), i++,
if( list[i] << !contains( "*" ) , insert into( unique_factors, list[i] )
)
);
num_sim_factors = N Items( unique_factors );
// Modifies each factor in the simulator to normal distribution with 3 standard deviations
simfactor = {};
for( i = 1, i <= num_sim_factors, i++,
temp_1 = char( unique_factors[i] ) || " << Random( Normal( " || char( col mean( unique_factors[i] ) ) ||
", " || char( stddev * col std dev( unique_factors[i] ) ) || ") ),"
insert into( sim_factor, temp_1 )
);
// Inputs simfactor into simulator
mymodel_sls << Simulator( 1, eval( simfactor ) );
// Creates the arguments for Simulate to table
simtable_pt1 = "N Runs( " || char( iteration ) || "),"
simtable_pt2 = {};
// Creates an argument for each factor
for( i = 1, i <= num_sim_factors, i++,
temp_2 = char( unique_factor[i] ) || " << Sequence Location( " || char ( Col Minimum( unique_factor[i] ) ) || ", "
chart ( Col Maximum( unique_factor[i] ) ) || ", " || char( step ) || " ),";
insert into( simtable_pt2, temp_2 )
);
// Combines strings into a single argument for use for Simulate to Table
simarg = simtable_pt1 || simtable_pt2;
// Simuates data to table for further analysis
mymodel_sls << Get simulator;
mymodel_sls << Simulate to table( simarg );
);
/////////////////////////// Cols to use - user adjustable
predict = {:"Neck circumference (cm)"n, :"Chest circumference (cm)"n,
:"Abdomen circumference (cm)"n, :"Hip circumference (cm)"n,
:"Thigh circumference (cm)"n, :"Knee circumference (cm)"n,
:"Ankle circumference (cm)"n, :"Biceps (extended) circumference (cm)"n,
:"Forearm circumference (cm)"n, :"Wrist circumference (cm)"n};
response = {:"Age (years)"n, :"Weight (lbs)"n, :"Height (inches)"n};
/////////////////////////// User input
num_response = N Items( response );
num_predict = N Items( predict );
// How many simulations to run?
sim_no = 1000;
// How many standard deviations for each predictor in the simulation?
stddev = 3;
// Steps in simulation
steps = 4;
/////////////////////////// Changing col attribute
// In a later step, Simulate, the mean should be 0 due to this
for( i = 1, i <= num_response, i++,
response[i] << Set Property( "Coding", { col minimum( response[i] ), col maximum( response[i] ) } );
);
/////////////////////////// Modeling
/* Fit Model - Stepwise, w/ K-fold validation --> SLS --> Simulate */
for( i = 1, i <= num_response, i++,
// Names models for calling later
mymodel_sw = "FM_SW_" || char( i );
// Iterating through responses - JMP 17
mymodel_sw = Fit Model( Y( response[i] ),
Effects( Factorial to degree( eval( predict ) ), Response Surface( eval( predict ) ) ),
Personality("Stepwise"),
Run( "K-Fold Crossvalidation"n(5) )
);
// Runs modeling
mymodel_sw << Go;
// Finishes predictor selection before proceeding
mymodel_sw << Finish;
// Makes model
mymodel_sls = mymodel_sw << Make Model;
// Runs SLS model
mymodel_sls << Run;
// Finishes modeling before proceeding
mymodel_sls << Finish;
////////////////// NOT WORKING BELOW
// Gets list of predictors <--- This is first step
param_sls1 = mymodel_sls << Get Effect Names;
param_sls2 = mymodel_sls << Get Parameter Names;
show(param_sls1, param_sls2);
// Calls on custom function <--- This is second step
mysim( param_sls1, sim_no, stddev, steps );
// Names Simulate to table dataset by response variable in for loop
Current data table() << Set name( char( response[i] ) || "_report" );
);幫助! 這有多個部分不起作用!這是有效的 - 註釋掉自定義函數和下面的任何內容(靠近腳本底部),其中狀態不在下面。 我可以通過SLS建模的生成,但是一旦涉及到修改模擬參數和運行模擬,這兩者都是自定義的(請參閱自定義功能),我就束手無策了。
回复:腳本自動化:檢索預測變量和設置西格瑪水平該功能有很多錯別字,可能會導致問題。 我只是修復了一些東西,不知道它是否做了它應該做的
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Body Fat.jmp");
mysim = function({input_list, iteration, stddev, step},
unique_factors = Filter Each({item}, input_list, !Contains(item, "*"));
num_sim_factors = N Items(unique_factors);
simfactor = {};
simfactor = Transform Each({uniq_factor}, unique_factors,
Eval Insert("^uniq_factor^ << Random(Normal(^col mean(column(dt, uniq_factor))^, ^stddev * col std dev(column(dt, uniq_factor))^");
);
// Inputs simfactor into simulator
mymodel_sls << Simulator( 1, eval(simfactor));
// Creates the arguments for Simulate to table
simtable_pt1 = "N Runs( " || char(iteration) || "),";
simtable_pt2 = {};
// Creates an argument for each factor
simtable_pt2 = Transform Each({uniq_factor}, unique_factors,
Eval Insert("^uniq_factor^ << Sequence Location(^Col Minimum(column(dt, uniq_factor))^, ^Col Maximum(column(dt, uniq_factor))^, ^step^)");
);
// Combines strings into a single argument for use for Simulate to Table
simarg = simtable_pt1 || Concat Items(simtable_pt2, ",");
// Simuates data to table for further analysis
mymodel_sls << Get simulator;
mymodel_sls << Simulate to table(simarg);
);
predict = {:"Neck circumference (cm)"n, :"Chest circumference (cm)"n,
:"Abdomen circumference (cm)"n, :"Hip circumference (cm)"n,
:"Thigh circumference (cm)"n, :"Knee circumference (cm)"n,
:"Ankle circumference (cm)"n, :"Biceps (extended) circumference (cm)"n,
:"Forearm circumference (cm)"n, :"Wrist circumference (cm)"n};
response = {:"Age (years)"n, :"Weight (lbs)"n, :"Height (inches)"n};
num_response = N Items(response);
num_predict = N Items(predict);
sim_no = 1000;
stddev = 3;
steps = 4;
For(i = 1, i <= num_response, i++,
response[i] << Set Property("Coding", {Col Minimum(response[i]), Col Maximum(response[i])})
);
For(i = 1, i <= num_response, i++,
mymodel_sw = "FM_SW_" || Char(i);
mymodel_sw = Fit Model(
Y(response[i]),
Effects(Factorial to degree(Eval(predict)), Response Surface(Eval(predict))),
Personality("Stepwise"),
Run("K-Fold Crossvalidation"n(5))
);
mymodel_sw << Go;
mymodel_sw << Finish;
mymodel_sls = mymodel_sw << Make Model;
mymodel_sls = mymodel_sls << Run;
mymodel_sls << Finish;
param_sls1 = mymodel_sls << Get Effect Names;
param_sls2 = mymodel_sls << Get Parameter Names;
Show(param_sls1, param_sls2);
mysim(param_sls1, sim_no, stddev, steps);
dt << Set name(Char(response[i]) || "_report");
);回复:腳本自動化:檢索預測變量和設置西格瑪水平@jthi - 我將不得不深入研究一下你的建議。我見過 Filter Each、Transform Each 和 Eval Insert,但我沒有使用它們的經驗,也不知道它們是如何工作的。
另一個問題要問你。在 Eval Insert 中,你有胡蘿蔔 ^ 標記,這是我以前從未見過的。是否有一些文檔可以讓我更多地了解它們的功能?我認為從您的使用方式來看已經很清楚了,但是我很感興趣並且想確保我正確地解釋了您的用法。
simfactor = Transform Each({uniq_factor}, unique_factors,
Eval Insert("^uniq_factor^ << Random(Normal(^col mean(column(dt, uniq_factor))^, ^stddev * col std dev(column(dt, uniq_factor))^");
);回复:腳本自動化:檢索預測變量和設置西格瑪水平@jthi ,
你走在正確的軌道上! 其他表達式操作對於創建參數以插入到它們各自的函數中是必要的。在mysim自定義函數中,參數insert into修改模擬的分佈,生成參數insert into Simulate to Table已經有詳細說明。這是一個非常令人興奮的學習機會,讓我對這些類型的高級表達式大開眼界。
如果有人想了解更多關於表達式操作的信息,這裡有一個文檔鏈接: https://www.jmp.com/support/help/en/17.0/#page/jmp/advanced-expressions-macros-and-lists.shtml#
感謝那些提供幫助的人!
Names default to here(1);
dt = open( "$SAMPLE_DATA/Body Fat.jmp" );
mysim = function( {list, iteration, stddev, step},
// filter list of effects down to main effects. These are the effects whose name matches a column name
// take advantage of the speed of associative arrays to get the intersection set.
list << Intersect(Associative Array(dt<<GET column="" names=""> SLS --> Simulate */
for( k = 1, k <= num_response, k++,
// Names models for calling later
mymodel_sw = "FM_SW_" || char( k );
// Iterating through responses - JMP 17
mymodel_sw = Fit Model( Y( response[k] ),
Effects( Factorial to degree( eval( predict ) ), Response Surface( eval( predict ) ) ),
Personality("Stepwise"),
Run( "K-Fold Crossvalidation"n(5) )
);
// Runs modeling
mymodel_sw << Go;
// Finishes predictor selection before proceeding
mymodel_sw << Finish;
// Makes model
mymodel_sls = mymodel_sw << Make Model;
// Runs SLS model
mymodel_sls = mymodel_sls << Run; // this creates another object. assign your variable to that object
mymodel_sls << Profiler(1); // make sure profiler is on.
// Gets associative array of effect names.
// use this in the function to easily filter down to the main effect names
param_sls1 = Associative Array(mymodel_sls << Get Effect Names);
// Calls on custom function <--- This is second step
resultDT = mysim( param_sls1, sim_no, stddev, steps ); // assign variable to reference returned table
// Names Simulate to table dataset by response variable in for loop
resultDT << Set name( char( response[k] ) || "_report" );
);</GET>
SS