Learn R Programming

AssocBin (version 1.1-0)

singleBinner: Single split recursive binning

Description

`singleBinner` is an iterative implementation of a recursive binary partitioning algorithm which accepts the splitting and stopping functions that guide partitioning as arguments.

Usage

singleBinner(
  x,
  y,
  stopper,
  splitter,
  init = halfSplit,
  maxK = 5,
  dropPoints = FALSE
)

Value

A list of lists each with elements `x`, `y`, `bnds`, `expn`, `n`, and `stopped`.

Arguments

x

numeric vector of the first variable to be binned

y

numeric vector of the second variable to be binned

stopper

function which accepts a list with elements `x`, `y`, `bnds`, `expn`, and `n` and returns a logical indicating whether a split should occur for the bin defined by that list

splitter

function which accepts a list of lists with elements `x`, `y`, `bnds`, `expn`, and `n` and returns a list where each element is a list of two corresponding to a split of the bin at that position in the original list

init

function like `splitter` applied to the first bin

maxK

integer giving the number of bins where splitting is stopped regardless of stop criteria

dropPoints

logical; should points be dropped from final bins?

Author

Chris Salahub

Details

`singleBinner` creates a two-dimensional histogram of the sample space of `x` and `y` by recursively splitting partitions of the data using `splitter` until `stopper` indicates that all partitions are not to be split. An optional argument `init` gives the function applied to the first bin containing all points to initialize the binning algorithm. Unlike `binner`, it does this by splitting one bin at a time, and so accepts an argument to specify exactly how many bins to produce.

Examples

Run this code
## necessary set up
crits <- makeCriteria(depth >= 4, n < 10, expn <= 5)
stopFn <- function(bns) stopper(bns, crits)
spltFn <- function(bn) rIntSplit(bn, minExp = 5)
## generate data
x <- sample(1:100)
y <- sample(1:100)
## run binner
bins <- singleBinner(x, y, stopper = stopFn, splitter = spltFn)

Run the code above in your browser using DataLab