require(robustbase) # for example data and covMcd():
## simple 2D example :
plot(starsCYG, main = "starsCYG data (n=47)")
B.st <- mvBACON(starsCYG)
points(starsCYG[ ! B.st$subset,], pch = 4, col = 2, cex = 1.5)
stopifnot(identical(which(!B.st$subset), c(7L,11L,20L,30L,34L)))
## finds the 4 clear outliers (and 1 "borderline");
## it does not find obs. 14 which is an outlier according to covMcd(.)
iniS <- setNames(, eval(formals(mvBACON)$init.sel)) # all initialization methods, incl "random"
set.seed(123)
Bs.st <- lapply(iniS[iniS != "manual"], function(s)
mvBACON(as.matrix(starsCYG), init.sel = s, verbose=FALSE))
ii <- - match("steps", names(Bs.st[[1]]))
Bs.s1 <- lapply(Bs.st, `[`, ii)
stopifnot(exprs = {
length(Bs.s1) >= 4
length(unique(Bs.s1)) == 1 # all 4 methods give the same
})
## Example where "dUniMedian" and "V2" differ :
data(pulpfiber, package="robustbase")
dU.plp <- mvBACON(as.matrix(pulpfiber), init.sel = "dUniMedian")
V2.plp <- mvBACON(as.matrix(pulpfiber), init.sel = "V2")
(oU <- which(! dU.plp$subset))
(o2 <- which(! V2.plp$subset))
stopifnot(setdiff(o2, oU) %in% c(57L,58L,59L,62L))
## and 57, 58, 59, and 62 *are* outliers according to covMcd(.)
## 'coleman' from pkg 'robustbase'
coleman.x <- data.matrix(coleman[, 1:6])
Cc <- covMcd (coleman.x) # truly robust
summary(Cc) # -> 6 outliers (1,3,10,12,17,18)
Cb1 <- mvBACON(coleman.x) ##-> subset is all TRUE hmm??
Cb2 <- mvBACON(coleman.x, init.sel = "dUniMedian")
stopifnot(all.equal(Cb1, Cb2))
## try 20 different random starts:
Cb.r <- lapply(1:20, function(i) { set.seed(i)
mvBACON(coleman.x, init.sel="random", verbose=FALSE) })
nm <- names(Cb.r[[1]]); nm <- nm[nm != "steps"]
all(eqC <- sapply(Cb.r[-1], function(CC) all.equal(CC[nm], Cb.r[[1]][nm]))) # TRUE
## --> BACON always breaks down, i.e., does not see the outliers here
stopifnot(Cb1$subset, Cb.r[[1]]$subset, eqC)
## breaks down even when manually starting with all the non-outliers:
Cb.man <- mvBACON(coleman.x, init.sel = "manual",
man.sel = setdiff(1:20, c(1,3,10,12,17,18)))
which( ! Cb.man$subset) # the outliers according to mvBACON : _none_
Run the code above in your browser using DataLab