Question

Using the code from : http://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Clustering/Hierarchical_Clustering

Here is how to generate a dendogram :

# import data
x <- read.table("data.txt")

# run AGNES
ag <- agnes (x, false, metric="euclidean", false, method ="single")

# print components of ag
print(ag)

# plot clusters
plot(ag, ask = FALSE, which.plots = NULL)

I'm receiving an error on

ag <- agnes (x, false, metric="euclidean", false, method ="single")

The error is :

Error in agnes(x, false, metric = "euclidean", false, method = "single") : 
  object 'false' not found

This implementation of agnes works but its generating numbered labels for the dendogram :

ag <- agnes (data, metric="euclidean")
# plot clusters
plot(ag, ask = FALSE, which.plots = NULL)

The dendogram :

enter image description here

The dendogram generated from http://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Clustering/Hierarchical_Clustering includes labels :

enter image description here Here is the data file :

,ba,fi,mi,vo,rm,to
ba,0,662,877,255,412,996
fi,662,0,295,468,268,400
mi,877,295,0,754,564,138
vo,255,468,754,0,219,869
rm,412,268,564,219,0,669
to,996,400,138,869,669,0

How can generate a labelled hierarchical cluster based on above data which is same as labelled dendogram above ?

Update :

After following @sgibb suggestion I used this :

ag <- agnes(data, FALSE, metric="euclidean", FALSE, method ="single")

# plot clusters
plot(ag, ask = FALSE, which.plots = NULL)

The dendogram being generated is now :

enter image description here

This is an incorrect structure. Maybe its beacuse the column names of my dataset are appearing as 1,2,3,4,5,6 and are not labelled, if so how can I modify the import statement ?

the dataset imported :

enter image description here

Was it helpful?

Solution

My problem was an extra comma in the dataset.

running help(read.table) and taking note of this section helped me solve the issue :

If there is a header and the first row contains one fewer field than the number of columns, the first column in the input is used for the row names. Otherwise if row.names is missing, the rows are numbered.

This works :

  1. import the data vai the r gui data to import :

    ba,fi,mi,vo,rm,to ba,0,662,877,255,412,996 fi,662,0,295,468,268,400 mi,877,295,0,754,564,138 vo,255,468,754,0,219,869 rm,412,268,564,219,0,669 to,996,400,138,869,669,0

  2. run the commands :

ag <- agnes(data, FALSE, metric="euclidean", FALSE, method ="single")

plot(ag, ask = FALSE, which.plots = NULL)

This generates this dendogram which looks correct :

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top