################################################### ### chunk number 1: ################################################### options(width=80, prompt="R> ") ################################################### ### chunk number 2: ################################################### library("archetypes") ################################################### ### chunk number 4: ################################################### data("toy") par(mar = c(2,2,0,0) + 0.1, ps = 9) plot(toy, xlab = "", ylab = "", xlim = c(0,20), ylim = c(0,20), pch = 19, col = gray(0.7), cex = 0.6) ################################################### ### chunk number 5: ################################################### set.seed(1986) a <- archetypes(toy, 3) ################################################### ### chunk number 6: ################################################### a ################################################### ### chunk number 7: ################################################### atypes(a) ################################################### ### chunk number 9: ################################################### par(mfrow = c(1,2), mar = c(2,2,0,0)+0.1, ps = 9) plot(a, toy, chull = chull(toy), xlab = "", ylab = "", xlim = c(0, 20), ylim = c(0, 20), cex = 0.6) plot(a, toy, adata.show = TRUE, xlab = "", ylab = "", xlim = c(0, 20), ylim = c(0, 20), cex = 0.6) ################################################### ### chunk number 11: ################################################### par(mfrow = c(2, 4), mar = c(0, 0, 0, 0) + 0.1, ps = 9) movieplot(a, toy, xlim = c(0, 20), ylim = c(0, 20), cex = 0.6, axes = FALSE, postfn = function(iter) { box() text(1, 19, paste(iter + 1, ".", sep = ""), cex = 1) }) ################################################### ### chunk number 12: ################################################### set.seed(1986) a4 <- stepArchetypes(data = toy, k = 3, verbose = FALSE, nrep = 4) ################################################### ### chunk number 13: ################################################### a4 ################################################### ### chunk number 14: ################################################### summary(a4) ################################################### ### chunk number 16: ################################################### par(mar = c(2, 2, 0, 0) + 0.1, ps = 9) plot(a4, toy, cex = 0.6, xlim = c(0, 20), ylim = c(0, 20), xlab = "", ylab = "") ################################################### ### chunk number 18: ################################################### print(bestModel(a4), full = FALSE) ################################################### ### chunk number 19: ################################################### set.seed(1986) as <- stepArchetypes(data = toy, k = 1:10, verbose = FALSE, nrep = 4) ################################################### ### chunk number 20: ################################################### rss(as) ################################################### ### chunk number 21: ################################################### iters(as) ################################################### ### chunk number 23: ################################################### par(mar = c(3, 4, 0.1, 0) + 0.1, ps = 9) screeplot(as, cex = 0.6, ylim = c(0, 0.08), axes = FALSE) mtext("Archetypes", side = 1, line = 2) axis(2, las = 2) box() ################################################### ### chunk number 25: ################################################### a7 <- bestModel(as[[7]]) par(mfrow = c(1, 2), mar = c(2, 2, 0, 0) + 0.1, ps = 9) plot(a7, toy, chull = chull(toy), xlim = c(0, 20), ylim = c(0, 20), cex = 0.6, xlab = "", ylab = "") plot(a7, toy, adata.show = TRUE, xlim = c(0, 20), ylim = c(0, 20), cex = 0.6, xlab = "", ylab = "") ################################################### ### chunk number 26: ################################################### set.seed(1986) gas <- stepArchetypes(data = toy, k = 1:10, family = archetypesFamily("ginv"), verbose = FALSE, nrep = 4) ################################################### ### chunk number 27: ################################################### rss(gas) ################################################### ### chunk number 29: ################################################### par(mfrow = c(1, 4), mar = c(0, 0, 0, 0) + 0.1, ps = 9) movieplot(gas[[9]][[3]], toy, xlim = c(0, 20), ylim = c(0, 20), cex = 0.6, axes = FALSE, postfn = function(iter) { box() text(1, 19, paste(iter + 1, ".", sep = ""), cex = 1) }) ################################################### ### chunk number 31: ################################################### ga7 <- bestModel(gas[[7]]) par(mfrow = c(1, 2), mar = c(2, 2, 0, 0) + 0.1, ps = 9) plot(ga7, toy, chull = chull(toy), xlim = c(0, 20), ylim = c(0, 20), cex = 0.6, xlab = "", ylab = "") plot(ga7, toy, adata.show = TRUE, xlim = c(0, 20), ylim = c(0, 20), cex = 0.6, xlab = "", ylab = "") ################################################### ### chunk number 32: ################################################### apply(alphas(ga7), 2, range) ################################################### ### chunk number 33: ################################################### data("skel") skel2 <- subset(skel, select = -Gender) ################################################### ### chunk number 35: ################################################### par(mar = c(1, 4, 0, 0) + 0.1, ps = 9) jd() ################################################### ### chunk number 37: ################################################### datacol <- rgb(178, 178, 178, maxColorValue = 255, alpha = round(255 * 0.2)) par(mar = c(5.5, 0.4, 0, 0.4) + 0.1, ps = 9) pcplot(skel2, las = 2, col = datacol) ################################################### ### chunk number 40: ################################################### set.seed(1981) as <- stepArchetypes(skel2, k = 1:15, verbose = FALSE) ################################################### ### chunk number 42: ################################################### par(mar = c(3, 4, 0.4, 0) + 0.1, ps = 9) screeplot(as, cex = 0.6, axes = FALSE) mtext("Archetypes", side = 1, line = 2) axis(2, las = 2) box() ################################################### ### chunk number 43: ################################################### a3 <- bestModel(as[[3]]) ################################################### ### chunk number 44: ################################################### t(atypes(a3)) ################################################### ### chunk number 46: ################################################### par(mar = c(5, 4, 0.4, 0) + 0.1, ps = 9) barplot(a3, skel2, percentage = TRUE, las = 2) ################################################### ### chunk number 48: ################################################### datacol <- c(rgb(0, 205, 0, maxColorValue = 255, alpha = round(255 * 0.2)), rgb(0, 0, 255, maxColorValue = 255, alpha=round(255 * 0.2))) par(mar = c(5.5, 0.4, 0, 0.4) + 0.1, ps = 9) pcplot(a3, skel2, las = 2, data.col = datacol[skel$Gender]) ################################################### ### chunk number 52: ################################################### library("vcd") ternaryplot(alphas(a3), dimnames = 1:3, cex = 0.3, col = datacol[skel$Gender], main = NULL, labels = "none", grid = FALSE) grid.text("1", x = 3, y = 3) ################################################### ### chunk number 54: ################################################### par(mar = c(1, 4, 0, 0) + 0.1, ps = 9) skeletonplot(atypes(a3), skel.height = 190)