# NOT RUN {
data(demo.knowns)
data(demo.samples)
demo.knowns <- group.knowns(demo.knowns, cut.height=2.5)
plot(demo.knowns)
## Increasing cut.height makes groups more inclusive:
plot(group.knowns(demo.knowns, cut.height=100))
res <- TRAMP(demo.samples, demo.knowns)
m1.ungrouped <- summary(res)
m1.grouped <- summary(res, group=TRUE)
ncol(m1.grouped) # 94 groups
res2 <- group.knowns(res, cut.height=100)
m2.ungrouped <- summary(res2)
m2.grouped <- summary(res2, group=TRUE)
ncol(m2.grouped) # Now only 38 groups
## group.knowns results in the same distance matrix as produced by
## TRAMP, therefore using the same method (e.g. method="maximum") is
## important. The example below shows how the matrix produced by
## dist(summary(x)) (as calculated by group.knowns) is the same as that
## produced by TRAMP:
f <- function(x, method="maximum") {
## Create a pseudo-samples object from our knowns
y <- x
y$data$height <- 1
names(y$info)[names(y$info) == "knowns.pk"] <- "sample.pk"
names(y$data)[names(y$data) == "knowns.fk"] <- "sample.fk"
class(y) <- "TRAMPsamples"
## Run TRAMP, clean up and return
## (If method != "maximum", rescale the error to match that
## generated by dist()).
z <- TRAMP(y, x, method=method)
if ( method != "maximum" ) z$error <- z$error * z$n
names(dimnames(z$error)) <- NULL
z
}
g <- function(x, method="maximum")
as.matrix(dist(summary(x), method=method))
all.equal(f(demo.knowns, "maximum")$error, g(demo.knowns, "maximum"))
all.equal(f(demo.knowns, "euclidian")$error, g(demo.knowns, "euclidian"))
all.equal(f(demo.knowns, "manhattan")$error, g(demo.knowns, "manhattan"))
## However, TRAMP is over 100 times slower in this special case.
system.time(f(demo.knowns))
system.time(g(demo.knowns))
# }
Run the code above in your browser using DataLab