R version 2.12.0 (2010-10-15) Copyright (C) 2010 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. > par9 = 'variables' > par8 = 'CSUQ' > par7 = 'all' > par6 = 'all' > par5 = 'female' > par4 = 'FALSE' > par3 = 'TRUE' > par2 = '10' > par1 = 'ward' > ylab = 'height' > xlab = 'cases or variables' > main = 'Dendrogram' > par9 <- 'variables' > par8 <- 'CSUQ' > par7 <- 'all' > par6 <- 'all' > par5 <- 'female' > par4 <- 'FALSE' > par3 <- 'TRUE' > par2 <- '10' > 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.4) 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 > # > x <- as.data.frame(read.table(file='http://www.wessa.net/download/utaut.csv',sep=',',header=T)) > x$U25 <- 6-x$U25 > if(par5 == 'female') x <- x[x$Gender==0,] > if(par5 == 'male') x <- x[x$Gender==1,] > if(par6 == 'prep') x <- x[x$Pop==1,] > if(par6 == 'bachelor') x <- x[x$Pop==0,] > if(par7 != 'all') { + x <- x[x$Year==as.numeric(par7),] + } > cAc <- with(x,cbind( A1, A2, A3, A4, A5, A6, A7, A8, A9,A10)) > cAs <- with(x,cbind(A11,A12,A13,A14,A15,A16,A17,A18,A19,A20)) > cA <- cbind(cAc,cAs) > cCa <- with(x,cbind(C1,C3,C5,C7, C9,C11,C13,C15,C17,C19,C21,C23,C25,C27,C29,C31,C33,C35,C37,C39,C41,C43,C45,C47)) > cCp <- with(x,cbind(C2,C4,C6,C8,C10,C12,C14,C16,C18,C20,C22,C24,C26,C28,C30,C32,C34,C36,C38,C40,C42,C44,C46,C48)) > cC <- cbind(cCa,cCp) > cU <- with(x,cbind(U1,U2,U3,U4,U5,U6,U7,U8,U9,U10,U11,U12,U13,U14,U15,U16,U17,U18,U19,U20,U21,U22,U23,U24,U25,U26,U27,U28,U29,U30,U31,U32,U33)) > cE <- with(x,cbind(BC,NNZFG,MRT,AFL,LPM,LPC,W,WPA)) > cX <- with(x,cbind(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13,X14,X15,X16,X17,X18)) > if (par8=='ATTLES connected') x <- cAc > if (par8=='ATTLES separate') x <- cAs > if (par8=='ATTLES all') x <- cA > if (par8=='COLLES actuals') x <- cCa > if (par8=='COLLES preferred') x <- cCp > if (par8=='COLLES all') x <- cC > if (par8=='CSUQ') x <- cU > if (par8=='Learning Activities') x <- cE > if (par8=='Exam Items') x <- cX > ncol <- length(x[1,]) > for (jjj in 1:ncol) { + x <- x[!is.na(x[,jjj]),] + } > par3 <- as.logical(par3) > par4 <- as.logical(par4) > if (par3 == TRUE){ + dum = xlab + xlab = ylab + ylab = dum + } > if (par9=='variables') { + x <- t(x) + } else { + ncol <- length(x[1,]) + colnames(x) <- 1:ncol + } > hc <- hclust(dist(x),method=par1) > d <- as.dendrogram(hc) > str(d) --[dendrogram w/ 2 branches and 33 members at h = 47.9] |--[dendrogram w/ 2 branches and 3 members at h = 19.9] | |--leaf "U25" | `--[dendrogram w/ 2 branches and 2 members at h = 14.9] | |--leaf "U10" | `--leaf "U11" `--[dendrogram w/ 2 branches and 30 members at h = 31.0] |--[dendrogram w/ 2 branches and 6 members at h = 18.8] | |--[dendrogram w/ 2 branches and 3 members at h = 13.5] | | |--leaf "U28" | | `--[dendrogram w/ 2 branches and 2 members at h = 12.5] | | |--leaf "U21" | | `--leaf "U22" | `--[dendrogram w/ 2 branches and 3 members at h = 14.0] | |--leaf "U29" | `--[dendrogram w/ 2 branches and 2 members at h = 10.9] | |--leaf "U23" | `--leaf "U24" `--[dendrogram w/ 2 branches and 24 members at h = 28.5] |--[dendrogram w/ 2 branches and 6 members at h = 18.3] | |--[dendrogram w/ 2 branches and 2 members at h = 8.3] | | |--leaf "U17" | | `--leaf "U18" | `--[dendrogram w/ 2 branches and 4 members at h = 15.0] | |--leaf "U12" | `--[dendrogram w/ 2 branches and 3 members at h = 14.4] | |--leaf "U14" | `--[dendrogram w/ 2 branches and 2 members at h = 13] | |--leaf "U13" | `--leaf "U16" `--[dendrogram w/ 2 branches and 18 members at h = 25.3] |--[dendrogram w/ 2 branches and 14 members at h = 18.9] | |--[dendrogram w/ 2 branches and 10 members at h = 14.3] | | |--[dendrogram w/ 2 branches and 2 members at h = 10.6] | | | |--leaf "U5" | | | `--leaf "U9" | | `--[dendrogram w/ 2 branches and 8 members at h = 14.1] | | |--[dendrogram w/ 2 branches and 3 members at h = 12.0] | | | |--leaf "U15" | | | `--[dendrogram w/ 2 branches and 2 members at h = 9.95] | | | |--leaf "U30" | | | `--leaf "U31" | | `--[dendrogram w/ 2 branches and 5 members at h = 13.2] | | |--leaf "U19" | | `--[dendrogram w/ 2 branches and 4 members at h = 12.3] | | |--leaf "U7" | | `--[dendrogram w/ 2 branches and 3 members at h = 9.6] | | |--leaf "U20" | | `--[dendrogram w/ 2 branches and 2 members at h = 8.49] | | |--leaf "U4" | | `--leaf "U6" | `--[dendrogram w/ 2 branches and 4 members at h = 18.4] | |--leaf "U8" | `--[dendrogram w/ 2 branches and 3 members at h = 10.5] | |--leaf "U3" | `--[dendrogram w/ 2 branches and 2 members at h = 3.46] | |--leaf "U1" | `--leaf "U2" `--[dendrogram w/ 2 branches and 4 members at h = 19.1] |--[dendrogram w/ 2 branches and 2 members at h = 11.4] | |--leaf "U27" | `--leaf "U33" `--[dendrogram w/ 2 branches and 2 members at h = 15.7] |--leaf "U26" `--leaf "U32" > mysub <- paste('Method: ',par1) > postscript(file="/var/www/rcomp/tmp/1pkrs1335699810.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/www/rcomp/tmp/2pxjk1335699810.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) + } --[dendrogram w/ 2 branches and 10 members at h = 28.8] |--[dendrogram w/ 2 branches and 8 members at h = 15.9] | |--leaf 3 | `--[dendrogram w/ 2 branches and 7 members at h = 14.7] | |--leaf 10 | `--[dendrogram w/ 2 branches and 6 members at h = 13.3] | |--leaf 6 | `--[dendrogram w/ 2 branches and 5 members at h = 12.2] | |--leaf 9 | `--[dendrogram w/ 2 branches and 4 members at h = 10.5] | |--leaf 7 | `--[dendrogram w/ 2 branches and 3 members at h = 9.37] | |--leaf 5 | `--[dendrogram w/ 2 branches and 2 members at h = 7.47] | |--leaf 1 | `--leaf 2 `--[dendrogram w/ 2 branches and 2 members at h = 17.1] |--leaf 4 `--leaf 8 > > #Note: the /var/www/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/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/www/rcomp/tmp/3if361335699810.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/www/rcomp/tmp/4xyou1335699810.tab") + } > > try(system("convert tmp/1pkrs1335699810.ps tmp/1pkrs1335699810.png",intern=TRUE)) character(0) > try(system("convert tmp/2pxjk1335699810.ps tmp/2pxjk1335699810.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.840 0.380 2.161