Binning

require.mx('mxjs/base/utilities/binning.js');

Convenience functions for binning values.

StatusName
Object binValues ( Array values, Object settings )

calculateBinCentres ( Object binnedValues )

calculateBinStarts ( Object binnedValues )

generateHistogram ( Table outTable, Array values, Object settings )

Generate X/Y positions for a histogram of the given values, and write them to a table. The settings object uses the following properties:

  • min (optional) minimum value to consider for the range of the histogram. if no value is specified, then the minimum value in the data will be used.
  • max (optional) maximum value to consider for the range of the histogram. if no value is specified, then the maximum value in the data will be used.
  • binSize (optional) width of the histogram bins. If no width is specified, it will be calculated based on the min, max, and binCount.
  • binCount (optional) number of bins to use when binning the data. If not specified, the number of bins will be calculated based on the min, max, and binSize.
  • xPosition a string describing the relative position of the bin to be used for the x value written to the table, either "left" or "centre".
  • writeX a function that writes the X values to the table.
  • writeY a function that writes the Y values to the table.
  • writeID (optional) a function that writes IDs to the table. IF specified, IDs will automatically be generated as (table_index+1).
  • calculateY (optional) a function that calculates Y values for bins. The function is passed two parameters: the number of values in the current bin, and the total number of values considered from the data. For example function(binCount, totalCount) { return binCount / totalCount; }. If this function is not specified, the number of values in the current bin will be used as the Y value.
  • onWrite (optional) a function called for every row written to the output table. It is passed one parameter, the index of the written row. This can be used to write associated values (e.g. group IDs).


Library Functions

results = Lib.binValues ( values, settings )

Parameters: Returns: Object results
Lib.calculateBinCentres ( binnedValues )

Parameters:
  • Object binnedValues - results from binValues().
Lib.calculateBinStarts ( binnedValues )

Parameters:
  • Object binnedValues - results from binValues().
Lib.generateHistogram ( outTable, values, settings )

Generate X/Y positions for a histogram of the given values, and write them to a table. The settings object uses the following properties:

  • min (optional) minimum value to consider for the range of the histogram. if no value is specified, then the minimum value in the data will be used.
  • max (optional) maximum value to consider for the range of the histogram. if no value is specified, then the maximum value in the data will be used.
  • binSize (optional) width of the histogram bins. If no width is specified, it will be calculated based on the min, max, and binCount.
  • binCount (optional) number of bins to use when binning the data. If not specified, the number of bins will be calculated based on the min, max, and binSize.
  • xPosition a string describing the relative position of the bin to be used for the x value written to the table, either "left" or "centre".
  • writeX a function that writes the X values to the table.
  • writeY a function that writes the Y values to the table.
  • writeID (optional) a function that writes IDs to the table. IF specified, IDs will automatically be generated as (table_index+1).
  • calculateY (optional) a function that calculates Y values for bins. The function is passed two parameters: the number of values in the current bin, and the total number of values considered from the data. For example function(binCount, totalCount) { return binCount / totalCount; }. If this function is not specified, the number of values in the current bin will be used as the Y value.
  • onWrite (optional) a function called for every row written to the output table. It is passed one parameter, the index of the written row. This can be used to write associated values (e.g. group IDs).

Parameters: