FREQ Subroutine

public subroutine FREQ(X, N)

NAME

freq(3f) - [M_datapac:STATISTICS] compute the sample frequency and
cumulative sample frequency of a vector

SYNOPSIS

   SUBROUTINE FREQ(X,N)

    REAL(kind=wp),intent(in) :: X(:)
    INTEGER,intent(in)       :: N

DESCRIPTION

freq(3f) computes the sample frequency and sample cumulative frequency
for the data in the input vector x.

INPUT ARGUMENTS

X    The  vector of (unsorted or sorted) observations.

N    The integer number of observations in the vector X.
     The maximum allowable value of N for this subroutine is 15000.

OUTPUT

Several (for large data sets) pages of automatic plots (with
approximately 55 values per page) consisting of an ordered listing
of each distinct value in the data set along with the frequency of
occurance of that value and the cumulative frequency.

EXAMPLES

Sample program:

program demo_freq
use M_datapac, only : freq
implicit none
! call freq(x,y)
end program demo_freq

Results:

AUTHOR

The original DATAPAC library was written by James Filliben of the
Statistical Engineering Division, National Institute of Standards
and Technology.

MAINTAINER

John Urban, 2022.05.31

LICENSE

CC0-1.0

REFERENCES

  • KENDALL AND STUART, THE ADVANCED THEORY OF STATISTICS, VOLUME 1, EDITION 2, 1963, page 8.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: X(:)
integer, intent(in) :: N

Common Blocks

CAUPLT (subroutine)
CHSCDF (subroutine)
CODE (subroutine)
DECOMP (subroutine)
DEMOD (subroutine)
DEXPLT (subroutine)
EV1PLT (subroutine)
EV2PLT (subroutine)
EXPPLT (subroutine)
EXTREM (subroutine)
EXTREM (subroutine)
GAMPLT (subroutine)
GEOPLT (subroutine)
HFNPLT (subroutine)
INVXWX (subroutine)
LAMPLT (subroutine)
LGNPLT (subroutine)
LOGPLT (subroutine)
MEDIAN (subroutine)
norout (subroutine)
NORPLT (subroutine)
PARPLT (subroutine)
PLOTU (subroutine)
POIPLT (subroutine)
RUNS (subroutine)
SAMPP (subroutine)
SPCORR (subroutine)
TAIL (subroutine)
TPLT (subroutine)
TRIM (subroutine)
UNIPLT (subroutine)
WEIB (subroutine)
WEIPLT (subroutine)
WIND (subroutine)
"> common /BLOCK2_real64/

Type Attributes Name Initial
real :: WS(15000)

Source Code

SUBROUTINE FREQ(X,N)
REAL(kind=wp),intent(in) :: X(:)
INTEGER,intent(in)       :: N
REAL(kind=wp) :: an, cfreq, dvalue, frq, hold, pcfreq, pfreq, s, sum, WS, xbar, Y
INTEGER i, icfreq, iflag, ifreq, ip1, iupper, ndv, nm1, numseq
DIMENSION Y(15000)
COMMON /BLOCK2_real64/ WS(15000)
EQUIVALENCE (Y(1),WS(1))
!
      iupper = 15000
!
!     CHECK THE INPUT ARGUMENTS FOR ERRORS
!
      IF ( N<1 .OR. N>iupper ) THEN
         WRITE (G_IO,99001) iupper
         99001 FORMAT (' ***** FATAL ERROR--THE SECOND INPUT ARGUMENT TO FREQ(3f) IS OUTSIDE THE ALLOWABLE (1,',&
         & I0,') INTERVAL *****')
         WRITE (G_IO,99002) N
         99002 FORMAT (' ','***** THE VALUE OF THE ARGUMENT IS ',I0,' *****')
         RETURN
      ELSEIF ( N==1 ) THEN
         WRITE (G_IO,99003)
         99003 FORMAT (' ***** FATAL ERROR-- THE SECOND INPUT ARGUMENT TO FREQ(3f) HAS THE VALUE 1 *****')
         RETURN
      ELSE
         hold = X(1)
         DO i = 2 , N
            IF ( X(i)/=hold ) GOTO 50
         ENDDO
         WRITE (G_IO,99004) hold
         99004 FORMAT (' ***** NON-FATAL DIAGNOSTIC--THE FIRST  INPUT ARGUMENT (A VECTOR) TO FREQ(3f) HAS ALL ELEMENTS = ', &
         & E15.8,' *****')
!
!-----START POINT-----------------------------------------------------
!
 50      an = N
!
!     COMPUTE THE SAMPLE MEAN AND SAMPLE STANDARD DEVIATION
!
         sum = 0.0_wp
         DO i = 1 , N
            sum = sum + X(i)
         ENDDO
         xbar = sum/an
         sum = 0.0_wp
         DO i = 1 , N
            sum = sum + (X(i)-xbar)**2
         ENDDO
         s = SQRT(sum/(an-1.0_wp))
!
         WRITE (G_IO,99005)
         99005    FORMAT ('1')
         WRITE (G_IO,99006)
!
         99006    FORMAT (' ',18X,'SAMPLE FREQUENCY AND SAMPLE CUMULATIVE FREQUENCY')
         WRITE (G_IO,99014)
         WRITE (G_IO,99007) N
         99007    FORMAT (' ',27X,'THE SAMPLE SIZE N = ',I0)
         WRITE (G_IO,99008) xbar
         99008    FORMAT (' ',25X,'THE SAMPLE MEAN = ',E15.8)
         WRITE (G_IO,99009) s
         99009    FORMAT (' ',20X,'THE SAMPLE STANDARD DEVIATION = ',E15.8)
         WRITE (G_IO,99014)
         WRITE (G_IO,99014)
         WRITE (G_IO,99010)
99010    FORMAT ('     INDEX            VALUE       FREQUENCY    PERCENTAGE        CUMULATIVE    PERCENTAGE')
99011    FORMAT ('                                               FREQUENCY         FREQUENCY     CUMULATIVE')
99012    FORMAT ('                                                                               FREQUENCY ')
         WRITE (G_IO,99011)
         WRITE (G_IO,99012)
         WRITE (G_IO,99014)
!
         CALL SORT(X,N,Y)
         ndv = 0
         icfreq = 0
         numseq = 1
         nm1 = N - 1
         DO i = 1 , nm1
            ip1 = i + 1
            IF ( Y(i)==Y(ip1) ) numseq = numseq + 1
            IF ( Y(i)/=Y(ip1) ) THEN
               ndv = ndv + 1
               dvalue = Y(i)
               ifreq = numseq
               icfreq = icfreq + ifreq
               frq = ifreq
               cfreq = icfreq
               pfreq = 100.0_wp*frq/an
               pcfreq = 100.0_wp*cfreq/an
               WRITE (G_IO,99013) ndv , dvalue , ifreq , pfreq , icfreq , pcfreq
               iflag = ndv - 10*(ndv/10)
               IF ( iflag==0 ) WRITE (G_IO,99014)
               numseq = 1
            ENDIF
         ENDDO
         ndv = ndv + 1
         dvalue = Y(N)
         ifreq = numseq
         icfreq = icfreq + ifreq
         frq = ifreq
         cfreq = icfreq
         pfreq = 100.0_wp*frq/an
         pcfreq = 100.0_wp*cfreq/an
         WRITE (G_IO,99013) ndv , dvalue , ifreq , pfreq , icfreq , pcfreq
         iflag = ndv - 10*(ndv/10)
         IF ( iflag==0 ) WRITE (G_IO,99014)
      ENDIF
99013 FORMAT (' ',I8,4X,E17.10,3X,I8,6X,F8.4,10X,I8,6X,F8.4)
99014 FORMAT (' ')
END SUBROUTINE FREQ