libsim  Versione7.2.6
simple_stat_test.f90
1 ! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
2 ! authors:
3 ! Davide Cesari <dcesari@arpa.emr.it>
4 ! Paolo Patruno <ppatruno@arpa.emr.it>
5 
6 ! This program is free software; you can redistribute it and/or
7 ! modify it under the terms of the GNU General Public License as
8 ! published by the Free Software Foundation; either version 2 of
9 ! the License, or (at your option) any later version.
10 
11 ! This program is distributed in the hope that it will be useful,
12 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ! GNU General Public License for more details.
15 
16 ! You should have received a copy of the GNU General Public License
17 ! along with this program. If not, see <http://www.gnu.org/licenses/>.
18 ! Programma di test per il module simple_stat
19 ! migliorare a piacimento
20 PROGRAM simple_stat_test
22 USE simple_stat
23 IMPLICIT NONE
24 
25 REAL :: s1(6)=(/4.,6.,7.,8.,9.,11./), s2(6)=(/11.,9.,8.,7.,6.,4./)
26 REAL :: s3(6)=(/rmiss,6.,7.,8.,9.,rmiss/), s4(6)=(/rmiss,9.,rmiss,rmiss,6.,rmiss/)
27 REAL :: val1, val2, valv(5)
28 REAL :: opt1, opt2, opt3, opt4
29 INTEGER,ALLOCATABLE :: bin(:)
30 REAL, PARAMETER :: epsy=1.0e-20
31 
32 print*,'=== Testing simple_stat module ==='
33 
34 print*,'Checking average'
35 val1 = stat_average(s1)
36 val2 = stat_average(s2)
37 print*,'averages: ',val1,val2
38 IF (abs(val1-7.5) > epsy) CALL exit(1)
39 IF (abs(val2-7.5) > epsy) CALL exit(1)
40 
41 print*,'Checking average with missing data'
42 val1 = stat_average(s3)
43 val2 = stat_average(s4)
44 print*,'averages: ',val1,val2
45 IF (abs(val1-7.5) > epsy) CALL exit(1)
46 IF (abs(val2-7.5) > epsy) CALL exit(1)
47 
48 print*,'Checking variances'
49 val1 = stat_variance(s1, opt1)
50 val2 = stat_variance(s1, opt2)
51 print*,'variances: ',val1,val2
52 print*,'averages: ',opt1,opt2
53 
54 print*,'Checking variances with missing data'
55 val1 = stat_variance(s3, opt1)
56 val2 = stat_variance(s4, opt2)
57 print*,'variances: ',val1,val2
58 print*,'averages: ',opt1,opt2
59 
60 print*,'Checking linear correlation'
61 val1 = stat_linear_corr(s1, s2, opt1, opt2, opt3, opt4)
62 print*,'correlation: ',val1
63 print*,'averages and variances: ', opt1, opt2, opt3, opt4
64 IF (abs(val1+1.) > epsy) CALL exit(1)
65 
66 print*,'Checking linear correlation with missing data'
67 val1 = stat_linear_corr(s3, s4, opt1, opt2, opt3, opt4)
68 print*,'correlation: ',val1
69 print*,'averages and variances: ', opt1, opt2, opt3, opt4
70 IF (abs(val1+1.) > epsy) CALL exit(1)
71 
72 print*,'Checking linear regression'
73 CALL stat_linear_regression(s1, s2, val1, val2)
74 print*,'regression coefficients: ',val1,val2
75 IF (abs(val1-15.) > epsy .OR. abs(val2+1.) > epsy) CALL exit(1)
76 
77 print*,'Checking linear regression with missing data'
78 CALL stat_linear_regression(s3, s4, val1, val2)
79 print*,'regression coefficients: ',val1,val2
80 IF (abs(val1-15.) > epsy .OR. abs(val2+1.) > epsy) CALL exit(1)
81 
82 print*,'Checking percentiles'
83 valv = stat_percentile(s2, (/0.,25.,50.,75.,100./))
84 print*,'percentiles: ',valv
85 IF (abs(valv(1)-s2(6)) > epsy) CALL exit(1)
86 IF (abs(valv(5)-s2(1)) > epsy) CALL exit(1)
87 
88 print*,'Checking percentiles with missing data'
89 valv = stat_percentile(s3, (/0.,25.,50.,75.,100./))
90 print*,'percentiles: ',valv
91 IF (abs(valv(1)-s3(2)) > epsy) CALL exit(1)
92 IF (abs(valv(5)-s3(5)) > epsy) CALL exit(1)
93 
94 print*,'Checking binning'
95 CALL stat_bin(s1, bin, 4, 3.5, 11.5)
96 print*,'bin population: ',bin
97 IF (any(bin /= (/1,2,2,1/))) CALL exit(1)
98 CALL stat_bin(s2, bin, 4, 3.5, 11.5)
99 print*,'bin population: ',bin
100 IF (any(bin /= (/1,2,2,1/))) CALL exit(1)
101 
102 print*,'Checking binning with missing data'
103 CALL stat_bin(s3, bin, 4, 3.5, 11.5)
104 print*,'bin population: ',bin
105 IF (any(bin /= (/0,2,2,0/))) CALL exit(1)
106 CALL stat_bin(s4, bin, 4, 3.5, 11.5)
107 print*,'bin population: ',bin
108 IF (any(bin /= (/0,1,1,0/))) CALL exit(1)
109 
110 print*,'Checking mode'
111 val1 = stat_mode_histogram(s1, 4, 3.5, 11.5)
112 print*,'mode: ',val1
113 IF (abs(val1-6.5) > epsy) CALL exit(1)
114 val1 = stat_mode_histogram(s2, 4, 3.5, 11.5)
115 print*,'mode: ',val1
116 IF (abs(val1-6.5) > epsy) CALL exit(1)
117 
118 print*,'Checking mode with missing data'
119 val1 = stat_mode_histogram(s3, 4, 3.5, 11.5)
120 print*,'mode: ',val1
121 IF (abs(val1-6.5) > epsy) CALL exit(1)
122 val1 = stat_mode_histogram(s4, 4, 3.5, 11.5)
123 print*,'mode: ',val1
124 IF (abs(val1-6.5) > epsy) CALL exit(1)
125 
126 END PROGRAM simple_stat_test
Compute the average of the random variable provided, taking into account missing data.
Definition: simple_stat.f90:39
Bin a sample into equally spaced intervals to form a histogram.
Compute the mode of the random variable provided taking into account missing data.
Compute a set of percentiles for a random variable.
Compute the linear regression coefficients between the two random variables provided, taking into account missing data.
Compute the variance of the random variable provided, taking into account missing data...
Definition: simple_stat.f90:54
Definitions of constants and functions for working with missing values.
Module for basic statistical computations taking into account missing data.
Definition: simple_stat.f90:25
Compute the linear correlation coefficient between the two random variables provided, taking into account missing data.
Definition: simple_stat.f90:89

Generated with Doxygen.