Minitab:计算宏中的样本方差

时间:2016-01-16 15:31:21

标签: minitab

所以我在minitab中的C1中有这组样本,我从这些数据中进行了200次重采样并将其存储在C2-C201中。现在,我想计算每个列的样本方差,然后将结果保存在单独的列中。我可以让它来计算每列的样本方差,但是我在保存结果时遇到了问题。这是我目前的宏:

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

这可以完成这项任务,但它只是一遍又一遍地覆盖同一个单元格。最好的办法就是每次迭代都像c202(K1)一样保存它,但我不知道如何实现它。

1 个答案:

答案 0 :(得分:0)

嗯。我有很多方法可以改变这个宏。

您所述问题的原因是Statistics的Variance子命令将结果存储在整列中,覆盖了内容。如果您真的想将200个单独的子样本存储在不同的列中,那么应该这样做:

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

如果您想存储子样本,但很乐意将它们存储在两列中,那么这就更整洁了:

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

当然,200 x 16样品的更换与3200个样品相同,只需更换,因此更整洁 - 更快 - 将是:

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