1. to contrast Hui's verb, histogram, which collects its frequency interval counts with the dyadic verb I. (Idot), with the interval counts in statistical histograms,

  2. to align properly the interval labels and their frequency counts, and
  3. to enable the construction of a statistical histogram with rescaled frequency counts when the intervals are not of uniform widths.



I. collects frequency counts based on intervals which are open on the left and closed on the right: (xi-1,xi]. Statistical intervals reverse this pattern: [xi-1,xi). This problem is dealt with later by reversing the input to Idot, after dealing with the alignment problem, although the reversal problem still exists here, and is just ignored.

histogram =: <: @ (#/.~) @ (i.   @#@[ , I.)  
histogram1=: <: @ (#/.~) @ (i.@>:@#@[ , I.)

test1 =: dyad define
 assert. ({:x)>:>./y
 assert. ({.x)<<./y
)


   d=: +/ 10 1e6 ?.@$ 21
   e=: 5 * i.40
   f=: }.}: e
   h =: e  histogram d
   h1=: f histogram1 d
   e (histogram-:histogram1) d        NB. should NOT be equal
0
   h1 -: }.h                          NB. should be equal
1
   f test1 d
   ff=: 2+/\-:e

   load 'plot'
   plot ff;h1


histogram1.jpg


The verb Idotr defined here reverses the application of I. and also adjusts the interval boundaries in the verb histogram2. However, alone histogram2 cannot cope with unequal interval widths. The final example creates unequal interval widths by eliminating the interval boundaries 45 and 50. The verbs relative and drawplot treat the Hui example as if it were to be modeled my a discrete probability mass model, instead of the continuous Gaussian density function. In such cases, the area of each interval is proportional to the interval's relative frequency, rather than the vertical heights being proportional to the relative frequency. The final plot shows the desired result.

histogram =: <: @ (#/.~) @ (i.   @#@[ , I.)  
histogram1=: <: @ (#/.~) @ (i.@>:@#@[ , I.)
histogram2=: <: @ (#/.~) @ (i.@>:@#@[ , Idotr)
Idotr =: |.@[ (#@[-I.) ]

relative =: ((2 -~/\ [) %~ }.@}:@histogram2) % #@]
drawplot =: 2&#@[ ; _1&|.@(2&#)@(,&0)@]

test1 =: dyad define
 assert. ({:x)>:>./y
 assert. ({.x)<<./y
)
test2 =: dyad define
  assert. ({:x)>>./y
  assert. ({.x)<:<./y
)

   d=: +/ 10 1e6 ?.@$ 21
   e=: 5 * i.40
   e2 =: e -. 45 50
   e2 test2 d
   'ycaption relative frequency'plot e2 ([ drawplot relative ) d


histogram2.jpg

BrianSchott/Histogram (last edited 2008-12-08 10:45:49 by )