The macro TRIM calculates a 10% trimmed mean--5% trimmed from each end of the data--for a column of data from the global worksheet and stores it in a constant in the global worksheet.
(1) |
MACRO |
(2) |
TRIM X XBAR |
|
# # TRIM takes one column, X, as input. It orders the data, trims 5% # from each end, calculates the mean of the remaining data, and # stores it in the constant XBAR. # |
(3) |
MCONSTANT N T1 T2 XBAR MCOLUMN X XSORT XTRIM |
(4) |
# # first we calculate the trimming points T1 and T2 LET N = COUNT(X) LET T1 = ROUND(N*0.05) LET T2 = N-T1+1 # next we check for the case when T1 = 0 and nothing is trimmed IF T1 = 0 LET XTRIM = X # otherwise, we sort X, trim the ends and calculate the mean ELSE LET XSORT = SORT(X) COPY XSORT XTRIM; OMIT 1:T1 T2:N. ENDIF LET XBAR = MEAN(XTRIM) |
(5) |
ENDMACRO |
Here is what each line in the macro means:
(1) MACRO marks the beginning of a local macro.
(2) Template. Says to invoke this macro with two arguments: argument 1 is the column of data to be trimmed, and argument 2 is the constant where the trimmed mean is to be stored. See Writing a Template.
(3) Declaration statements.
MCONSTANT declares four constants (N, T1, T2, and XBAR) to be used as variables by the local macro. One of these constants, XBAR, is an argument which corresponds to the constant that is passed into the macro when the user invokes the macro.
MCOLUMN declares three columns (X, XSORT, and XTRIM) to be used as variables by the local macro. One of these columns, X, is an argument which corresponds to the column that is passed into the macro when the user invokes the macro.
See Declaring Variables.
(4) Body of the macro.
(5) ENDMACRO marks the end of the macro.
All lines beginning with the comment symbol # are comments, which are ignored by Minitab. See Adding Comments.