Confidence Intervals for the Mean or Median using Bootstrap Methods Code
How to save this page as a macro
macro
bootstrap x b est alpha;
store n.
###########################################################################
#
# Macro: bootstrap.MAC
# Written by: Daniel Griffith and Eduardo Santiago---December 2006
#
#
# This macro computes nonparametric confidence intervals on the mean and
# median of a sample by using bootstrap methods.
#
# The macro inputs one column (x) and three parameters (b, est, alpha).
# The one column should contain the data from your sample; the sample
# should be representative of the underlying distribution. The first
# parameter 'b' is the number of iterations that will be used to estimate
# the confidence interval. Typically this number is larger than 1000.
# The parameter 'est' indicates what kind of estimator is taken into
# consideration; 'est' takes the value of 1 for the mean and 2 for the
# median. The third parameter alpha is the significance level.
#
# For example, if the sample (data) column is in c1, and you want to
# estimate a confidence interval for the mean (1) based on 1000
# iterations using 95% confidence intervals then your alpha should be set
# to 0.05. This will automatically give you a two-sided 95% confidence
# interval. To run the macro, choose Edit > Command Line Editor and type
#
# %bootstrap c1 1000 1 0.05
#
# Click on Submit commands.
#
###########################################################################
#
# Neither Minitab, Inc. nor the author(s) of this MACRO makes any claim
# of or offers any Warranty whatsoever with regard to the accuracy of
# this MACRO or its suitability for use. Minitab, Inc. and the author(s)
# of this MACRO each hereby disclaims any Warranty and/or liability with
# respect thereto.
#
###########################################################################
mcolumn x theta c100 test lb ub tstar tstart lbt ubt blanks lab1 lab2 lab3 cilevel
mconstant b est alpha n i m q estn aa bb
default n=10000
mreset
notitle
brief 1
noecho
let n = count(x)
do i=1:b
sample n x c100;
replace.
if est=1
let theta(i)=mean(c100)
elseif est=2
let theta(i)=median(c100)
else
note
note
note **Error** You have specified a value other than 1 or 2 for the estimate
note parameter
note
exit
endif
enddo
sort theta theta;
by theta.
let m=(alpha/2)*b
let m=floor(m,0)
if m = 0
note
note
note **Error** (Alpha/2)*B is less than 1
note Increase B or Increase Alpha
note
exit
else
let q=b+1-m
let lb=theta(m)
let ub=theta(q)
if est=1
let tstar = mean(theta)
let estn = " Mean"
else
let tstar = median(theta)
let estn = " Median"
endif
text tstar lb ub tstart lbt ubt;
maxwidth 20.
tset blanks
" "
end
concat blanks tstart tstart
stack (estn "Lower Bound" "Upper Bound") (tstart lbt ubt) (tstart lbt ubt)
let cilevel = (1 - alpha)*100
text cilevel cilevel
tset lab2
" The "
end
tset lab3
"% Bootstrap Confidence Interval (Percentile Method)"
end
concat lab2 cilevel lab3 lab1
mtitle "Bootstrap Confidence Interval"
write lab1
write tstart lbt ubt
Histogram theta;
AxLabel 1 estn;
ADisplay 1;
#Table;
#Section 1;
NoTable;
Bar;
Distribution;
Normal;
Reference 1 lb;
Type 1;
Color 25;
Size 2;
MODEL 1;
Label "Lower Bound";
Reference 1 tstar;
Type 1;
Color 74;
Size 2;
MODEL 1;
Label estn;
Reference 1 ub;
Type 1;
Color 25;
Size 2;
MODEL 1;
Label "Upper Bound";
# SubTitle;
# StDist;
Footnote;
FPer;
Title "Bootstrapping Distribution of the Parameter";
Footnote;
FPanel;
NoDTitle;
NoDSubtitle;
wtitle "Bootstrap Histogram";
NoPerFootnote.
endif
endmacro
Disclaimer:
Minitab Inc. provides the Macro Library as a convenience only. Minitab neither endorses, supports, nor verifies the accuracy of any content, information, or functionality of any macro found in the Macro Library. Minitab specifically disclaims any and all responsibility or liability arising from or related to any reliance upon, use, or incorporation of any content, information, or macro found in the Macro Library.