subroutine findmleall (means,NI,NJ,weights,groupclass,loglikes, + cvals,nerrs) implicit none integer I,J,NI,NJ,groupclass(NI) double precision means(NI,NJ),weights(NI),peakvals(NI),cutoff, + loglikes(NJ),cvals(NJ),nerrs(NJ),logl,n11,n21,n12,n22 cutoff = 0.0 logl = 0.0 DO 10 J = 1, NJ DO 20 I = 1,NI peakvals(I) = means(I,J) 20 CONTINUE call maxl(peakvals,weights,groupclass,NI,logl,cutoff, + n11,n21,n12,n22) cvals(J) = cutoff nerrs(J) = n21+n12 loglikes(J) = logl 10 CONTINUE RETURN END subroutine maxl (peakvals,weights,groupclass,NI,logl,cutoff, + n11,n21,n12,n22) implicit none integer NI,groupclass(NI),I,k double precision weights(NI),peakvals(NI),logl,cutoff, + n11,n12,n21,n22,templl,tempcutoff,tempn11,tempn12, + tempn21,tempn22,errct0,errct1,errct,temperrct logl = -10000000 errct0 = NI errct1 = NI errct = NI tempn11 = 1 tempn12 = 1 tempn21 = 1 tempn22 = 1 DO 20 k = 1, NI tempcutoff = peakvals(k) call calcll(peakvals,tempcutoff,weights,groupclass,NI,templl, + tempn11,tempn12,tempn21,tempn22) errct0 = tempn11+tempn22 errct1 = tempn12+tempn21 temperrct = min(errct0,errct1) IF (temperrct .LT. errct) THEN errct = temperrct logl = templl cutoff = tempcutoff n11 = tempn11 n12 = tempn12 n21 = tempn21 n22 = tempn22 END IF 20 CONTINUE return end subroutine calcll (peakvals,cutoff,weights,groupclass,NI,logl, + n11,n21,n12,n22) implicit none integer I,NI,groupclass(NI) double precision weights(NI),peakvals(NI),logl,cutoff,temp, + n11,n12,n21,n22 n11 = 0 n12 = 0 n21 = 0 n22 = 0 DO 10 I = 1,NI IF (groupclass(I) .EQ. 0 .AND. peakvals(I) .LE. cutoff) THEN n11 = n11 + weights(I) ELSE IF (groupclass(I) .EQ. 1 .AND. + peakvals(I) .LE. cutoff) THEN n21 = n21 + weights(I) ELSE IF (groupclass(I) .EQ. 0 .AND. + peakvals(I) .GT. cutoff) THEN n12 = n12 + weights(I) ELSE IF (groupclass(I) .EQ. 1 .AND. + peakvals(I) .GT. cutoff) THEN n22 = n22 + weights(I) END IF 10 Continue logl = 0 IF (n11 .GT. 0) THEN temp = n11/(n11+n21) logl = logl + n11*LOG(temp) END IF IF (n21 .GT. 0) THEN temp = n21/(n11+n21) logl = logl + n21*LOG(temp) END IF IF (n12 .GT. 0) THEN temp = n12/(n12+n22) logl = logl + n12*LOG(temp) END IF IF (n22 .GT. 0) THEN temp = n22/(n12+n22) logl = logl + n22*LOG(temp) END IF RETURN END