The R Project SVN R

Rev

Rev 73569 | Rev 80296 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 73569 Rev 76160
Line 1815... Line 1815...
1815
set.seed(46)
1815
set.seed(46)
1816
d <- dist(matrix(round(rnorm(n*p), digits = 2), n,p), "manhattan")
1816
d <- dist(matrix(round(rnorm(n*p), digits = 2), n,p), "manhattan")
1817
d[] <- d[] * sample(1 + (-4:4)/100, length(d), replace=TRUE)
1817
d[] <- d[] * sample(1 + (-4:4)/100, length(d), replace=TRUE)
1818
hc <- hclust(d, method = "median")
1818
hc <- hclust(d, method = "median")
1819
stopifnot(all.equal(hc$height[5:11],
1819
stopifnot(all.equal(hc$height[5:11],
-
 
1820
		    c(1.70595, 1.657675, 1.8909, 1.619973438, 
1820
                    c(1.69805, 1.75134375, 1.34036875, 1.47646406,
1821
                      1.548624609, 3.097474902, 6.097159351),
1821
                      3.21380039, 2.9653438476, 6.1418258), tolerance = 1e-9))
1822
                    tolerance = 1e-9))
1822
## Also ensure that hclust() remains fast:
1823
## Also ensure that hclust() remains fast:
1823
set.seed(1); nn <- 2000
1824
set.seed(1); nn <- 2000
1824
tm0 <- system.time(dst <- as.dist(matrix(runif(n = nn^2, min = 0, max = 1)^1.1, nn, nn)))
1825
tm0 <- system.time(dst <- as.dist(matrix(runif(n = nn^2, min = 0, max = 1)^1.1, nn, nn)))
1825
(tm <- system.time(hc <- hclust(dst, method="average")))
1826
(tm <- system.time(hc <- hclust(dst, method="average")))
1826
stopifnot(tm[1] <= tm0[1])
1827
stopifnot(tm[1] <= tm0[1])