calculate_stats Subroutine

subroutine calculate_stats()

Arguments

None

Contents

Source Code


Variables

Type Visibility Attributes Name Initial
real(kind=8), public :: a
real(kind=8), public :: b
real(kind=8), public :: c
real(kind=8), public :: s(5,2)
real(kind=8), public :: sxy

Source Code

    subroutine calculate_stats
        real(8) :: a, b, c, sxy
        real(8) :: s(5,2)

        call summary_stats(x_seq(1:n_seq),s(1,1),s(2,1),s(3,1),s(4,1),s(5,1))
        call stats%set('n',real(n_seq,8))
        call stats%set('ux',s(1,1))
        call stats%set('mx',s(2,1))
        call stats%set('sx',s(3,1))
        call stats%set('lqx',s(4,1))
        call stats%set('uqx',s(5,1))
        if (seq_is_x) then
                 write(6,10) '    count n -> ',n_seq
            call print_value('    mean ux -> ',s(1,1))
            call print_value('  stddev sx -> ',s(3,1))
            call print_value('  median mx -> ',s(2,1))
            call print_value('lower_q lqx -> ',s(4,1))
            call print_value('upper_q uqx -> ',s(5,1))
       else
            call summary_stats(y_seq(1:n_seq),s(1,2),s(2,2),s(3,2),s(4,2),s(5,2))
                 write(6,10) '    count n        -> ',n_seq
            call print_value('    means ux , uy  -> ',s(1,1),s(1,2))
            call print_value('  stddevs sx , xy  -> ',s(3,1),s(3,2))
            call print_value('  medians mx , my  -> ',s(2,1),s(2,2))
            call print_value('lower_qs lqx , lqy -> ',s(4,1),s(4,2))
            call print_value('upper_qs uqx , uqy -> ',s(5,1),s(5,2))
            call stats%set('uy',s(1,2))
            call stats%set('my',s(2,2))
            call stats%set('sy',s(3,2))
            call stats%set('lqy',s(4,2))
            call stats%set('uqy',s(5,2))

            call calculate_regression(s(1,1),s(1,2),a,b,c,sxy)
            call stats%set('a',a)
            call stats%set('b',b)
            call stats%set('corr',c)
            call stats%set('cov',sxy)
            write(6,'(/a)') 'Regression:  y = ax + b'
            call print_value('   gradient a      ->',a)
            call print_value('  intercept b      -> ',b)
            call print_value(' covariance cov    -> ',sxy)
            call print_value('correlation corr   -> ',c)
        end if
        10 format(a,i0)
        
    end subroutine calculate_stats