Rev 5634 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
subroutine cldaisy(nn,jpp,x,valmd,weights,+ jtmd,jdat,vtype,ndyst,mdata,disv)c cc c Calculating dissimilarities between objects or variablesc cinteger nn, jppc c nn = number of objectsc c jpp = number of variables used for the calculationsc c The following vectors and matrices must be dimensioned in thec c main program :double precision x(nn,jpp), valmd(jpp), weights(jpp)double precision disv(1+nn*(nn-1)/2)integer jtmd(jpp), jdat, vtype(jpp), ndyst, mdatac vtype was character originallyc vtype(j) is the type of variable j:c = 1 (A) for an Asymmetric binary variablec = 2 (S) for a Symmetric binary variablec = 3 (N) for a Nominal variablec = 4 (O) for an Ordinal variablec = 5 (I) for an Interval variable (additive)c = 6 (T) for a raTio variable (log transformed)c vector jtmd is only read if there are missing values : if(mdata)c jtmd(j) = 0 if variable j is binaryc = -1 if variable j is not binary and has missing valuesc = +1 if variable j is not binary and has no missing valuesc VARdouble precision clk,dlk, pp,ppa, rpresinteger j,k,l,la, lsubt, nlk, nbad, npreslogical hasNAhasNA = (mdata .ne. 0)c calculation of the dissimilaritiesnlk=0if(jdat .eq. 1) thenc Case I: `mixed' type variablesnbad=0do 450 l=2,nnla=l-1do 440 k=1,lanlk=nlk+1ppa=0.dlk=0.c Dissimilarity between obs. l & kdo 420 j=1,jppif(vtype(j) .ge. 3) thenif (hasNA) thenif(jtmd(j).lt.0) thenif(x(l,j).eq.valmd(j)) goto 420if(x(k,j).eq.valmd(j)) goto 420endifendifppa=ppa + weights(j)if(vtype(j).eq.3) thenif(x(l,j).ne.x(k,j)) dlk=dlk+ weights(j)elsedlk=dlk+ weights(j)*dabs(x(l,j)-x(k,j))endifelsec binary variable x(*,j)if(x(l,j).ne.0..and.x(l,j).ne.1.) goto 420if(x(k,j).ne.0..and.x(k,j).ne.1.) goto 420if(vtype(j).eq.2.or.x(l,j).ne.0.or.x(k,j).ne.0)* ppa=ppa+weights(j)if(x(l,j).ne.x(k,j)) dlk=dlk+ weights(j)endif420 continueif(ppa.le.0.5) thennbad=nbad+1disv(nlk)=-1elsedisv(nlk)=dlk/ppaendif440 continue450 continueelsec Case II : jdat != 1: all variables are interval scaledc ------- ~~~~~~~~~ { basically === dysta() in ./dysta.fc FIXME: common code! }pp=jppdo 600 l=2,nnlsubt=l-1do 520 k=1,lsubtclk=0.0nlk=nlk+1npres=0do 530 j=1,jppif (hasNA) thenif(jtmd(j).lt.0) thenif(x(l,j).eq.valmd(j)) goto 530if(x(k,j).eq.valmd(j)) goto 530endifendifnpres=npres+1if(ndyst.eq.1) thenclk=clk+ (x(l,j)-x(k,j))*(x(l,j)-x(k,j))elseclk=clk+ dabs(x(l,j)-x(k,j))endif530 continuerpres=npresif(npres.eq.0)thendisv(nlk)=-1.0else if(ndyst.eq.1) thendisv(nlk)=dsqrt(clk*(pp/rpres))elsedisv(nlk)=clk*(pp/rpres)endif520 continue600 continueendifend