Categories &

Functions List

Function Reference: jackknife

statistics: jackstat = jackknife (E, x)

statistics: jackstat = jackknife (E, x, …)

statistics: jackstat = jackknife (…, 'Options', options)

Compute jackknife estimates of a parameter taking one or more given samples as parameters.

In particular, E is the estimator to be jackknifed as a function name, handle, or inline function, and x is the sample for which the estimate is to be taken. Each row of x is an observation, and a row vector is taken as a column of them. The i-th row of jackstat holds the estimator’s value on x with its i-th row omitted, reshaped to a row, so an estimator returning m values gives an n×m matrix for n observations, and a scalar estimator a column vector. Every sample must give the estimator’s result the same number of elements as the whole of x does. With fewer than two observations there is nothing to omit, and jackstat is the estimator’s value on x itself.

 
 jackstat (i,:) = E (x([1:i-1, i+1:end],:))

Depending on the number of samples to be used, the estimator must have the appropriate form:

  • If only one sample is used, then the estimator need not be concerned with cell arrays, for example jackknifing the standard deviation of a sample can be performed with jackstat = jackknife (@std, rand (100, 1)).
  • If several samples are used, an estimator that takes as many inputs, or declares varargin, receives each sample as an argument of its own, as in MATLAB. A scalar is passed to every call unchanged, and the other samples must all have the same number of rows, the same row being omitted from each:
 
 jackstat = jackknife (@(x, y) std (x) / var (y),
 rand (100, 1), randn (100, 1))

An estimator declaring exactly one input instead receives the samples as the elements of a cell array, in their order of appearance, and the samples must all have the same number of rows. This form is an Octave extension. An estimator written for it that also declares an optional second input receives the samples as separate arguments.

 
 jackstat = jackknife (@(x) std(x{1})/var(x{2}),
 rand (100, 1), randn (100, 1))

'Options' takes an options structure, as made by statset, for MATLAB compatibility; it changes nothing, the samples being evaluated one after another.

If all goes well, a theoretical value P for the parameter is already known, n is the sample size,

t = n * E(x) - (n - 1) * mean(jackstat)

and

v = sumsq(n * E(x) - (n - 1) * jackstat - t) / (n * (n - 1))

then

(t-P)/sqrt(v) should follow a t-distribution with n-1 degrees of freedom.

Jackknifing is a well known method to reduce bias. Further details can be found in:

References

  1. Rupert G. Miller. The jackknife - a review. Biometrika (1974), 61(1):1-15. doi:10.1093/biomet/61.1.1
  2. Rupert G. Miller. Jackknifing Variances. Ann. Math. Statist. (1968), Volume 39, Number 2, 567-582. doi:10.1214/aoms/1177698418

Source Code: jackknife

 rng (42);
 for k = 1:1000
   x = rand (10, 1);
   s(k) = std (x);
   jackstat = jackknife (@std, x);
   j(k) = 10 * std (x) - 9 * mean (jackstat);
 endfor
 figure ();
 hist ([s', j'], 0:sqrt (1/12)/10:2*sqrt (1/12))
plotted figure

 rng (42);
 for k = 1:1000
   x = randn (1, 50);
   y = rand (1, 50);
   jackstat = jackknife (@(x) std (x{1})/std (x{2}), y, x);
   j(k) = 50 * std (y) / std (x) - 49 * mean (jackstat);
   v(k) = sumsq ((50 * std (y) / std (x) - 49 * jackstat) - j(k)) / (50 * 49);
 endfor
 t = (j - sqrt (1 / 12)) ./ sqrt (v);
 figure ();
 plot (sort (tcdf (t, 49)), ...
       '-;Almost linear mapping indicates good fit with t-distribution.;')
plotted figure

Jackknife the correlation of two samples, each handed to the estimator as an argument of its own, and correct it for bias

 rng (42);
 x = randn (30, 1);
 y = x + randn (30, 1);
 n = numel (x);
 r = corr (x, y);
 jackstat = jackknife (@(a, b) corr (a, b), x, y);
 bias = (n - 1) * (mean (jackstat) - r)
bias = 5.1710e-03
 se = sqrt ((n - 1) / n * sumsq (jackstat - mean (jackstat)))
se = 0.1067
 r_corrected = r - bias
r_corrected = 0.6880