Advertisement
wachiorsino

BOOT_MEAN nasa.gov

Mar 1st, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. PRO BOOT_MEAN, Y, N_SAMPLE, MEAN, ROBUST=whatever
  2. ;
  3. ;+
  4. ; NAME:
  5. ; BOOT_MEAN
  6. ;
  7. ; PURPOSE:
  8. ; Calculate the Bootstrap Mean. (Also see BBOOTSTRAP.)
  9. ;
  10. ; CALLING SEQUENCE:
  11. ; BOOT_MEAN, y, N_Sample, Mean, [ /ROBUST ]
  12. ; INPUT:
  13. ; Y = vector to average
  14. ; N_SAMPLE = the number of bootstrap samples
  15. ;
  16. ; OUTPUT:
  17. ; MEAN = vector of N_SAMPLE means
  18. ;
  19. ; OPTIONAL INPUT KEYWORD:
  20. ; ROBUST - If this argument is present, an iterative biweighted mean is
  21. ; returned
  22. ;
  23. ; SUBROUTINES CALLED:
  24. ; BIWEIGHT_MEAN, ROBUST_SIGMA, MED
  25. ;
  26. ;NOTE:
  27. ; This program randomly selects values to fill sets of the same size as Y,
  28. ; Then calculates the mean of each. It does this N_SAMPLE times.
  29. ;
  30. ; The user should choose N_SAMPLE large enough to get a good distribution.
  31. ; The sigma of that distribution is then the standard deviation of the
  32. ; mean of MEAN.
  33. ; For example, if input Y is normally distributed with a standard
  34. ; deviation of 1.0, the standard deviation of the vector MEAN will be
  35. ; ~1.0/SQRT(N-1), where N is the number of values in Y.
  36. ;
  37. ; WARNING:
  38. ; At least 5 points must be input. The more, the better.
  39. ; REVISION HISTORY:
  40. ; Written, H.T. Freudenreich, HSTX, ?/92
  41. ;-
  42.  
  43. IF KEYWORD_SET(WHATEVER) THEN BIWT=1 ELSE BIWT=0
  44.  
  45. N=N_ELEMENTS(Y)
  46.  
  47. IF N LT 5 THEN BEGIN
  48. PRINT,'BOOT_MEAN: Too few points! Setting N_SAMPLE to zero'
  49. N_SAMPLE = 0
  50. RETURN
  51. ENDIF
  52.  
  53. MEAN=FLTARR(N_SAMPLE)
  54.  
  55. R0=SYSTIME(1)*2.+1.
  56. SEEDS=RANDOMU(R0,N_SAMPLE)*1.0E6+1.
  57.  
  58. FOR L=0,N_SAMPLE-1 DO BEGIN
  59. ; Get the random number seed: FOR VMS!
  60. R=SEEDS(L)
  61. ; Uniform random numbers between 0 and N-1:
  62. PICK=RANDOMU(R,N)
  63. R=FIX(PICK*N)
  64. V=Y(R)
  65. IF BIWT EQ 0 THEN MEAN(L)=TOTAL(V)/N ELSE MEAN(L)=BIWEIGHT_MEAN(V)
  66. ENDFOR
  67.  
  68. RETURN
  69. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement