bin {mixR} | R Documentation |
Binning the Raw Data
Description
This function creates a binned data set from the raw data
Usage
bin(x, brks)
Arguments
x |
a numeric vector of raw data |
brks |
a numeric vector in increasing order, representing the bin values within each of which we want to calculate the frequency of the data |
Details
Given a numeric vector, the function bin
creates a binned data set with bin values provided
by brks
. Fitting mixture models with a large data set may be slow, especially when
we want to fit non-normal mixture models. Binning the data with a relatively
small bin width speeds up the computation of EM algorithm while at the same time keeps the
precision of the estimation result.
Value
The function bin
returns a matrix with three columns, representing the value of the left bin, the value of the right bin and the number of observations in x
that falls in each bin.
See Also
Examples
set.seed(99)
x <- rmixnormal(200, c(0.5, 0.5), c(2, 5), c(1, 1))
data <- bin(x, seq(-2, 10, 0.1))
fit1 <- mixfit(x, ncomp = 2)
fit2 <- mixfit(data, ncomp = 2)