0

So I have this set of samples in C1 in minitab, and I make 200 resamples from this data and store it in C2-C201. Now I want to calculate the sample variance from each of these columns and then save the result in a seperate column. I can get it to calculate the sample variance for each of the columns, but I am having trouble saving the results. This is my current macro:

GMACRO          #Starts the global macro
Resample        #Names the macro
DO K1=2:201
Sample 16 'Data' CK1;
Replace.        #Resampling
Name c202 "Variance"
Statistics CK1;     # Calculate S^2 
  Variance 'Variance'.
ENDDO
ENDMACRO        #Ends the macro

This does the job, but it just overwrites the same cell over and over. The optimal thing would be for it to just save it like c202(K1) for each iteration, but I'm not sure how to implement this.

HereBeeBees
  • 145
  • 9

1 Answers1

1

Hmmm. There are many ways I would change that macro.

The cause of your stated problem is that the Variance subcommand to Statistics stores the results in a whole column, overwriting the contents. If you really want to store the 200 separate subsamples in separate columns then this should do it:

GMACRO          #Starts the global macro
Resample        #Names the macro
Name c202 "Variance" # no need to name this column 200 times!
DO K1=2:201
  Sample 16 'Data' CK1;
    Replace.        #Resampling
  Statistics CK1;     # Calculate S^2 
    Variance C203.  # into row 1 of temporary column C203
  Stack 'Variance' C203 'Variance' # append to end of Variance
ENDDO
erase K1 c203  # clean up
ENDMACRO        #Ends the macro

If you want to store the subsamples but are happy to store them in just two columns then this is neater:

GMACRO          #Starts the global macro
Resample        #Names the macro
Name C2 'Sample number' c3 'Sample data'
set 'Sample number' # populate Sample number
(1:200)16
end
DO K1=1:200 
  Sample 16 'Data' c4;
    Replace.        #Resampling
  Stack C4 'Sample data' 'Sample data' # append to Sample data
ENDDO
Name c4 "Variance"
Statistics 'Sample data';
  By 'Sample number';
  Variance 'Variance'.
ENDMACRO        #Ends the macro

Of course, 200 x 16 samples with replacement is identical to 3200 samples with replacement so even neater - and much faster- would be:

GMACRO          #Starts the global macro
Resample        #Names the macro
Name C2 'Sample number' c3 'Sample data'
set 'Sample number' # populate Sample number
(1:200)16
end
Sample 3200 'Data' 'Sample data';
replace.
Name c4 "Variance"
Statistics 'Sample data';
  By 'Sample number';
  Variance 'Variance'.
ENDMACRO        #Ends the macro
user20637
  • 664
  • 3
  • 11