Hi All,
I'd like to thank you for your ongoing suggested changes. I have made some changes to the script and like the latest modified version better, so I really appreciate other's contributions. The updated script will be posted at the end of this reply. This new script also provides summary statistics for Character data types. I also slightly modified the layout of the panels.
@jthi , I think your suggestions were very good, and I have incorporated them. I like the colored header names for the result statistics. Also, similar to what @ErraticAttack had in their code, I made it so that the stats would update upon selecting a new column OR selecting a new numerical result. I allowed the character stat results to change its vertical size because there might be many levels, like for the Big Class.jmp data table. The categorical stats will also update when changing to that column type, but will throw an error if the character column is selected and then someone clicks on a numerical stat option. I did keep the width suggestion so the window wouldn't keep changing width size. Sorry @ErraticAttack , I'm not so familiar at this point with defining new name spaces and how you went about modifying the code. It does look very useful and a good way to approach things, I just need to learn how to do it correctly.
I'm sure there are other suggestions out there on how to improve this, especially the aesthetics. If so, please post, but be sure to tag me so I know there's been an update to this discussion. Thanks again everyone for your suggested improvements.
Thanks!,
DS
<JSL> below
//GUI for quickly reporting statistics written by D. Schmidt, ver1.5
//Thanks to JMP User community members: jthi, ian_jmp, and ErraticAttach for helpful suggested changes.
Names Default To Here( 1 );
Clear Symbols();
//the width of the column list box in pixels
lbWidth = 217;
dt = Current Data Table();
//dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
//List of statistics to calculate
StatsList1 = {"µ", "σ", "Max", "Min", "Range(Δ)", "N"};
StatsList2 = {"Quantiles", "5%", "25%", "50%", "75%", "95%"};
StatsList3 = {"N", "N Missing", "N 0", "Prop 0", "Prop non-0"};
maxStatCount = Max( N Items( StatsList1 ), N Items( StatsList2 ), N Items( StatsList3 ) );
//RadioBox() arguments
rbArg = Eval List( {Concat Items( StatsList1, ", " ), Concat Items( StatsList2, ", " ), Concat Items( StatsList3, ", " )} );
rbcArg = {"Select for categorical columns"};
//Statistics to Calculate
statMean = Expr( Col Mean( tempCol ) );
statStd = Expr( Col Std Dev( tempCol ) );
statMax = Expr( Col Max( tempCol ) );
statMin = Expr( Col Min( tempCol ) );
statRange = Expr(
Col Max( tempCol ) - Col Min( tempCol )
);
statN = Expr( Col Number( tempCol ) );
statQ95 = Expr(
Col Quantile( tempCol, 0.05 )
);
statQ75 = Expr(
Col Quantile( tempCol, 0.25 )
);
statQ50 = Expr(
Col Quantile( tempCol, 0.5 )
);
statQ25 = Expr(
Col Quantile( tempCol, 0.75 )
);
statQ5 = Expr(
Col Quantile( tempCol, 0.95 )
);
statMiss = Expr(
Col N Missing( tempCol )
);
statZero = Expr(
N Items( Loc( tempCol << get as matrix, 0 ) )
);
statProp0 = Expr( statZero / statN );
statPropn0 = Expr( 1 - statProp0 );
CatStats = Expr(
coltype = tempCol << Get Data type;
If( coltype == "Character",
catdist = dt << Distribution( Nominal Distribution( Column( tempCol ) ), Invisible );
rpt_catdist = catdist << Report;
lvl = rpt_catdist[String Col Box( 1 )] << Get;
Count = rpt_catdist[Number Col Box( 1 )] << Get;
Prob = rpt_catdist[Number Col Box( 2 )] << Get;
SummNMiss = rpt_catdist[List Box( 7 )][2] << Get Text;
SummLvl = rpt_catdist[List Box( 8 )][1] << Get text;
numNMiss = Num( SummNMiss );
numLvl = Num( SummLvl );
catdist << Close Window;
);
Insert Into( lvl, {"N Missing", "N Levels"} );
Insert Into( Count, numNMiss );
Insert Into( Count, numLvl );
);
//List for results
StatList = Eval List( {StatsList1, StatsList2, StatsList3} );
StatListRes1 = Expr(
Eval List( {statMean, statStd, statMax, statMin, statRange, statN} )
);
StatListRes2 = Expr(
Eval List( {., statQ95, statQ75, statQ50, statQ25, statQ5} )
);
StatListRes3 = Expr(
Eval List( {statN, statMiss, statZero, statProp0, statPropn0} )
);
StatListRes = Expr(
Eval List( {StatListRes1, StatListRes2, StatListRes3} )
);
//User window
ValueDlg = Expr(
nwin = New Window( "GUI for quick stats",
<<Return Result,
<<On Validate,
Border Box( Left( 3 ), Top( 2 ),
V List Box(
Text Box( "Quick Stats Window", <<Set Font Size( 12 ) ),
H List Box(
Panel Box( "Select Columns",
ColListData = Col List Box(
dt,
All,
Grouped,
Max Selected( 1 ),
width( lbWidth ),
nLines( 10 ),
<<On change(
lvlcb << Set( {} );
ccb << Set( {} );
pcb << Set( {} );
scb << Set( {} );
ncb << Set( {} );
tempCol = Column( dt, (ColListData << Get Selected) );
If( !Contains( dt << Get Column Names, tempCol ),
Throw( "No Column Selected" ),
coltype = tempCol << Get Data type;
If(
Coltype == "Numeric",
vals = qstats << get;
scb << Set( StatList[vals] );
ncb << Set( StatListRes( vals )[vals] );,
Coltype == "Character",
CatStats;
lvlcb << Set( lvl );
ccb << Set( Count );
pcb << Set( prob );
);
);
)
)
),
Panel Box( "Numerical Results",
ntb = Table Box(
scb = String Col Box( "Stats", {}, <<set width( 75 ) ),
ncb = Number Col Box( "Values", {} ),
String Col Box( "", Repeat( {""}, maxStatCount ), Visibility( "Hidden" ) ) //you can use hidden string col box to "force" height to Table box
)
),
Panel Box( "Categorical Results",
ctb = Table Box(
lvlcb = String Col Box( "Level", {}, <<set width( 70 ) ),
ccb = Number Col Box( "Count", {} ),
pcb = Number Col Box( "Prob", {} ),
String Col Box( "", Repeat( {""}, maxStatCount ), Visibility( "Hidden" ) ) //you can use hidden string col box to "force" height to Table box
)
),
Panel Box( "Action",
Lineup Box( N Col( 1 ),
Button Box( "Cancel/End", nwin << Close Window ),
Text Box( " " ),
Button Box( "Help", Web( "https://www.jmp.com/en_ch/support/online-help-search.html?q=*%3A*" ) )
)
)
),
V List Box(
H List Box(
Panel Box( "Choose numerical quick stats",
qstats = Radio Box(
rbArg,
<<Set Function(
Function( {this, index},
{},
lvlcb << Set( {} );
ccb << Set( {} );
pcb << Set( {} );
scb << Set( {} );
ncb << Set( {} );
vals = this << get;
If(
!Contains( dt << Get Column Names, tempCol );, Throw( "No Column Selected" ),
Coltype != "Numeric", Throw( "Wrong Column Type for Numerical Stats" ),
tempCol = Column( dt, (ColListData << Get Selected) );
coltype = tempCol << Get Data type;
scb << Set( StatList[vals] );
ncb << Set( StatListRes( vals )[vals] );
);
)
)
),
),
)
)
),
),
),
);
ValueDlg;