R Examples

To learn more about R, check out my open-access textbook Deep R Programming.

How to Install

To install the package from CRAN, call:

install.packages("lumbermark")

Note

For best performance, advanced users will benefit from compiling the package from sources:

Sys.setenv(CXX_DEFS="-O3 -march=native")  # for gcc and clang
install.packages(c("quitefastmst", "deadwood", "lumbermark"), type="source")

To enable OpenMP on macOS, execute brew install libomp, and then call in R:

Sys.setenv(CXX_DEFS="-O3 -march=native -Xpreprocessor -fopenmp")
install.packages(c("quitefastmst", "deadwood", "lumbermark"), type="source")

Basic Use

Note

This section is a work in progress. In the meantime, take a look at the documentation of the lumbermark function and the paper [2].

wut/z2 is an example dataset with five clusters of rather non-homogeneous densities. Lumbermark separates them correctly with no need for further parameter tuning:

Z2 <- as.matrix(read.table("z2.data.gz"))
library("lumbermark")
lumbermark_labels <- lumbermark(Z2, 5)
plot(Z2, asp=1, ann=FALSE, col=lumbermark_labels)
../_images/r_z2_dataset-1.png

Figure 4 The z2 dataset

Outlier Detection in the Case of Clusters of Heterogeneous Densities

The recently-developed Deadwood outlier detection algorithm works already quite well in the case of clusters of heterogeneous densities. Still, we can combine it with Lumbermark to detect outliers in each detected cluster separately.

par(mfrow=c(1, 2))

library("deadwood")

is_outlier_homo   <- deadwood(Z2)
plot(Z2, asp=1, xlab=NA, ylab=NA,
    col=c("#00000055","#ff333333")[is_outlier_homo+1], main="Deadwood")

is_outlier_hetero <- deadwood(lumbermark_labels)
plot(Z2, asp=1, xlab=NA, ylab=NA,
    col=c("#00000055","#ff333333")[is_outlier_hetero+1], main="Deadwood+Lumbermark")
../_images/r_z2_deadwood-1.png

Figure 5 Outlier detection of the z2 dataset