Advertisement
wachiorsino

BOOT_BINDATA nasa.gov

Mar 1st, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. BOOT_BINDATA
  2.  
  3. PRO BOOT_BINDATA,NBINS, XIN,YIN, X1,X2,NSAMP, X,Y,S,BINHITS, ITYPE
  4. ;
  5. ;+
  6. ; NAME:
  7. ; BOOT_BINDATA
  8. ;
  9. ; PURPOSE:
  10. ; Groups data into NBINS bins of equal size, and finds the robust mean of
  11. ; each bin. The X value per bin is not necessarily = bin-center. The boot-
  12. ; strap method is used. If a bin has fewer than 6 points, the biweighted
  13. ; mean is calculated; otherwise, a robust line is fitted to the data.
  14. ;
  15. ; CALLING SEQUENCE:
  16. ; BOOT_BINDATA, NBins, Xin, Yin, X1, X2, NSamp, X, Y, S, BinHits, [IType]
  17. ;
  18. ; INPUTS:
  19. ; NBins = number of bins
  20. ; Xin = the input X values
  21. ; Yin = the input Y values
  22. ; X1 = the low end of the range of X
  23. ; X2 = the high end of the range of X
  24. ; NSamp = the number of bootstrap samples
  25. ; IType (OPTIONAL) = use logarithmically equal bin-widths if present
  26. ;
  27. ; OUTPUTS:
  28. ; X = the X values of the bins
  29. ; Y = the y values (=-100000 if a bin is empty)
  30. ; S = the robust standard deviations of the bins
  31. ; BinHits = the number of entries per bin.
  32. ;
  33. ; NOTES:
  34. ;
  35. ; If a bin has fewer than 6 entries, a biweighted mean of Y is
  36. ; calculated; X is weighted by the same weights, so the X value of the bin
  37. ; is not necessarily bin-center. If 6 points or more, a robust line is
  38. ; fitted to the data, and evaluated at bin-center.
  39. ;
  40. ; REVISION HISTORY
  41. ; Written, H.T. Freudenreich, Hughes STX, 12/3/92
  42. ;-
  43.  
  44. X=FLTARR(NBINS)
  45. Y=FLTARR(NBINS)
  46. S=FLTARR(NBINS)
  47. BINHITS=LONARR(NBINS)
  48. ITYPE=0
  49.  
  50. IF N_PARAMS() GT 10 THEN BEGIN
  51. ITYPE = 1
  52. IF X1 LE 0. THEN BEGIN
  53. PRINT,'BOOT_BINDATA: For Log Scale, Xmin > 0.!'
  54. RETURN
  55. ENDIF
  56. DX = EXP( ALOG(X2/X1)/NBINS )
  57. ENDIF ELSE DX = (X2-X1)/NBINS
  58.  
  59. NUM = -1
  60. FOR I=0,NBINS-1 DO BEGIN
  61. IF ITYPE EQ 0 THEN X2=X1+DX ELSE X2=X1*DX
  62. NUM=NUM+1
  63. Q=WHERE((XIN GE X1) AND (XIN LT X2),COUNT)
  64. BINHITS(NUM)=COUNT
  65. S(NUM) = 0.
  66. X(NUM) = .5*(X1+X2)
  67.  
  68. IF COUNT EQ 0 THEN BEGIN
  69. Y(NUM) = -1000000.
  70. ENDIF ELSE IF COUNT EQ 1 THEN BEGIN
  71. X(NUM) = XIN(Q(0))
  72. Y(NUM) = YIN(Q(0))
  73. ENDIF ELSE IF COUNT EQ 2 THEN BEGIN
  74. X(NUM) = (XIN(Q(0))+XIN(Q(1)))/2.
  75. Y(NUM) = (YIN(Q(0))+YIN(Q(1)))/2.
  76. ENDIF ELSE BEGIN
  77. IF COUNT LT 6 THEN BEGIN
  78. BOOT_MEAN, YIN(Q), NSAMP, MEANS, /ROBUST
  79. IF NSAMP GT 0 THEN BEGIN
  80. Y(NUM) = TOTAL(MEANS)/count
  81. X(NUM) = TOTAL(XIN(Q))/count
  82. S(NUM) = STDEV(MEANS)
  83. ENDIF ELSE BEGIN
  84. Y(NUM) = MED(YIN(Q))
  85. X(NUM) = TOTAL(XIN(Q))/COUNT
  86. S(NUM) = 0.
  87. ENDELSE
  88. ENDIF ELSE BEGIN
  89. X(NUM) = TOTAL(XIN(Q))/COUNT
  90. CC = BOOT_POLYFIT(XIN(Q),YIN(Q),1,NSAMP,NOUT,/ROBUST)
  91. IF NOUT EQ 1 THEN BEGIN
  92. Y(NUM)=YIN(Q)
  93. ENDIF ELSE BEGIN
  94. YY=CC(0,*)+CC(1,*)*X(NUM)
  95. Y(NUM)=TOTAL(YY)/COUNT
  96. S(NUM)=STDEV(YY)
  97. ENDELSE
  98. ENDELSE
  99. ENDELSE
  100. X1 = X2
  101. ENDFOR
  102.  
  103. RETURN
  104. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement