### # # Euro Distances data(eurodist) ### # # Layout in 1-d via PCA loc <- cmdscale(eurodist, k=1) x <- loc[,1] plot(x, rep(0,length(loc[,1])), ylim=c(0,1), pch="+", xlab="", ylab="", main="cmdscale(eurodist)") text(x, (1:21)/21, names(eurodist), cex=0.8) ### # # Layout in 2-d via PCA loc <- cmdscale(eurodist, k=2) x <- loc[,1] y <- (-loc[,2]) plot(x, y, pch="+", xlab="", ylab="", main="cmdscale(eurodist)") text(x, y+100, names(eurodist), cex=0.8) ### # # Layout the Euro Cities under stress, i.e. 1-d (with random start config for non-metric) par(mfrow=c(1,3)) plot(rep(0,21), cmdscale(eurodist, k=1), type="n") text(rep(0,21), cmdscale(eurodist, k=1), names(eurodist)) plot(rep(0,21), sammon(eurodist, k=1)$points, type="n") text(rep(0,21), sammon(eurodist, k=1)$points, names(eurodist)) plot(rep(0,21), isoMDS(eurodist, d<-matrix(runif(21,-2000,2000),21,1), k=1)$points, type="n") text(rep(0,21), isoMDS(eurodist, d, k=1)$points, names(eurodist)) ### # # Remaining Stress for Crabs Data in 1:7 Dimensions stress <- 1:7 crd <- dist(normdf(crabs[4:8])) for ( i in 1:7 ) stress[i] <- sammon(crd, k=i)$stress plot(stress, type="l", xlab="Dimensionen") #### # # Find a layout for the crabs data from a random start # (finds the four groups at a minimal stress value of 0.327986!!! - runs long!) plot(as.data.frame(isoMDS(crd, matrix(runif(600), 200, 3), k=3, maxit=200)$points), col=sp-1+2*(sex-1)+1) ### # # Compare fitted an original distances in 2-d and label them fit <- dist(sammon(eurodist, k=2)$points) plot(eurodist, fit, pch="+") n1 <- length(names(eurodist)) fit.mat <- as.matrix(fit) for( i in 1:n1) for( j in 1:n1) if( i<=j ) fit.mat[i,j] <- 0 fit.df <- as.data.frame(as.table(fit.mat)) dist.mat <- as.matrix(eurodist) for( i in 1:n1) for( j in 1:n1) if( i<=j ) dist.mat[i,j] <- 0 dist.df <- as.data.frame(as.table(dist.mat)) diffs <- abs(dist.df$Freq - fit.df$Freq) text(dist.df$Freq[diffs>500], fit.df$Freq[diffs>500]+75, paste(fit.df$Var1[diffs>500], "-", fit.df$Var2[diffs>500])) ### # # A layout for the olive oil data in 2-d, colored for the 3 Regions ofit <- sammon(dist(olives[4:11]), k=2)$points plot(ofit, col=olives[,2])