Next: bit_ops Up: MacAnova Help File Previous: bcprd()   Contents


bin(x,Bnds [,silent:T,leftendin:T]), x a REAL matrix, Bnds REAL vector,
   Bnds[k] < Bnds[k+1]
bin(x,vector(anchor,width) [,leftendin:T]), anchor and width > 0 REAL
bin(x,nbins, [leftendin:T]), nbins positive integer.
bin(x [,leftendin:T])

Keywords: categorical data, summary statistics
bin(x,Edges) counts the number of values v in each column of REAL vector
or matrix x in class intervals defined by the elements of REAL vector
Edges with length(Edges) > 2.  Edges must satisfy Edges[k] < Edges[k+1],
k = 1, ..., nclasses = length(Edges) - 1.  When x is a matrix, counts
are computed for each column of x.

The value of bin(x,Edges) is structure(boundaries:edges, counts:M) where
edges is a vector of length nclasses + 1 containing the class limits and
M contains counts.  In this usage, edges is identical to Edges.  When x
is a vector, M[k] = (number of values of x in class k).  When x is a
matrix, M is a matrix with nclasses rows and ncols(x) columns with
M[k,j] = (number of values in column j of x in class k).

The count for class k is the number of values v with Edges[k] < v <=
Edges[k+1], k = 1, ..., nclasses, that is any value equal to the right
end of an interval is counted in that interval.

When any element of x is <= Edges[1] or > Edges[nbins+1], it is not
included in the count and a warning message is printed.

bin(x,Edges,leftendin:T) does the same except a value v is counted in
class k if Edges[k] <= v < Edges[k+1], that is, a value equal to the
left end of a class is counted as being in the class.  v is not counted
when v < Edges[1] or v >= Edges[nbins+1].  'leftendin:T' can be used
with all variants of bin() arguments

bin(x,Edges,silent:T) does the same except any warning messages are
suppressed.  'silent:T' can be used with all variants of bin()

bin(x,vector(anchor, width)), where anchor and width are scalars, does
the same, except that the class boundaries are of the form anchor +
k*width, where k is an integer, with the minimum and maximum values of k
selected so as to include all the data in x.  For example, bin(x,
vector(.5,1)) would use class intervals of width 1 centered at integers.

bin(x,nbins) does the same, except that boundaries for nbins classes are
computed so that the classes have equal widths and include all the data.
The class boundaries will normally not be "neat".

bin(x) is equivalent to bin(x, ceiling(log(nrows(x))/log(2))+1), that is
the number of bins is approximately log2(nrows(x)).

You can use bin() to find counts needed to draw a histogram or to
compute a chi-squared test of goodness of fit of a sample to a
theoretical distribution.

Gary Oehlert 2003-01-15