
<!-- README.md is generated from README.Rmd. Please edit that file -->

[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/lowmemtkmeans)](https://cran.r-project.org/package=lowmemtkmeans)

# lowmemtkmeans

The tkmeans package attempts to implement the trimmed k-means algorithm
of Garcia-Escudero, et. al.(2008) using as little memory as possible.
Data is edited in place, the trimming is implemented using a priority
queue structure in C++ through Rcpp and low memory use versions of
utility functions are provided.

An extremely simple example:  
1. Convert the iris dataset to a matrix and rescale matrix columns.

    iris_mat <- as.matrix(iris[,1:4])
    scale_params<-scale_mat_inplace(iris_mat)

2.  Cluster with 2 and 3 clusters, 10% trimming  

<!-- -->

    iris_cluster_2<- tkmeans(iris_mat, 2 , 0.1, c(1,1,1,1), 1, 10, 0.001)  
    iris_cluster_3<- tkmeans(iris_mat, 2 , 0.1, c(1,1,1,1), 1, 10, 0.001)

3.  Calculate BIC  

<!-- -->

    BIC_2 <-cluster_BIC(iris_mat, iris_cluster_2)  
    BIC_3 <-cluster_BIC(iris_mat, iris_cluster_3)

4.  Allocate using 3 clustering  

<!-- -->

    clustering <- nearest_cluster(iris_mat, iris_cluster_3)

5.  Plot results using reconstructed matrix

<!-- -->

    library(lattice) 
    orig_matrix <- sweep(sweep(m,2,scale_params[2,],'*'),2,scale_params [1,], '+')  
    xyplot(orig_matrix[,1]~orig_matrix[,2], group=clustering) 

To install the latest version:

    install.packages("devtools")  
    library(devtools)  
    install_github("andrewthomasjones/tkmeans")  
