PROGRAM BT2_7 PARAMETER (NMAX=100,MMAX=8, KMAX=5) REAL XX(NMAX,0:MMAX),X(NMAX) REAL TB(MMAX),MEDIAN(MMAX) REAL TRIMEAN(MMAX),TBHC(MMAX,KMAX) REAL DX(MMAX),SX(MMAX),IQR(MMAX) REAL MAD(MMAX) REAL SHC(MMAX,KMAX),A(MMAX),YULKED(MMAX) REAL ALFA(KMAX) INTEGER N,M,I,N1 CHARACTER*2 DIREC(MMAX) DATA ALFA /0.01, 0.02, 0.03, 0.05, 0.10/ ! MO TA HUONG GIO DATA DIREC /' N','NE',' E','SE',' S','SW',' W','NW'/ ! DOC SO LIEU OPEN(1,FILE='C:\MASTER\G_TR\BAITAP~1\NEW\BANG4.TXT') READ(1,*) READ(1,*) READ(1,*)N, M READ(1,*)((XX(I,J),J=0,M), I=1,N) DO 100 J=1,M DO I=1,N X(I)=XX(I,J) ENDDO DO 101 K=1,KMAX CALL ANOVA(X,N,ALFA(K),TB(J),MEDIAN(J), & TRIMEAN(J),TBHC(J,K),DX(J),SX(J), & IQR(J),MAD(J),SHC(J,K),A(J),YULKED(J)) 101 CONTINUE 100 CONTINUE WRITE(*,*)' CAC DAC TRUNG THONG KE CO BAN' WRITE(*,'("ALFA=",5F14.3)') (ALFA(K),K=1,KMAX) WRITE(*,*) WRITE(*,*)' TRUNG BINH HIEU CHINH ' DO J=1,M WRITE(*,'(A5,5F14.3)')DIREC(J), (TBHC(J,K),K=1,KMAX) ENDDO WRITE(*,*) WRITE(*,*)' PHUONG SAI HIEU CHINH ' DO J=1,M WRITE(*,'(A5,5F14.3)')DIREC(J), (SHC(J,K),K=1,KMAX) ENDDO PAUSE WRITE(*,*) WRITE(*,*)' CAC DAC TRUNG KHAC ' WRITE(*,'(7X,8A9)') (DIREC(J),J=1,M) WRITE(*,'(" T.BINH",8F9.2)') (TB(J),J=1,M) WRITE(*,'(" MEDIAN",8F9.2)') (MEDIAN(J),J=1,M) WRITE(*,'(" TRIMEA",8F9.2)') (TRIMEAN(J),J=1,M) WRITE(*,'(" PH.SAI",8F9.2)') (DX(J),J=1,M) WRITE(*,'(" DO LC ",8F9.2)') (SX(J),J=1,M) WRITE(*,'(" IQR ",8F9.2)') (IQR(J),J=1,M) WRITE(*,'(" MAD ",8F9.2)') (MAD(J),J=1,M) WRITE(*,'(" YULKED",8F9.2)') (YULKED(J),J=1,M) WRITE(*,'(" DO BDX",8F9.2)') (A(J),J=1,M) END SUBROUTINE ANOVA(XX,N,ALFA,TB,MEDIAN,TRIMEAN,TBHC, & DX,SX,IQR,MAD,SHC,A,YULKED) ! CHUONG TRINH NAY TINH CAC DAC TRUNG THONG KE DON GIAN UNG DUNG ! TRONG PHAN TICH KHAO SAT SO LIEU ! ! INPUT: + X MANG SO LIEU BAN DAU DO DAI N ! + N DUNG LUONG MAU ! + ALFA (%) PHAN TRAM SO LIEU BI CAT BO ! OUTPUT: + TB TRUNG BINH SO HOC ! + MEDIAN TRUNG VI ! + TRIMEAN ! + TBHC TRUNG BINH HIEU CHINH ! + DX PHUONG SAI ! + SX DO LECH CHUAN ! + IQR CHI SO BIEN DO PHAN TU ! + MAD CHI SO MAD (MEDIAN CUA DO LECH TUYET DOI SO VOI ! MEDIAN BAN DAU CUA CHUOI) ! + SHC PHUONG SAI HIEU CHINH ! + A DO BAT DOI XUNG ! + YULKED CHI SO YULE-KENDALL ! FUNCTION/SUBROUTINE DUOC GOI TOI: SORT, QUANTILES ! DIMENSION XX(N),X(N),X1(N),CHISO(N) REAL ALFA,TB,MEDIAN,TRIMEAN,TBHC REAL DX,SX,IQR,MAD,SHC,A,YULKED REAL Q50,Q25,Q75,TMP INTEGER N,I,N1,K ! X=XX TB=AMMGOC(X,N,1) DX=AMMTAM(X,N,2) SX=SQRT(DX) A =AMMTAM(X,N,3)/(DX*SX) CALL SORT(X,N,X1,CHISO,N1) CALL QUANTILES(X,N,Q50,Q25,Q75) ! MEDIAN=Q50 TRIMEAN=(Q25+2.0*Q50+Q75)/4.0 IQR=Q75-Q25 YULKED=(Q25-2.0*Q50+Q75)/IQR ! K=INT(REAL(N)*ALFA) TMP=0.0 DO I=K+1,N-K TMP=TMP+X(I) ENDDO TBHC=TMP/REAL(N-2*K) ! TMP=0.0 DO I=K+1,N-K TMP=TMP+(X(I)-TBHC)**2 ENDDO SHC=TMP/REAL(N-2*K) ! DO I=1,N X(I)=ABS(X(I)-Q50) ENDDO CALL QUANTILES(X,N,Q50,Q25,Q75) MAD=Q50 RETURN END SUBROUTINE SORT(X,N,X1,CHISO,N1) ! ! CHUONG TRINH NAY SAP XEP CHUOI THANH CHUOI TRINH TU ! VA CHUOI XEP HANG ! ! INPUT: + MANG X DO DAI N CHUA CHUOI SO LIEU BAN DAU ! + N DUNG LUONG MAU ! OUTPUT: + MANG X DO DAI N CHUA CHUOI TRINH TU ! + MANG X1 DO DAI N1 CHUA CHUOI XEP HANG ! + MANG CHISO DO DAI N1 CHUA CHI SO CUA CHUOI XEP HANG ! + N1 SO THANH PHAN TRONG CHUOI XEP HANG ! DIMENSION X(1),X1(1),CHISO(1) INTEGER N,N1,I,J,K REAL TMP ! SAP XEP THANH CHUOI TRINH TU TANG DAN DO I=1,N-1 DO J=I+1,N IF (X(J).LT.X(I)) THEN TMP=X(J) X(J)=X(I) X(I)=TMP ENDIF ENDDO ENDDO ! XAC DINH CAC THANH PHAN CUA CHUOI XEP HANG N1=1 I=1 X1(N1)=X(I) CHISO(N1)=REAL(I) 10 I=I+1 IF (I.GT.N) GOTO 100 IF (X(I).NE.X(I-1)) THEN N1=N1+1 X1(N1)=X(I) ENDIF GOTO 10 100 CONTINUE ! TINH CHI SO CUA CAC THANH PHAN TRONG CHUOI XEP HANG DO J=1,N1 K=0 CHISO(J)=0.0 DO I=1,N IF (X(I).EQ.X1(J)) THEN K=K+1 CHISO(J)=CHISO(J)+REAL(I) ENDIF ENDDO CHISO(J)=CHISO(J)/REAL(K) ENDDO RETURN END FUNCTION Q05(X,N) ! ! HAM NAY TINH TRUNG VI CUA CHUOI X ! INPUT: + X LA MANG SO LIEU DA SAP XEP THANH CHUOI TRINH TU ! + N LA DO DAI CUA X (DUNG LUONG MAU) ! OUTPUT: + TRUNG VI CUA CHUOI ! DIMENSION X(1) INTEGER N,I,NC NC=N/2 IF (MOD(N,2).EQ.0) THEN Q05=(X(NC)+X(NC+1))/2.0 ELSE Q05=X(NC+1) ENDIF RETURN END SUBROUTINE QUANTILES(X,N,Q50,Q25,Q75) ! ! CHUONG TRINH NAY TINH CAC PHAN VI CHINH CUA CHUOI X DO DAI N ! ! INPUT: + X MANG CHUA CHUOI SO LIEU DA SAP XEP TRINH TU ! + N DUNG LUONG MAU ! OUTPUT: + TRUNG VI Q50 ! + CAC PHAN VI DUOI VA TREN Q25, Q75 ! FUNCTION/SUBROUTINE DUOC GOI TOI: Q05(X,N) ! DIMENSION X(1), X1(N) INTEGER N,I,NC1,NC2,NT,J REAL Q50,Q25,Q75,Q125,Q375,Q625,Q875 Q50=Q05(X,N) NT=N NC1=NT/2 IF (MOD(NT,2).EQ.0) THEN NC2=NC1+1 ELSE NC1=NC1+1 NC2=NC1 ENDIF DO I=1,NC1 X1(I)=X(I) ENDDO Q25=Q05(X1,NC1) J=0 DO I=NC2,N J=J+1 X1(J)=X(I) ENDDO Q75=Q05(X1,NC1) RETURN END FUNCTION AMMGOC(X,N,K) ! ! HAM NAY TINH MOMEN GOC BAC K CUA CHUOI SO LIEU ! INPUT: + X MANG SO LIEU BAN DAU DO DAI N ! + N DUNG LUONG MAU ! + K BAC CUA MOMEN ! OUTPUT: MOMEN GOC BAC K ! DIMENSION X(N) INTEGER N,K,I REAL TMP TMP=0.0 DO I=1,N TMP=TMP+X(I)**K ENDDO AMMGOC=TMP/REAL(N) RETURN END FUNCTION FAC(N) ! TINH N! (N GIAI THUA) REAL TMP IF (N.LT.0) THEN WRITE(*,*)' INVALID NUMERIC INPUT IN FAC FUNCTION' STOP ELSE IF (N.EQ.0.OR.N.EQ.1) THEN FAC=1.0 RETURN ELSE TMP=1.0 DO I=2,N TMP=TMP*REAL(I) ENDDO FAC=TMP RETURN ENDIF END FUNCTION COMBIN(N,K) ! TINH TO HOP CHAP K CUA N ! FUNCTION/SUBROUTINE DUOC GOI TOI: FAC(N) IF (N.LT.0.OR.K.LT.0.OR.N.LT.K) THEN WRITE(*,*)' INVALID NUMERIC INPUT IN COMBIN FUNCTION' STOP ELSE COMBIN=FAC(N)/FAC(K)/FAC(N-K) RETURN ENDIF END FUNCTION AMMTAM(X,N,K) ! HAM NAY TINH MOMEN TRUNG TAM BAC K TU CHUOI SO LIEU X ! INPUT: + X MANG SO LIEU BAN DAU DO DAI N ! + N DUNG LUONG MAU ! + K BAC CUA MOMEN ! OUTPUT: MOMEN TRUNG TAM BAC K ! FUNCTION/SUBROUTINE DUOC GOI TOI: AMMGOC(X,N,K), COMBIN(N,K) DIMENSION X(N) INTEGER N,K,I REAL TMP,TB TB=AMMGOC(X,N,1) TMP=0 DO I=0,K TMP=TMP+(-1)**I*COMBIN(K,I)*TB**I*AMMGOC(X,N,K-I) ENDDO AMMTAM=TMP RETURN END