# Jackknife a statistic

### Dimitri Shvorob (view profile)

15 Apr 2007 (Updated )

(Extension of JACKKNIFE)

jknifedemo
% JKNIFEDEMO  Demonstration of JKNIFE and JSTATS
% EXAMPLE   : jknife_demo (Oh, the FEX code metrics..)
% AUTHOR    : Dimitri Shvorob, dimitri.shvorob@vanderbilt.edu, 4/15/07

% Simple regression
n = 100;
x = rand(n,1);
i = ones(n,1);
a = 3;
b = 5;
y = a + b*x + randn(n,1);

% Jackknife calculations
disp('A. "fun" with vector output (OLS estimates of regression intercept and slope)')
ls = jknife('olsvector',[y i x]);
disp('Mean and variance estimates')
[m,v] = jstats(ls)     %#ok

disp('B. "fun" with structure output (OLS estimates of regression intercept and slope)')
ls = jknife('olsstructure',[y i x]);
disp('Mean and variance estimates')
[m,v] = jstats(ls,'b') %#ok

% Jackknife distributions of OLS estimates
ab = [ls.b];                      % note: may want to exclude actual-sample value
subplot(3,1,1)
scatter(x,y,2)
title(['Random sample: \ity = ' num2str(a) ' + ' num2str(b) 'x + \epsilon, \rmwhere \itx ~ U\rm[\it0,1\rm]\it,\epsilon ~ N\rm[\it0,1\rm], \iti = 1,..,100']);

subplot(3,1,2)
opt.dx   = .01;
opt.xmin = a - .5;
opt.xmax = a + .5;
opt.xmrk = a;
histf(ab(1,:),opt)
title(['OLS intercept estimate: jackknife distribution. (True value = \it' num2str(a) '\rm)'])

subplot(3,1,3)
opt.xmrk = b;
opt.xmin = b - .5;
opt.xmax = b + .5;
histf(ab(2,:),opt)
title(['OLS slope estimate: jackknife distribution. (True value = \it' num2str(b) '\rm)'])

A. "fun" with vector output (OLS estimates of regression intercept and slope)
Mean and variance estimates

m =

3.1155
4.6971

v =

0.0449
0.1239

B. "fun" with structure output (OLS estimates of regression intercept and slope)
Mean and variance estimates

m =

3.1155
4.6971

v =

0.0449
0.1239