User:Timothee Flutre/Notebook/Postdoc/2011/11/07

From OpenWetWare

Jump to: navigation, search
Project name Main project page
Previous entry      Next entry

Entry title

  • customize the built-in heatmap in R (inspired from this):
S <- 3  # nb of subgroups
V <- 7  # nb of observations
z <- matrix(c(0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,1,1,1,0,0), nrow=V, ncol=S, byrow=TRUE)

myheatmap <- function(z, out.file="") {
  def.par <- par(no.readonly=TRUE)
  par(mar=c(4,5,3,2), font=2, font.axis=2, font.lab=2, cex=1.5, lwd=2)
  if (out.file != "")
  layout(mat=cbind(1, 2), width=c(7,1))  # plot +  legend
  mycol <- rev(heat.colors(4))
  image(x=1:NCOL(z), y=1:NROW(z), z=t(z),
        xlim=0.5+c(0,NCOL(z)), ylim=0.5+c(0,NROW(z)),
        xlab="", ylab="Observations sorted by cluster", main="Custom heatmap",
        axes=FALSE, col=mycol)
  axis(1, 1:NCOL(z), labels=paste("subgroup", 1:NCOL(z)), tick=0)
  legend("center", legend=sprintf("%.2f", seq(from=min(z), to=max(z), length.out=5)[-1]),
         fill=mycol, border=mycol, bty="n")
  if (out.file != "")


  • try KMLOCAL, yet another kmeans clustering program:

cat test_kmlocal.config 
show_assignments yes      # show final cluster assignments
validate yes              # validate assignments
dim 3                     # dimension
data_size 1000            # number of data points
seed 1859                 # random number seed
read_data_pts matrix.txt  # read data points
kcenters 4                # number of centers
max_tot_stage 20 0 0 0    # number of stages
seed 4                    # use different seed
run_kmeans swap           # run with this algorithm

kmltest -i test_kmlocal.config -o test_kmlocal.out

But it doesn't work on a big dataset (bad_alloc).

Personal tools