我有一個資料集,其中包含許多連續的資料列和我在儀表板中過濾的兩個分類因素,以及一個用於分割所有繪圖/分析的附加分類變數(組)。 我還有一個主列切換器,這意味著使用者可以循環瀏覽每個連續變數的總計表。 主列切換器連結到儀表板內繪圖和分析上的所有其他列切換器。 因此,任何繪圖和分析一次都會顯示一個連續變量,並且可以按性別(男性/女性或兩者)進行過濾。
這一切都運作良好,但是當我建立一個新表(dtSumm)時,問題出現了,該表使用每個連續變數的總計統計表併計算一個新變數(相對變化)。 這個新的匯總表僅具有與組類別一樣多的行,並且沒有性別,因此我們現在失去了按此進行過濾的能力。
dtSumm的程式碼如下:
// Create a separate datatable for treatment group means
dtSumm = dt << Summary (
Group (:Group,:Sex ),
Mean ( eval ( cols ) ),
statistics column name format( "column" ),
Link to original data table( 1 ),
invisible
);
// Add RC columns for each column in cols to dtSumm
//This works by getting the mean of each column for treatment group "A"
For( i = 1, i <= num, i++,
mean0 = Mean(Column(cols[i])[(dtSumm << get rows where( :"Group" == "A"))]);
dtSumm << New Column(
Char(cols[i]||"_RC"),
Formula( ( ( ( column( cols[i] )[]) - ( eval(mean0) ) ) / ( eval(mean0) ) ) * 100 )
);
);
歡迎任何建議。 謝謝
現在可能有更好的方法,但過去我使用過「makeFilterChangeHandler()」。 所以,概括地說:
NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// Report involving detail-level data
NewWindow("Detail and Summary Data with Local Data Filter", << onClose(Try(Close(dt2, noSave))),
hlb = HListBox(dist = dt << Distribution(Continuous Distribution( Column( :height ) )));
);
// Local data filter
ldf = dist << Local Data Filter( Add Filter( columns( :sex ) ) );
// This script will run each time the filter selection is changed
ldfChange =
Function( {a},
filteredRows = ldf << getFilteredRows;
// Try to close any open ancilary tables
Try(Close(dt2, noSave));
// Make a subset table according to the current selection
dt2 = dt << subset(Rows(filteredRows), Invisible);
// Aggregate the subset table
dt3 = dt2 << summary(Mean(:height), Invisible);
// Update the report
hlb << append(dt3 << Tabulate(Show Control Panel( 0 ), Add Table(Column Table( Analysis Columns( :"Mean(height)"n ), Statistics( Mean ) ))));
);
// Attach the script to the local data filter
rsh = ldf << makeFilterChangeHandler(ldfChange);新增一個範例來演示該問題可能會有所幫助。 (請參閱下面的 JSL)
此範例使用 JMP 樣本資料中的 AdverseR 資料。 目標是產生如下所示的儀表板:

您可以看到 SEX 上有一個資料過濾器。 還有一個列切換器,用於切換在兩個表格報告和分佈中匯總的「回應」變數。
第一個表格(左)給出了每個治療組的平均反應。
第二個表格(右)給出了每個治療組相對於 PBO 組的平均反應百分比變化。 這來自每個治療組的每個反應的平均值的總表(“dtSumm”)。
問題是資料篩選器適用於第二個表格報告之外的所有內容。 如果 dtSumm 能夠僅匯總滿足資料檔案管理器標準的數據,那將是理想的情況。 當資料過濾器中的選擇發生變化時,dtSumm 將會重新建立。
那可能嗎?
// Open the data table
dt = Open( "$SAMPLE_DATA/AdverseR.jmp" );
//Define cols as the list of columns for column switcher to use
//This is essentially hard-coding the columns that will be used in the dashboard
//Edit the items in this list to change the columns used in the dashboard
cols = {"DAY ON DRUG", "AGE", "WEIGHT", "ADR DURATION"};
//Define num as the number of columns in the list, cols
num = length(cols);
// We create a separate data table for treatment group means
// Get table, dtSumm, of means by group for each column in cols
dtSumm = dt << Summary (
Group (:Name("TREATMENT GROUP")),
Mean ( eval( cols ) ),
statistics column name format( "column" ),
Link to original data table( 1 ),
invisible
);
// Add RC columns for each column in cols to dtSumm
//This works by getting the mean for "PBO" treatment group for each
For( i = 1, i <= num, i++,
mean0 = Mean(Column(cols[i])[(dtSumm << get rows where( :"TREATMENT GROUP" == "PBO"))]);
dtSumm << New Column(
Char(cols[i]||"_RC"),
Formula( ( ( ( column( cols[i] )[]) - ( eval(mean0) ) ) / ( eval(mean0) ) ) * 100 )
);
);
// Create dashboard with tables and Distribution plot
mainWindow=New Window( "Example",
H List Box(
dt << Current Data Table() << Data Filter(
Location( {55, 48} ),
Mode( Select( 0 ), Show( 1 ), Include( 1 ) ),
Add Filter( columns( :SEX ) ) //
);
,
table1= dt << Tabulate(
Show Control Panel( 0 ),
Add Table(
Column Table(
Analysis Columns(
Column( cols[1] )
),
Statistics( Mean, N )
),
Row Table( Grouping Columns( :TREATMENT GROUP ) )
)
);
,
table2= dtSumm << Tabulate(
Change Item Label( Statistics( Mean, "%Rel Change" ) ),//Changes heading from "Mean"
Show Control Panel( 0 ),
Add Table(
Column Table( Analysis Columns( Char(cols[1]||"_RC") ), Statistics( Mean ) ),
Row Table( Grouping Columns( :TREATMENT GROUP ) )
)
);
,
dist0 = dt << Distribution(
Continuous Distribution(
Column( cols[1] ), //dt_c_col[1] uses first in column list
Always use column properties( 1 ),
Process Capability( 0 )
),
Histograms Only,
SendToReport(
Dispatch( {}, "Distribution", OutlineBox ),
Dispatch( {}, "Process 1", OutlineBox, {Close( 1 )} )
)
)
)
);
// Add a column switcher to table1
cs = table1 << Column Switcher(
cols[1],
cols
);
// Link column switchers at each platform - JMP 15 solution
cs1 = table2 << Column Switcher(
Char(cols[1]||"_RC"),
eval list(dtSumm << Get Column Names( String ))[(num+3)::(num+2+num)],
Close Outline( 1 )
);
cs2 = dist0 << Column Switcher(
cols[1],
cols,
Close Outline( 1 )
);
mainWindow[ListBoxBox( 1 )] << Set Script(
var = mainWindow[ListBoxBox( 1 )] << Get Selected;
cs1 << Set Current(Char(var[1]||"_RC"));
cs2 << Set Current(var[1]);
);