One goal of this project was to become more familiar with R internals. This package contains two simple implementations of an EM algorithm to fit a Gaussian mixture model, one in R and one with (stl only) c++. Finally, the c++ is ported into R without the use of Rcpp.
See mclust for a more robust R implementation for fitting Gaussian mixture models.
devtools::install_github("gregory-bopp/gaussian_mixture_model/gmm")
See example/r_example.R
for an example of simulating data from a GMM and fit using the gmm EM implementation.
- Simulate GMM data with
example/example.R
. Data and initial values are stored inexample/data/
- Build gmm cpp program with
make
fromgmmcpp
- Run cpp implementation of EM algorithm to find ML estimates for GMM with
$ ./gmmcpp/bin/gmm -v -i ../example/data/init.csv -o ../example/data/fit.csv ../example/data/data.csv
See example/cpp_example.R