The Summarize command collects summary statistics for a data table and stores them in global variables. The Summarize command is different from the Summary command, which also calculates summary statistics, but presents them in a new data table.
Summarize( dt1,
exg = By( :sex ),
exm = Mean( :height )
Show( exg );
Show( exm );
Named arguments include the following: Count, Sum, Mean, Min, Max, StdDev, First, Corr, and Quantile. These statistics can be calculated only for numeric columns. Each argument takes a data column argument.
•
|
If a name=By(groupvar) statement is included, then a list of subgroup statistics is assigned to each name.
|
•
|
Count does not require a column argument, but it is often useful to specify a column to count the number of nonmissing values.
|
•
|
Quantile also takes a second argument for specifying which quantile, such as 0.1 for the 10th percentile.
|
注意:Excluded rows are excluded from Summarize calculations. If all data are excluded, Summarize returns lists of missing values. If all data have been deleted (there are no rows), Summarize returns empty lists.
sumHt = Sum( :height ),
meanHt = Mean( :height ),
minHt = Min( :height ),
maxHt = Max( :height ),
sdHt = Std Dev( :height ),
Show( a, c, sumHt, meanHt, minHt, maxHt, sdHt, q10Ht );
Because the script included a By group, the results are a list and six matrices:
You can format the results using TableBox.
New Window( "Summary Results",
图 9.2 Results from Summarize
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
sumHt = Sum( :height ),
meanHt = Mean( :height ),
minHt = Min( :height ),
maxHt = Max( :height ),
sdHt = Std Dev( :height ),
tsumHt = Sum( :height ),
tmeanHt = Mean( :height ),
tminHt = Min( :height ),
tmaxHt = Max( :height ),
tsdHt = Std Dev( :height ),
Insert Into( a, "Total" );
New Window( "Summary Results",
图 9.3 Summarize with Total
sumHt = Sum( :height ),
meanHt = Mean( :height ),
minHt = Min( :height ),
maxHt = Max( :height ),
sdHt = Std Dev( :height ),
Show( c, sumHt, meanHt, minHt, maxHt, sdHt, q10Ht );
Summarize supports multiple By groups. For example, in Big Class.jmp, proceed as follows:
Summarize( g = By( :age, :sex ), c = Count() );
Show( g, c );