# # ### Can you have groups of different sizes *and* they have the same Sums-of-Squares? # sos <- function(x){sum((x - mean(x))^2)} pop <- seq(-5, 5, by = 1) pop <- sort(c(pop, rep(0, 21))); pop hist(pop) summary(pop) sos(pop) length(pop) result <- 1 all.results <- as.vector(0) b.out <- 0 z <- 0 best.so.far <- as.vector(0) g.id <- c(rep("x1",10),rep("x2",15)) data.results <- as.list(0) system.time( while(result != 0){ b.out <- b.out + 1 x1 <- sort(sample(pop, 10, replace = F)) x2 <- sort(sample(pop, 15, replace = F)) dat <- data.frame(g.id, c(x1,x2)) data.results[[b.out]] <- dat; rm(dat) result <- abs(sos(x1) - sos(x2)) print(rep(b.out,10)) print(x1); print(x2) print("abs(sos(x1) - sos(x2))"); print(result) print(rep("#", 10)) all.results[b.out] <- result plot(sort(all.results, decreasing = T)) if(b.out > 3){z <- z + 1; best.so.far[z] <- min(all.results)} if(b.out == 10000){break} } ) min(best.so.far) plot(sort(all.results, decreasing = T)) best <- which(all.results == min(all.results)); best data.results[best] ls() rm(g.id, data.results, best, all.results, b.out, best.so.far, pop, result, sos, x1, x2, z) ls() # End; last updated Feb. 5, 2013.