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,2,2,6,5,1,2,6,3,2,2,6,6,1,2,6,2,2,2,6,3,2,1,6,4,2,1,6,7,1,2,6,4,2,1,3,7,1,1,6,5,2,2,6,3,2,1,6,6,1,2,6,3,2,1,6,4,2,2,6,4,1,1,6,5,1,2,6,6,2,1,6,6,1,1,6,6,1,1,6,6,1,2,6,4,2,2,5,3,2,1,6,7,1,2,6,3,2,2,6,3,2,2,6,4,2,1,6,4,2,2,6,4,2,1,6,7,1,2,6,5,1,1,6,7,1,2,6,5,1,2,6,2,2,1,6,5,1,1,3,4,1,2,6,3,2,1,6,4,1,2,6,5,1,2,6,3,2,1,6,5,1,1,6,7,1,2,6,4,2,2,6,4,2,2,6,3,2,1,6,4,1,1,6,2,2,1,6,5,1,2,6,5,1,2,6,3,2,2,6,3,2,2,6,3,2,2,6,4,1,2,6,5,1,2,6,3,2,2,6,3,2,1,6,6,1,2,6,4,2,2,6,4,2,2,6,3,2,2,6,3,2,1,6,4,2,2,6,2,2,1,6,3,1,2,6,3,2,1,6,4,2,2,6,3,2,2,6,3,2,2,6,3,2,2,6,3,2,2,6,4,2,2,6,4,1,1,6,4,2,2,6,5,1,2,6,2,2,2,6,5,1,1,6,4,2,2,6,6,1,1,3,5,1,1,7,5,1,1,7,3,1,1,8,7,1,1,8,5,1,2,9,3,2,2,9,4,2,2,9,4,2,2,9,3,2,1,9,3,2,2,9,4,2,1,9,6,1,1,9,6,1,2,9,7,1,2,9,4,1,2,9,3,1,1,9,3,1,2,9,4,2,2,9,3,2,1,9,4,2,2,9,7,1,1,9,4,2,1,9,6,1,1,9,4,1,1,10,4,2),dim=c(4,226),dimnames=list(c('Family','Location','Age','Children'),1:226))
 y <- array(NA,dim=c(4,226),dimnames=list(c('Family','Location','Age','Children'),1:226))
 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 = 'centroid'
ylab = 'height'
xlab = 'cases'
main = 'Dendrogram'
par4 <- 'FALSE'
par3 <- 'FALSE'
par2 <- 'ALL'
par1 <- 'centroid'
#'GNU S' R Code compiled by R2WASP v. 1.2.327 (Sun, 16 Jul 2017 10:31:41 +0200)
#Author: root
#To cite this work: Wessa, P., (2017), Hierarchical Clustering (v1.0.5) in Free Statistics Software (v$_version), Office for Research Development and Education, URL https://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)
mysub <- paste('Method: ',par1)
postscript(file="/home/pw/wessanet/rcomp/tmp/1lyd81506898724.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()
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="/home/pw/wessanet/rcomp/tmp/25skn1506898724.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)
}

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="/home/pw/wessanet/rcomp/tmp/32o1d1506898724.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="/home/pw/wessanet/rcomp/tmp/4nbw31506898724.tab") 
}

try(system("convert /home/pw/wessanet/rcomp/tmp/1lyd81506898724.ps /home/pw/wessanet/rcomp/tmp/1lyd81506898724.png",intern=TRUE))
try(system("convert /home/pw/wessanet/rcomp/tmp/25skn1506898724.ps /home/pw/wessanet/rcomp/tmp/25skn1506898724.png",intern=TRUE))
