;+
; NAME:
; bootstrap_mean
;
;
; PURPOSE:
; compute the bootstrap mean
;
;
; CATEGORY:
; Statistics
;
;
; INPUTS:
; X: Values array to compute the bootstrap mean of
;
;
; KEYWORD PARAMETERS:
; PLOT: Make a plot the botstrap mean
; N_ITER: number of bootstrap iteratons, default:500
; COLOR: Color for the plot
; BACK: background for the plot
; ALL_MEANS: Array to contain the array of all means
; _EXTRA: Extra keywords to plot
;
; OUTPUTS:
; Array containing the mean and stddev(mean)
;
;
;
; EXAMPLE:
; IDL> x=randomn(seed, 100)*2+20
; IDL> print, bootstrap_mean(x, /plot)
; 19.8310 0.173062
;
;
;
; MODIFICATION HISTORY:
;
; Wed Feb 13 16:31:03 2008, Brian Larsen
; written and tested
;
;-
FUNCTION bootstrap_mean, x, $
PLOT = plot, $
N_ITER = n_iter, $
ALL_MEANS = all_means, $
COLOR = color, $
BACK = back, $
_EXTRA = _EXTRA
IF n_elements(x) LT 2 THEN $
message, /ioerror, 'Input must have at least 2 elements'
n_x = n_elements(x)
IF n_elements(n_iter) EQ 0 THEN $
n_iter = 500
IF type(x) EQ 5 THEN $ ; if input is dbl use dbl
means = dblarr(n_iter) ELSE $ ; else use float
means = fltarr(n_iter)
mean = mean(x)
FOR i = 0L, n_iter-1 DO BEGIN
ind = resample(n_x, n_x)
means[i] = mean(x[ind])
ENDFOR
IF keyword_set(plot) THEN BEGIN
plot, means, $
psym = 0, $
/ynozero, $
xtitle = 'Iteration number', $
ytitle = 'Bootstrap mean', $
COLOR = color, $
BACK = back, $
_STRICT_EXTRA = _EXTRA
oplot_horiz, mean, COLOR = color
ENDIF
IF arg_present(ALL_MEANS) THEN $
all_means = means
return, [mean, stddev(means)]
END