為分類變數的所有層級編寫相同的輸出腳本你好,
我有一個腳本,它可以執行一些計算、運行一些平台並提取特定輸出,然後在新的視窗中建立選項卡框。我希望針對使用者在對話方塊中指定的某個分類變數的每個層級執行所有這些操作。
目前,我根據分組變數建立資料的各個子集,然後遍歷每個資料集:
dtSubset = dt << Subset( By( Eval( groupVar ) ), Linked, Selected Columns Only( 0 ), All Rows( 1 ), Invisible );
For( i = 1, i <= N Items( unique_groups ), i++,
dt_i = dtSubset[i];
...some code to do stuff
<BR />...append output as a new tab box in my window
);
Essentially all I am doing is coding up my own analysis and wanting a 'By' variable. I am wondering if there is a better or more efficient way to go about this? The main thing I want with the code is to have the output I create be specific for each level, while also still maintaining a connection to the original data table (meaning the plots in my output are interactive still).
如您所見,我將子集建立為不可見的,然後在我的程式碼中,在每次循環迭代結束時關閉它們。
謝謝,
羅伯特
自動化和腳本編寫回覆:為分類變數的所有層級編寫相同的輸出腳本平台內不使用 By 變數的原因是什麼?
回覆:為分類變數的所有層級編寫相同的輸出腳本這裡提供了三種使用分組列從資料表建立選項卡框的方法。如果您使用的是 JMP18 或更高版本(我認為),最後一種方法無疑是最簡單的。
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// Using subsets
dt_subsets = dt << Subset(
By(:age),
Linked,
Selected Columns Only(0),
All Rows(1),
Invisible
);
nw = New Window("Subsets",
tb = tab box()
);
dists = {};
For Each({dt_subset}, dt_subsets,
tb << Insert(Tab Page Box(Title(dt_subset << get name),
dt_subset << Distribution(
Continuous Distribution(Column(:weight)),
Nominal Distribution(Column(:age))
);
));
);
tb << Set Selected(1);
// Using Where in platform
nw = New Window("Where",
tb = tab box()
);
groups = Associative Array(Column(dt, "age")) << get keys;
dists = {};
For Each({group}, groups,
tb << Insert(Tab Page Box(Title("age=" || Char(group)),
dist = dt << Distribution(
Continuous Distribution(Column(:weight)),
Nominal Distribution(Column(:age)),
Where(:age == group)
);
));
(Report(dist) << Top Parent)[TextBox(1)] << Visibility("Collapse"); // to hide Where(... textbox
);
tb << Set Selected(1);
// Using By in platform
dist = dt << Distribution(
Group Options(Layout("Arrange in Tabs")),
Continuous Distribution(Column(:weight)),
Nominal Distribution(Column(:age)),
By(:age)
);
回覆:為分類變數的所有層級編寫相同的輸出腳本在 Jarmo 的「按群組」範例的基礎上,這裡提供一個建立輸出中所示的選項卡視窗的範例。
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// Using By in platform
dist = dt << Distribution(Invisible,
Group Options(Layout("Arrange in Tabs")),
Continuous Distribution(Column(:weight)),
Nominal Distribution(Column(:age)),
By(:age)
);
// Create a new window and add tabs for each age
nw = New Window( "Tabs",
tabb = Tab Box();
);
For( i = 1, i <= N Items( dist ), i++,
display = Report( dist[i] );
theByGroup = display[Outline Box( 1 )] << get title;
tabb << append( Tab Page Box( Title( theByGroup ), display ) );
);

回覆:為分類變數的所有層級編寫相同的輸出腳本主要原因是,我發現遍歷變數的不同層級並逐一建立標籤頁窗口,然後再進行追加操作,這樣更簡單。因為對於每個層級,我都需要進行表格計算、使用圖形生成器建立圖形、從 Dist 平台提取 QQ 圖、從擬合模型平台提取學生化殘差圖等等。
回覆:為分類變數的所有層級編寫相同的輸出腳本感謝二位的建議,提供的程式碼運作良好。我需要補充一點,我正在開發一個相當複雜的插件,它會從許多不同的平台提取數據,並產生一些新的輸出。我真正想要的是確保通常與數據表關聯的圖表保持這種關聯。我還希望每個標籤頁看起來都完全一樣,所以循環似乎是個簡單的解決方案。
您認為最好的方法是在所有我使用的平台上都使用“按”選項,然後遍歷我的變數的各個級別,使用不同的路徑呼叫每個元件,並將它們附加到我想要的位置嗎?
回覆:為分類變數的所有層級編寫相同的輸出腳本如果像 Jim 演示的那樣將它們附加在一起,最終會失去互動性。子集/Where 子句都很好用,但在某些情況下,你無法輕鬆地使用 Where 子句,例如建立匯總表(它使用本機資料篩選器而不是簡單的 Where 子句)。而且,使用子集可能會導致產生大量資料表,因為它們可能不會像你預期的那樣關閉(在關閉主表時)。有時,使用本機資料篩選器也值得考慮,因為你可以使用資料篩選上下文框在多個平台上使用同一個篩選器。