function [TH,SE,CI] = BS_Ex1(dSet,nBoot,myAlpha) % NOTE: For compatibility with different web browsers, % this file has been renamed 'poissonTutorial.txt'. In % order to use it in MATLAB, you should rename it as % 'poissonTutorial.m' and then open it up with the % MATLAB editor. % bs_ex1.m: Bootstrap example for stroke data from pp. 3-5 of Efron & Tibshirani % % usage: [TH,SE,CI] = BS_Ex1(dSet,nBoot,Alpha) % ex: [TH,SE,CI] = BS_Ex1('stroke',1000,0.05); % % Inputs % - dSet, name of data set to use: 'stroke' or 'MI' % - nBoot, number of bootstrap iterations to perform % - Alpha, use 0.05 to get 95% CI % % Outputs % - TH, the ratio of rates for the two treatment groups (ASA:Placebo) % - SE, standard error of the ratio of rates % - CI, confidence interval % % RTB 5/28/2002 % defaults if nargin < 3, myAlpha = 0.05; end if nargin < 2, nBoot = 1000; end if nargin < 1, dSet = 'stroke'; end switch lower(dSet) case 'stroke' % sample data for strokes Y1 = [ones(119,1);zeros(10918,1)]; % aspirin group for strokes Y2 = [ones(98,1);zeros(10936,1)]; % non-aspirin group for strokes disp('Using dataset from Stroke Study.'); case 'mi' % sample data for heart attacks Y1 = [ones(104,1);zeros(10933,1)]; % aspirin group for heart attacks Y2 = [ones(189,1);zeros(10845,1)]; % non-aspirin group for heart attacks disp('Using dataset from heart attack study.'); otherwise % sample data for strokes Y1 = [ones(119,1);zeros(10918,1)]; % aspirin group for strokes Y2 = [ones(98,1);zeros(10936,1)]; % non-aspirin group for strokes disp('Data set not recognized: Using dataset from Stroke Study.'); end % calculate the actual ratio of rates TH = (sum(Y1)./length(Y1)) ./ (sum(Y2)./length(Y2)); % find bootstrap values--it's almost too easy. M1 = bootstrp(nBoot,'sum', Y1); M2 = bootstrp(nBoot,'sum', Y2); % calculate the standard error of the ratio of rates SE = std(M1 ./ M2); % determine confidence interval, CI C = sort(M1 ./ M2); iLo = floor((myAlpha/2) * nBoot); % index corresponding to lower bound iHi = nBoot - iLo; % index corresponding to upper bound CI = [C(iLo) C(iHi)];