plot.hclust: strange behaviour with "manufactured"
Andy: That's a great idea. And it's certainly part of the problem. I verified this by changing the type of the "merge" element of a valid hclust object to be double. As you suggest, it doesn't plot. What's interesting is that if I change it back to integer again, plot.hclust still gives an error. Moreover, the object.size of the "merge" component that was transformed integer to double to integer is different from the object.size of the original integer component. Is there something that I am missing about integer types? The original integer type was produced by the interal (C or Fortran) code, so maybe I am corrupting it in some way. An example below gives the details... ----------------------------------------------------------------------
library(mva) set.seed(103) x <- matrix(rnorm(5 * 2), ncol = 2) x.hc <- hclust(dist(x), method = "average") plot.hclust(x.hc) unlist(lapply(x.hc, storage.mode))
merge height order labels method call "integer" "double" "integer" "NULL" "character" "language" dist.method "character"
unlist(lapply(x.hc, object.size))
merge height order labels method call
152 60 52 0 44 324
dist.method
52
x.hc$merge <- as.double(x.hc$merge) plot.hclust(x.hc)
Error in plot.hclust(x.hc) : invalid dendrogram
unlist(lapply(x.hc,storage.mode))
merge height order labels method call "double" "double" "integer" "NULL" "character" "language" dist.method "character"
unlist(lapply(x.hc,object.size))
merge height order labels method call
92 60 52 0 44 324
dist.method
52
x.hc$merge <- as.integer(x.hc$merge) plot.hclust(x.hc)
Error in plot.hclust(x.hc) : invalid dendrogram
unlist(lapply(x.hc,storage.mode))
merge height order labels method call "integer" "double" "integer" "NULL" "character" "language" dist.method "character"
unlist(lapply(x.hc,object.size))
merge height order labels method call
60 60 52 0 44 324
dist.method
52
The problem seems to be that the original merge component is stored as int, but the source()'d version is not. Coercing that to int I think works. Cheers, Andy
-----Original Message----- From: Hugh Chipman [mailto:hachipma at icarus.math.uwaterloo.ca] Sent: Wednesday, February 20, 2002 1:32 PM To: r-help at stat.math.ethz.ch Cc: hachipma at icarus.math.uwaterloo.ca Subject: [R] plot.hclust: strange behaviour with "manufactured" hclust object I've been trying to get plot.hclust to work with a hclust object I created and have not had much success. It seems that there is some "hidden" characteristic of a hclust object that I can't see. This is most easily seen in the following example, where plot.hclust works on one object, but when this object is "dumped" and then re-read, plot.hclust no longer works. Is this a scoping problem? Script started on Wed Feb 20 13:17:37 2002 1>@icarus[101]% R R : Copyright 2002, The R Development Core Team Version 1.4.1 (2002-01-30) ......(stuff deleted)
set.seed(103) library(mva) x <- matrix(rnorm(5*2),ncol=2) x.hc <- hclust(dist(x),method='average') plot.hclust(x.hc)
# the above works
dump('x.hc')
source('dumpdata.R')
plot.hclust(x.hc)
Error in plot.hclust(x.hc) : invalid dendrogram input One hypothesis I had was that it might be something like the "call" object that wasn't correctly being re-created by the dump & source, but that doesn't seem to be it. Below, I remove everything except merge, order, and height, and plot.hclust still works on the original object and fails on the dump + source object.
x.hc <- hclust(dist(x),method='average')
x.hc$call <- NULL
x.hc$dist.method <- NULL
x.hc$method <- NULL
x.hc$labels <- NULL
plot.hclust(x.hc)
dump('x.hc')
source('dumpdata.R')
plot.hclust(x.hc)
Error in plot.hclust(x.hc) : invalid dendrogram input
str(x.hc)
List of 3
$ merge : num [1:4, 1:2] -2 -5 -1 -4 -3 1 2 3
$ height: num [1:4] 0.873 1.257 1.633 2.430
$ order : num [1:5] 4 1 5 2 3
- attr(*, "class")= chr "hclust"
Any help would be greatly appreciated!
Hugh Chipman
--
-- Hugh Chipman -- Associate Professor, Statistics &
Actuarial Science --
-- University of Waterloo, Ontario, Canada
--
--
--
-- Visiting Stanford Statistics Department, January-March
2002 --
-- (650) 725 6148 Fax (650)
725-8977 --
-- Department of Statistics, Sequoia Hall, 390 Serra Mall
--
-- Stanford University, Stanford, CA 94305-4065
--
-- http://www.stats.uwaterloo.ca/~hachipma/
hachipman at uwaterloo.ca --
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-.-.-.-.-.-.-
r-help mailing list -- Read
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To:
r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._._._._._._._._
-- Hugh Chipman -- Associate Professor, Statistics & Actuarial Science -- -- University of Waterloo, Ontario, Canada -- -- -- -- Visiting Stanford Statistics Department, January-March 2002 -- -- (650) 725 6148 Fax (650) 725-8977 -- -- Department of Statistics, Sequoia Hall, 390 Serra Mall -- -- Stanford University, Stanford, CA 94305-4065 -- -- http://www.stats.uwaterloo.ca/~hachipma/ hachipman at uwaterloo.ca -- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._