X-Git-Url: http://iramuteq.org/git?a=blobdiff_plain;f=Rscripts%2FCHD.R;h=e686637656fddb91714b51bc926a9cc62a573b64;hb=8aafccab06936a00d3a134bfc7bfe7e71f8e8ea6;hp=e6a3c7b5d6733ad2ec7e23d2155eff87da5e5305;hpb=4f2dc8e6823ac5886f758a6ad3f1ae6acb01916c;p=iramuteq diff --git a/Rscripts/CHD.R b/Rscripts/CHD.R index e6a3c7b..e686637 100644 --- a/Rscripts/CHD.R +++ b/Rscripts/CHD.R @@ -1,5 +1,5 @@ #Author: Pierre Ratinaud -#Copyright (c) 2008-2011 Pierre Ratinaud +#Copyright (c) 2008-2020 Pierre Ratinaud #License: GNU/GPL pp<-function(txt,val) { @@ -26,17 +26,28 @@ find.max <- function(dtable, chitable, compte, rmax, maxinter, sc, TT) { lo[1:nrow(dtable)] <- 0 for (k in 1:nrow(ln)) {lo[[ln[k,1]]]<-append(lo[[ln[k,1]]],ln[k,2])} for (k in 1:nrow(dtable)) {lo[[k]] <- lo[[k]][-1]} - lo<-lo[-c(1,length(lo))] - for (l in lo) { - compte <- compte + 1 - chitable[1,l]<-chitable[1,l]+1 - chitable[2,l]<-chitable[2,l]-1 - chi<-MyChiSq(chitable,sc,TT) - if (chi>maxinter) { - maxinter<-chi - rmax<-compte - } - } + ## lo<-lo[-c(1,length(lo))] + ## for (l in lo) { + ## compte <- compte + 1 + ## chitable[1,l]<-chitable[1,l]+1 + ## chitable[2,l]<-chitable[2,l]-1 + ## chi<-MyChiSq(chitable,sc,TT) + ## if (chi>maxinter) { + ## maxinter<-chi + ## rmax<-compte + ## } + #} + lo<-lo[-c(1)] + for (l in lo) { + chi<-MyChiSq(chitable,sc,TT) + if (chi>maxinter) { + maxinter<-chi + rmax<-compte + } + compte <- compte + 1 + chitable[1,l]<-chitable[1,l]+1 + chitable[2,l]<-chitable[2,l]-1 + } res <- list(maxinter=maxinter, rmax=rmax) res } @@ -218,8 +229,9 @@ CHD<-function(data.in, x=9, mode.patate = FALSE, svd.method, libsvdc.path=NULL){ print('###################################') print('longueur < 0') malcl<-length(vdelta) + if ((it>1)&&(!is.logical(listsub[[it]]))&&(!is.logical(listsub[[it-1]]))){ - if (listsub[[it]]==listsub[[(it-1)]]){ + if (all(listsub[[it]]==listsub[[(it-1)]])){ malcl<-0 } } @@ -237,14 +249,14 @@ CHD<-function(data.in, x=9, mode.patate = FALSE, svd.method, libsvdc.path=NULL){ #t2<-dtable[dtable[,'cl']==clnb+1,][,-ncol(dtable)] t1<-dtable[which(cl[,1]==clnb),]#[,-ncol(dtable)] t2<-dtable[which(cl[,1]==clnb+1),]#[,-ncol(dtable)] - if (class(t1)=='numeric') { + if (inherits(t1, "numeric")) { sc1 <- as.vector(t1) nrowt1 <- 1 } else { sc1 <- colSums(t1) nrowt1 <- nrow(t1) } - if (class(t2)=='numeric') { + if (inherits(t2, "numeric")) { sc2 <- as.vector(t2) nrowt2 <- 1 } else {