### R code from vignette source '/home/trusch/svn/egmds/paper/JSS/jss5517.Rnw' ################################################### ### code chunk number 1: jss5517.Rnw:42-43 ################################################### options(prompt="R> ", continue="+ ", width = 70, useFancyQuotes = FALSE) ################################################### ### code chunk number 2: pkgs ################################################### library("smacofx") ################################################### ### code chunk number 3: getkolldata ################################################### data("koller") dis <- dist(t(koller)) ################################################### ### code chunk number 4: initmods ################################################### mds0 <- mds(dis) mds0i <- mds(dis, type = "interval") mds0o <- mds(dis, type = "ordinal") ################################################### ### FIGURE 1 code chunk number 5: initplots ################################################### cg <- "grey30" olist <- list(mds0, mds0i, mds0o) par(mai = c(0.27, 0.27, 0.4, 0)) alignplot(olist, mds0$conf, mains = c("ratio MDS", "interval MDS", "ordinal MDS"), label.conf = list(pos = 5, col = cg), xlab = "", ylab = "", asp = 1) ################################################### ### code chunk number 7: sammonEx2 ################################################### sam <- sammonmap(dis, type = "interval") ################################################### ### code chunk number 8: samp (eval = FALSE) ################################################### ## sam ################################################### ### code chunk number 9: sammonEx2 ################################################### els <- elscal(dis, type = "ratio") ################################################### ### code chunk number 10: sammonEx2p (eval = FALSE) ################################################### ## els ################################################### ### code chunk number 11: alscalEx2 ################################################### als <- alscal(dis, type = "ratio") ################################################### ### code chunk number 12: alscalEx2p (eval = FALSE) ################################################### ## als ################################################### ### code chunk number 13: multscalEx2 ################################################### ms <- multiscale(dis, type = "ratio") ################################################### ### code chunk number 14: multscalEx2p (eval = FALSE) ################################################### ## ms ################################################### ### Figure 2 code chunk number 15: sammontomult ################################################### twobytwo <- matrix(1:4, ncol = 2, nrow = 2, byrow = TRUE) olist2 <- list(sam, els, als, ms) par(mai = c(0.3, 0.4, 0.4, 0)) alignplot(olist2, mds0$conf, mains = c("interval Sammon mapping", "ratio elastic scaling", "ratio ALSCAL", "ratio MULTISCALE"), layoutmat = twobytwo, label.conf = list(pos = 5, col = cg), xlab = "", ylab = "", asp = 1) ################################################### ### code chunk number 17: postMdsEx2 ################################################### pst <- postmds(dis, kappa = 0.35, lambda = 1.2, nu = -0.5, weightmat = dis) rpst <- rpostmds(dis, expo = 1.5, nu = -1.5, weightmat = dis) apst <- apostmds(dis, kappa = 3, lambda = 0.8, nu = -0.5) ################################################### ### code chunk number 18: postMdsEx2p (eval = FALSE) ################################################### ## pst ## rpst ## apst ################################################### ### code chunk number 19: rstressEx2 ################################################### rst <- rstressmds(dis, r = 0.6, type = "ordinal") ################################################### ### code chunk number 20: rstressEx2p (eval = FALSE) ################################################### ## rst ################################################### ### FIGURE 3 code chunk number 21: posttorstress ################################################### olist3 <- list(pst, rpst, apst, rst) par(mai = c(0.3, 0.4, 0.4, 0)) alignplot(olist3, mds0$conf, mains = c("ratio POST-MDS", "ratio restricted POST-MDS", "ratio approx. POST-MDS", "ordinal r-stress MDS"), layoutmat = twobytwo, label.conf = list(pos = 5, col = cg), xlab = "", ylab = "", asp = 1) ################################################### ### code chunk number 23: lmdsEx2 ################################################### lms <- lmds(dis, k = 5, tau = 0.5) ################################################### ### code chunk number 24: lmdsEx2p (eval = FALSE) ################################################### ## lms ################################################### ### code chunk number 25: bcmdsEx ################################################### bcm <- bcmds(dis, mu = 3, lambda = 0.7, rho = -1.5) ################################################### ### code chunk number 26: bcmdsExp (eval = FALSE) ################################################### ## bcm ################################################### ### code chunk number 27: clcaMdsEx2 ################################################### set.seed(1) clcares <- clca(dis, lambda0 = 1, alpha0 = 1) cldares <- clda(dis, lambda0 = 1, alpha0 = 1, k = 5) ################################################### ### code chunk number 28: clcaMdsEx2p (eval = FALSE) ################################################### ## clcares ## cldares ################################################### ### FIGURE 4 code chunk number 29: lmstoclda ################################################### olist4 <- list(lms, bcm, clcares, cldares) par(mai = c(0.43, 0.4, 0.4, 0)) alignplot(olist4, mds0$conf, mains = c("ratio LMDS", "ratio Box-Cox MDS", "CLCA", "CLDA"), layoutmat = twobytwo, label.conf = list(pos = 5, col = cg), xlab = "", ylab = "", asp = 1) ################################################### ### code chunk number 31: sparseMdsEx2 ################################################### smdsres <- eclca(dis, tau = 0.2, type = "interval") spmdsres <- eclpca(dis, kappa = 3, lambda = 1.5, tau = 0.025) ################################################### ### code chunk number 32: sparseMdsEx2p (eval = FALSE) ################################################### ## smdsres ## spmdsres ################################################### ### code chunk number 33: spmddaEx2 ################################################### sddares <- eclda(dis, k = 5, tau = 0.3) spmddares <- eclpda(dis, k = 5, tau = 0.05, kappa = 2, lambda = 1.5, nu = -1.5, type = "interval") ################################################### ### code chunk number 34: spmddaEx2p (eval = FALSE) ################################################### ## sddares ## spmddares ################################################### ### FIGURE 5 code chunk number 35: sparsies ################################################### olist5 <- list(smdsres, spmdsres, sddares, spmddares) par(mai = c(0.3, 0.4, 0.4, 0)) alignplot(olist5, mds0$conf, mains = c("interval eCLCA", "ratio eCLPCA", "ratio eCLDA", "interval eCLPDA"), layoutmat = twobytwo, label.conf = list(pos = 5, col = cg), xlab = "", ylab = "", asp = 1) ################################################### ### code chunk number 37: som (eval = FALSE) ################################################### ## so_eclpca(delta, lambda, kappa, tau, nu, type, epochs, weightmat) ## so_eclca(delta, tau, type, epochs, weightmat) ## so_eclpda(delta, k, epsilon, lambda, kappa, tau, nu, type, epochs, ## weightmat) ## so_eclda(delta, k, epsilon, tau, type, epochs, weightmat) ################################################### ### FIGURE 6 code chunk number 38: pstplots ################################################### op <- par(no.readonly = TRUE) par(mfrow = c(1, 2)) plot(pst, plot.type = "Shepard") plot(pst, plot.type = "transplot") par(op) ################################################### ### code chunk number 40: jack (eval = FALSE) ################################################### ## jk1 <- jackmds(sddares) ## plot(jk1) ################################################### ### code chunk number 41: bootEx (eval = FALSE) ################################################### ## bs1 <- bootmds(sddares, data = koller, method.dat = "euclidean") ## plot(bs1) ################################################### ### code chunk number 42: permtestEx (eval = FALSE) ################################################### ## permtest(sddares) ################################################### ### code chunk number 43: bcmms (eval = FALSE) ################################################### ## ms1 <- multistart(bcm) ################################################### ### code chunk number 44: corpsepaintload ################################################### data("corpsepaint") ################################################### ### FIGURE 7 code chunk number 45: corpseplot ################################################### par(mfrow = c(8, 4), mai = c(0, 0.01, 0.2, 0.01)) for(i in 1:ncol(corpsepaint)) { p1 <- matrix(corpsepaint[, i], ncol = 90, nrow = 90, byrow = FALSE) image(p1, col = gray.colors(256), main = colnames(corpsepaint)[i], axes = FALSE) } par(op) ################################################### ### code chunk number 47: distancemat ################################################### disc <- as.matrix(dist(t(corpsepaint), method = "manhattan")) ################################################### ### code chunk number 48: cp-mds ################################################### set.seed(0208) mds0c <- mds(disc, eps = 1e-8) clcaresc <- clca(disc, lambda0 = 1, alpha0 = 1) msc <- multiscale(disc, acc = 1e-8) alsc <- alscal(disc, acc = 1e-8, itmax = 50000) lmsc <- lmds(disc, k = 5, tau = 0.5, acc = 1e-8, itmax = 50000) elsc <- elscal(disc, acc = 1e-8, itmax = 50000) samc <- sammonmap(disc, type = "interval", acc = 1e-8, itmax = 50000) rstc <- rstressMin(disc, r = 0.75, type = "ordinal", acc = 1e-8, itmax = 50000) bcmc <- bcmds(disc, mu = 3, lambda = 0.7, rho = -1.5, acc = 1e-8, itmax = 50000) rpstc <- rpostmds(disc, expo = 3, nu = -1.5, weightmat = disc, acc = 1e-8, itmax = 50000) pstc <- postmds(disc, kappa = 0.3, lambda = 0.8, nu = -0.5, weightmat = disc, acc = 1e-8, itmax = 50000) smdsresc <- eCLCA(disc, tau = 0.15, type = "interval", acc = 1e-8, itmax = 50000) sddaresc <- eCLDA(disc, k = 5, tau = 0.1, acc = 1e-8, itmax = 50000) spmdsresc <- eCLPCA(disc, kappa = 2.5, lambda = 1.5, tau = 0.05, itmax = 50000, acc = 1e-8) spmddaresc <- eCLPDA(disc, k = 5, tau = 0.3, kappa = 3, lambda = 1.5, nu = -1.5, type = "interval", itmax = 50000, acc = 1e-8) ################################################### ### FIGURE 8 code chunk number 49: mdsmodels ################################################### lt <- matrix(1:15, nrow = 5, ncol = 3) cplist <- list(mds0c, clcaresc, msc, alsc, lmsc, elsc, samc, rstc, bcmc, rpstc, pstc, smdsresc, sddaresc, spmdsresc, spmddaresc) mains <- c("ratio MDS", "CLCA", "ratio MULTISCALE", "ratio ALSCAL", "ratio LMDS", "ratio elastic scaling", "interval Sammon mapping", "ordinal r-stress MDS", "ratio Box-Cox MDS", "ratio restricted POST-MDS", "ratio POST-MDS", "interval eCLCA", "ratio eCLDA", "ratio eCLPCA", "interval eCLPDA") par(mai = c(0.27, 0.27, 0.4, 0)) alignplot(cplist, mds0c$conf, mains = mains, layoutmat = lt, label.conf = list(pos = 5, col = cg), xlab = "", ylab = "", asp = 1) ################################################### ### code chunk number 51: printfour ################################################### rstc pstc spmddaresc bcmc ################################################### ### code chunk number 52: picplot ################################################### library("TeachingDemos") plot_cpmds <- function(mdsc, inches = 0.3, main = "MDS", xlab = "", ylab = "") { plot(mdsc, type = "n", main = main, asp = 1, xlab = xlab, ylab = ylab) for(i in 1:dim(mdsc)[1]) { r <- array(matrix(rev(corpsepaint[, i]), 90, 90, byrow = TRUE), c(90, 90, 3)) my.symbols(mdsc[i, 1], mdsc[i, 2], symb = ms.image, MoreArgs = list(img = r), inches = inches, symb.plots = TRUE, add = TRUE) } } ################################################### ### code chunk number 53: procadjust ################################################### pstc2 <- pstc$conf bcmc2 <- Procrustes(pstc$conf, bcmc$conf)$Yhat rstc2 <- Procrustes(pstc$conf, rstc$conf)$Yhat spmddaresc2 <- Procrustes(pstc$conf, spmddaresc$conf)$Yhat ################################################### ### FIGURE 9 code chunk number 54: fourex ################################################### par(mfrow = c(2, 2), mai = c(0.3, 0.3, 0.4, 0)) plot_cpmds(pstc2, inches = 0.3, main = "ratio POST-MDS") plot_cpmds(rstc2, inches = 0.3, main = "ordinal r-Stress MDS") plot_cpmds(spmddaresc2, inches = 0.3, main = "interval eCLPDA") plot_cpmds(bcmc2, inches = 0.3, main = "ratio Box-Cox MDS") par(op) ################################################### ### code chunk number 56: permtest2 ################################################### set.seed(666) pte <- permtest(spmddaresc, nrep = 100) ################################################### ### code chunk number 57: permtest2p ################################################### pte ################################################### ### code chunk number 58: jackmds ################################################### jk <- jackmds(pstc) ################################################### ### code chunk number 59: jackmdsp ################################################### jk ################################################### ### code chunk number 60: bsmds ################################################### bs <- bootmds(bcmc, corpsepaint, "manhattan") ################################################### ### code chunk number 61: bsmdsp ################################################### bs ################################################### ### FIGURE 10 code chunk number 62: resampfigs ################################################### par(mfrow = c(1, 2)) plot(jk) plot(bs) par(op) ################################################### ### code chunk number 65: trveness ################################################### prt.mean <- data.frame(kvltness = c(4.0, 4.8, 5.8, 5.8, 2.6, 3.0, 3.6, 3.2, 4.6, 5.4, 4.6, 1.2, 1.6, 3.2, 4.0, 3.4, 6.0, 2.8, 2.0, 5.8, 2.2, 2.4, 1.8, 3.2, 5.8, 5.4, 4.8, 4.6, 3.4, 2.0, 5.4, 0.4), row.names = paste0("F", 1:32)) bi1 <- biplotmds(rstc, extvar = prt.mean) ################################################### ### code chunk number 66: localopt3 ################################################### rpst2 <- rpostmds(disc, expo = 3, nu = -1.5, weightmat = disc, init = bcmc$conf, itmax = 1) round(c("Torgerson Start" = rpstc$stress, "BC-MDS Start" = rpst2$stress), 3) ################################################### ### code chunk number 67: localopt2 ################################################### set.seed(666) cl1 <- replicate(47, matrix(runif(2 * 32, min = -5, max = 5), ncol = 2), simplify = FALSE) cl1 <- c(list(bcmc$conf), list(rpstc$conf), cl1) ic1 <- icExploreGen(rpstc, conflist = cl1, verbose = FALSE) ################################################### ### FIGURE 11 code chunk number 68: poserratingplt ################################################### par(mfrow = c(1, 2)) plot(bi1, vecscale = 0.2, label.conf = list(pos = 5)) plot(ic1, cex.scale = 3) par(op) ################################################### ### code chunk number 70: multistart2 ################################################### set.seed(666) rpst3 <- rpostmds(disc, expo = 3, nu = -1.5, weightmat = disc, init = bcmc$conf) m2 <- multistart(rpst3,verbose=FALSE) ################################################### ### code chunk number 71: ms2p ################################################### m2$best