computeStability <- function(hc1,hc2) { stability <- c(1:dim(hc1)[1]) nbleaves <- c(1:dim(hc1)[1]) resultat <- .C("computeStability",as.integer(hc1),as.integer(hc2),as.integer(dim(hc1)[1]),as.double(stability),as.integer(nbleaves)) return(list(resultat[[4]],resultat[[5]])) } ## AFFICHAGE CLASSE DENDROGRAMME findInd <- function(h,vectheight) { for(i in 1:length(vectheight)) if(vectheight[i] == h) return(i) } decore <- function(dendo,vectheight,stab,minstab,minmembers) { if(!is.leaf(dendo)) { h <- attr(dendo,"height") ind <- findInd(h,vectheight) #attr(dendo,"edgetext") <- as.character(round(deco[ind],2)) if(stab[ind]>=minstab && attr(dendo,"members")>=minmembers) { attr(dendo,"edgetext") <- as.character(round(stab[ind],2)) attr(dendo,"edgePar") <- list(p.col="gray99") } else { #attr(dendo,"edgetext") <- as.character(round(deco[ind],2)) #attr(dendo,"edgePar") <- list(p.col="green") } } dendo } decoreDendo <- function(hc,stab,minstab=-Inf,minmembers=0) { dendo <- as.dendrogram(hc) dendrapply(dendo,decore,hc$height,stab,minstab,minmembers) } validTree<-function(array.dat,iterhc=5,interact=F) { nt<-dim(array.dat)[[2]] nrep<-dim(array.dat)[[3]] ngene<-dim(array.dat)[[1]] ####### #######Matrices pour strocker les resultats de la simulation res<-matrix(0,nrow=iterhc,ncol=ngene-1) nbleaves<-rep(0,ngene-1) dimnames(res)<-list(paste("iter",1:iterhc,sep=""), paste("nd.",1:(ngene-1),sep="")) if(!interact) { mat<-apply(array.dat,c(1,2),mean) matt<-t(apply(mat,1,function(x){x-mean(x)})) #att<-mat hcall<-hclust(dist(matt),method="ward") } else { gamma<-apply(array.dat,c(1,2),mean) mtemps<-apply(gamma,2,mean) mgene<-apply(gamma,1,mean) mu<-mean(gamma) gamma<-sweep(gamma,2,mtemps,FUN="-") gamma<-sweep(gamma,1,mgene,FUN="-") mat<-gamma+mu hcall<-hclust(dist(mat),method="ward") } for(i in 1:iterhc) { cat(paste("Numéro d'itération sur classification =",i,"\r")) #rep.cross<-sample(x=c(1:nrep),size=nt,replace=T) ar<-array(0,dim=c(ngene,nt,nrep)) for(j in 1:nt) { rep.cross<-sample(x=c(1:nrep),size=nrep,replace=T) ar[,j,]<-array.dat[,j,rep.cross] } ##On fait la moyenne if(!interact) { matboot<-apply(ar,c(1,2),mean) matboott<-t(apply(matboot,1,function(x){x-mean(x)})) hcboot<-hclust(dist(matboott),method="ward") } else { gamma<-apply(ar,c(1,2),mean) mtemps<-apply(gamma,2,mean) mgene<-apply(gamma,1,mean) mu<-mean(gamma) gamma<-sweep(gamma,2,mtemps,FUN="-") gamma<-sweep(gamma,1,mgene,FUN="-") matboot<-gamma+mu hcboot<-hclust(dist(matboot),method="ward") } tmp <-computeStability(hcall$merge,hcboot$merge) res[i,] <- tmp[[1]] nbleaves <- tmp[[2]] } cat("\n") invisible(list(stab=res,hc=hcall,nbleaves=nbleaves)) } dendnames <- function(n) { if(is.leaf(n)) { lab<- attr(n, "label") lab } }