1\name{binning} 2\alias{binning} 3\title{ 4Construct frequency table from raw data in 1, 2 or 3 dimensions. 5} 6\description{ 7Given a vector, or a matrix with 1, 2 or 3 columns, this function constructs a frequency table 8associated with appropriate intervals covering the range of \code{x}. 9} 10\usage{ 11binning(x, y, breaks, nbins) 12} 13\arguments{ 14\item{x}{ 15a vector or a matrix with either one, two or three columns, containing the original data. 16} 17\item{y}{ 18a vector of data, for example response data, associated with the data in \code{x}. 19} 20\item{breaks}{ 21either a vector or a matrix with two columns (depending on the dimension of \code{x}), 22assigning the division points of the axis, or the axes in the matrix case. 23It must not include \code{Inf},\code{-Inf} or \code{NA}s, and it must span the whole range of 24the \code{x} points. 25If \code{breaks} is not given, it is computed by dividing the range of \code{x} 26into \code{nbins} intervals for each of the axes. 27} 28\item{nbins}{ 29the number of intervals on each axis. If \code{nbins} is not supplied, a value is computed as \code{round(log(n)/log(2) + 1)}. 30}} 31\value{ 32In the vector case, a list is returned containing the following elements: 33a vector \code{x} of the midpoints of the bins excluding those with 0 frequecies, 34its associated matrix \code{x.freq} of frequencies, the co-ordinates of the 35\code{midpoints}, the division points, and the complete vector of observed 36frequencies \code{freq.table} (including the 0 frequencies), and the vector 37\code{breaks} of division points. 38In the matrix case, the returned value is a list with the following 39elements: a two-dimensional matrix \code{x} with the coordinates of the 40midpoints of the two-dimensional bins excluding those with 0 frequencies, 41its associated matrix \code{x.freq} of frequencies, the coordinates of the 42\code{midpoints}, the matrix \code{breaks} of division points, and the observed 43frequencies \code{freq.table} in full tabular form. 44} 45\details{ 46This function is called automatically (under the default settings) 47by some of the functions of the \code{sm} library when the sample size is 48large, to allow handling of datasets of essentially unlimited size. 49Specifically, it is used by \code{sm.density}, \code{sm.regression}, \code{sm.ancova}, 50\code{sm.binomial} and \code{sm.poisson}. 51} 52\references{ 53Bowman, A.W. and Azzalini, A. (1997). 54\emph{Applied Smoothing Techniques for Data Analysis: 55the Kernel Approach with S-Plus Illustrations.} 56Oxford University Press, Oxford. 57} 58\seealso{ 59\code{\link{sm}}, \code{\link{sm.density}}, \code{\link{sm.regression}}, \code{\link{sm.binomial}}, \code{\link{sm.poisson}}, \code{\link{cut}}, \code{\link{table}} 60} 61\examples{ 62# example of 1-d use 63x <- rnorm(1000) 64xb <- binning(x) 65xb <- binning(x, breaks=seq(-4,4,by=0.5)) 66# example of 2-d use 67x <- rnorm(1000) 68y <- 2*x + 0.5*rnorm(1000) 69x <- cbind(x, y) 70xb<- binning(x, nbins=12) 71} 72\keyword{nonparametric} 73% Converted by Sd2Rd version 1.15. 74