Quantil mean

Synopsis

use oakleaf

subroutine qmean(data,mean,stderr,stdsig,flag)
   real, dimension(:), intent(in) :: data
   real, intent(out) :: mean
   real, intent(out), optional :: stderr,stdsig
   logical, intent(in), optional :: verbose
   integer, intent(out), optional :: flag
end subroutine qmean

Description

This routine estimates both averadge and standard deviation of a data set on base of the order statistics, i.e. quantiles. The median, the Q(0.5) quantile, is claimed as the (robust) mean.

The standard deviation (and consequently the standard error) is estimated preferably by the Qn-estimator due Rousseeuw & Croux; one is more durable on highly contamined samples, yet additional memory space is required. In other cases (N < 3 or N > 2**16), the deviations is determined as MAD/0.6745, where MAD is the median of absolute deviations.

Both the median and the Qn,MAD are robust estimators, however they are generally incompatible to least-square estimates, as being granulated and deviated for contamined data.

The quick sort algorithm is used for small samples N ≤ 42; one requires N log N operations. The larger samples are estimated by the quick median which needs 2N operations (Wirth,D.: Algorithm and data structures, chapter Finding the Median). The Qn-estimator requires N**2/2 elements.

Parameters

On input:

data
array of data

On output:

mean
mean by median
stderr
(optional) standard error
stdsig
(optional) standard deviation by MAD
verbose
(optional) print a detailed information about the calulations.
flag
(optional) a flag, see the status codes.

Example

Save the program to the file example.f08:

program example

   use oakleaf

   real, dimension(5) :: data = [ 1, 2, 3, 4, 5 ]
   real :: mean,stderr,stdsig

   call qmean(data,mean,stderr,stdsig)
   write(*,*) 'qmean:',mean,' stderr:',stderr,'stdsig:',stdsig

end program example
  

Than compile and run it:

$ gfortran -I/usr/include example.f08 -L/usr/lib -loakleaf -lminpack
$ ./a.out
 qmean:   3.00000000      stderr:  0.992554188     stdsig:   2.21941876
  

References

Wirth,D.: Algorithm and data structures, Prentice-Hall International editions (1986)

Rousseeuw, Peter J and Croux, Christophe: Alternatives to the median absolute deviation, Journal of the American Statistical association vol. 88, 1273--1283 (1993)