R version 2.13.0 (2011-04-13) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-pc-linux-gnu (32-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > x <- array(list(99.2,96.7,101.0,99.0,98.1,100.1,100.0,100.0,100.0,111.6,104.9,90.6,122.2,104.9,86.5,117.6,109.5,89.7,121.1,110.8,90.6,136.0,112.3,82.8,154.2,109.3,70.1,153.6,105.3,65.4,158.5,101.7,61.3,140.6,95.4,62.5,136.2,96.4,63.6,168.0,97.6,52.6,154.3,102.4,59.7,149.0,101.6,59.5,165.5,103.8,61.3),dim=c(3,17),dimnames=list(c('A','B','C'),1:17)) > y <- array(NA,dim=c(3,17),dimnames=list(c('A','B','C'),1:17)) > for (i in 1:dim(x)[1]) + { + for (j in 1:dim(x)[2]) + { + y[i,j] <- as.numeric(x[i,j]) + } + } > par4 = 'FALSE' > par3 = 'FALSE' > par2 = 'ALL' > par1 = 'ward' > ylab = 'height' > xlab = 'cases' > main = 'Dendrogram' > par4 <- 'FALSE' > par3 <- 'FALSE' > par2 <- 'ALL' > par1 <- 'ward' > #'GNU S' R Code compiled by R2WASP v. 1.2.291 () > #Author: root > #To cite this work: Wessa, P., (2012), Hierarchical Clustering (v1.0.3) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_hierarchicalclustering.wasp/ > #Source of accompanying publication: Office for Research, Development, and Education > # > par3 <- as.logical(par3) > par4 <- as.logical(par4) > if (par3 == 'TRUE'){ + dum = xlab + xlab = ylab + ylab = dum + } > x <- t(y) > hc <- hclust(dist(x),method=par1) > d <- as.dendrogram(hc) > str(d) --[dendrogram w/ 2 branches and 17 members at h = 307] |--[dendrogram w/ 2 branches and 9 members at h = 47.2] | |--[dendrogram w/ 2 branches and 2 members at h = 4.64] | | |--leaf "12" | | `--leaf "13" | `--[dendrogram w/ 2 branches and 7 members at h = 27.9] | |--[dendrogram w/ 2 branches and 2 members at h = 11] | | |--leaf "14" | | `--leaf "17" | `--[dendrogram w/ 2 branches and 5 members at h = 15.5] | |--[dendrogram w/ 2 branches and 2 members at h = 6.2] | | |--leaf "9" | | `--leaf "10" | `--[dendrogram w/ 2 branches and 3 members at h = 8.51] | |--leaf "16" | `--[dendrogram w/ 2 branches and 2 members at h = 4.55] | |--leaf "11" | `--leaf "15" `--[dendrogram w/ 2 branches and 8 members at h = 81.5] |--[dendrogram w/ 2 branches and 3 members at h = 3.23] | |--leaf "3" | `--[dendrogram w/ 2 branches and 2 members at h = 1.68] | |--leaf "1" | `--leaf "2" `--[dendrogram w/ 2 branches and 5 members at h = 26.9] |--leaf "8" `--[dendrogram w/ 2 branches and 4 members at h = 12] |--leaf "4" `--[dendrogram w/ 2 branches and 3 members at h = 8.4] |--leaf "5" `--[dendrogram w/ 2 branches and 2 members at h = 3.84] |--leaf "6" `--leaf "7" > mysub <- paste('Method: ',par1) > postscript(file="/var/wessaorg/rcomp/tmp/1sm2h1335723922.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > if (par4 == 'TRUE'){ + plot(d,main=main,ylab=ylab,xlab=xlab,horiz=par3, nodePar=list(pch = c(1,NA), cex=0.8, lab.cex = 0.8),type='t',center=T, sub=mysub) + } else { + plot(d,main=main,ylab=ylab,xlab=xlab,horiz=par3, nodePar=list(pch = c(1,NA), cex=0.8, lab.cex = 0.8), sub=mysub) + } > dev.off() null device 1 > if (par2 != 'ALL'){ + if (par3 == 'TRUE'){ + ylab = 'cluster' + } else { + xlab = 'cluster' + } + par2 <- as.numeric(par2) + memb <- cutree(hc, k = par2) + cent <- NULL + for(k in 1:par2){ + cent <- rbind(cent, colMeans(x[memb == k, , drop = FALSE])) + } + hc1 <- hclust(dist(cent),method=par1, members = table(memb)) + de <- as.dendrogram(hc1) + postscript(file="/var/wessaorg/rcomp/tmp/2ni0n1335723922.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) + if (par4 == 'TRUE'){ + plot(de,main=main,ylab=ylab,xlab=xlab,horiz=par3, nodePar=list(pch = c(1,NA), cex=0.8, lab.cex = 0.8),type='t',center=T, sub=mysub) + } else { + plot(de,main=main,ylab=ylab,xlab=xlab,horiz=par3, nodePar=list(pch = c(1,NA), cex=0.8, lab.cex = 0.8), sub=mysub) + } + dev.off() + str(de) + } > > #Note: the /var/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/rcomp/createtable") > > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Summary of Dendrogram',2,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Label',header=TRUE) > a<-table.element(a,'Height',header=TRUE) > a<-table.row.end(a) > num <- length(x[,1])-1 > for (i in 1:num) + { + a<-table.row.start(a) + a<-table.element(a,hc$labels[i]) + a<-table.element(a,hc$height[i]) + a<-table.row.end(a) + } > a<-table.end(a) > table.save(a,file="/var/wessaorg/rcomp/tmp/350801335723922.tab") > if (par2 != 'ALL'){ + a<-table.start() + a<-table.row.start(a) + a<-table.element(a,'Summary of Cut Dendrogram',2,TRUE) + a<-table.row.end(a) + a<-table.row.start(a) + a<-table.element(a,'Label',header=TRUE) + a<-table.element(a,'Height',header=TRUE) + a<-table.row.end(a) + num <- par2-1 + for (i in 1:num) + { + a<-table.row.start(a) + a<-table.element(a,i) + a<-table.element(a,hc1$height[i]) + a<-table.row.end(a) + } + a<-table.end(a) + table.save(a,file="/var/wessaorg/rcomp/tmp/4tpu11335723922.tab") + } > > try(system("convert tmp/1sm2h1335723922.ps tmp/1sm2h1335723922.png",intern=TRUE)) character(0) > try(system("convert tmp/2ni0n1335723922.ps tmp/2ni0n1335723922.png",intern=TRUE)) convert: unable to open image `tmp/2ni0n1335723922.ps': No such file or directory @ blob.c/OpenBlob/2480. convert: missing an image filename `tmp/2ni0n1335723922.png' @ convert.c/ConvertImageCommand/2838. character(0) Warning message: running command 'convert tmp/2ni0n1335723922.ps tmp/2ni0n1335723922.png' had status 1 > > > proc.time() user system elapsed 0.521 0.103 0.619