help mata mm_histogram()
-------------------------------------------------------------------------------

Title

mm_histogram() -- Produce histogram data

Syntax

real matrix mm_histogram(x [, w, g, dir ])

where

x: real colvector containing data points

w: real colvector containing weights

g: real colvector containing the interval boundaries; default is g = rangen(min(x), max(x), 11)

dir: real scalar specifying the direction of the intervals (default: right open)

Description

mm_histogram() computes the density of x for the intervals defined by the grid points in g (g must be sorted). The default is to use right open intervals (with the last interval closed). However, dir!=0 specifies that left open intervals be used (with the first interval closed).

w specifies weights associated with the observations in x. Omit w, or specify w as 1 to obtain unweighted results. Note that x, w, and g should not contain missing values.

mm_histogram() returns a matrix containing for each interval the center (first column), width (second column) and the density (third column).

Remarks

Example:

: x = invnormal(uniform(100,1)) : g = mm_makegrid(x, 6) : mm_histogram(x, 1, g) 1 2 3 +----------------------------------------------+ 1 | -2.257750662 1.036214862 .0579030491 | 2 | -1.2215358 1.036214862 .1737091472 | 3 | -.1853209385 1.036214862 .3088162617 | 4 | .8508939234 1.036214862 .3377677863 | 5 | 1.887108785 1.036214862 .0868545736 | +----------------------------------------------+

Conformability

mm_histogram(x, w, g, dir) x: n x 1 w: n x 1 or 1 x 1 g: m x 1, m>=2 dir: 1 x 1 result: m-1 x 3.

Diagnostics

mm_histogram() abort with error if min(x) < g[1] or max(x) > g[rows(g)].

mm_histogram() produces erroneous results if g is not sorted.

Source code

mm_histogram.mata

Author

Ben Jann, ETH Zurich, jann@soz.gess.ethz.ch

Also see

Online: help for mm_makegrid(), [M-5] range(), [M-4] utility, twoway__histogram_gen, moremata