libsim Versione 7.2.1
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
20PROGRAM simple_stat_test
23IMPLICIT NONE
24
25REAL :: s1(6)=(/4.,6.,7.,8.,9.,11./), s2(6)=(/11.,9.,8.,7.,6.,4./)
26REAL :: s3(6)=(/rmiss,6.,7.,8.,9.,rmiss/), s4(6)=(/rmiss,9.,rmiss,rmiss,6.,rmiss/)
27REAL :: val1, val2, valv(5)
28REAL :: opt1, opt2, opt3, opt4
29INTEGER,ALLOCATABLE :: bin(:)
30REAL, PARAMETER :: epsy=1.0e-20
31
32print*,'=== Testing simple_stat module ==='
33
34print*,'Checking average'
35val1 = stat_average(s1)
36val2 = stat_average(s2)
37print*,'averages: ',val1,val2
38IF (abs(val1-7.5) > epsy) CALL exit(1)
39IF (abs(val2-7.5) > epsy) CALL exit(1)
40
41print*,'Checking average with missing data'
42val1 = stat_average(s3)
43val2 = stat_average(s4)
44print*,'averages: ',val1,val2
45IF (abs(val1-7.5) > epsy) CALL exit(1)
46IF (abs(val2-7.5) > epsy) CALL exit(1)
47
48print*,'Checking variances'
49val1 = stat_variance(s1, opt1)
50val2 = stat_variance(s1, opt2)
51print*,'variances: ',val1,val2
52print*,'averages: ',opt1,opt2
53
54print*,'Checking variances with missing data'
55val1 = stat_variance(s3, opt1)
56val2 = stat_variance(s4, opt2)
57print*,'variances: ',val1,val2
58print*,'averages: ',opt1,opt2
59
60print*,'Checking linear correlation'
61val1 = stat_linear_corr(s1, s2, opt1, opt2, opt3, opt4)
62print*,'correlation: ',val1
63print*,'averages and variances: ', opt1, opt2, opt3, opt4
64IF (abs(val1+1.) > epsy) CALL exit(1)
65
66print*,'Checking linear correlation with missing data'
67val1 = stat_linear_corr(s3, s4, opt1, opt2, opt3, opt4)
68print*,'correlation: ',val1
69print*,'averages and variances: ', opt1, opt2, opt3, opt4
70IF (abs(val1+1.) > epsy) CALL exit(1)
71
72print*,'Checking linear regression'
73CALL stat_linear_regression(s1, s2, val1, val2)
74print*,'regression coefficients: ',val1,val2
75IF (abs(val1-15.) > epsy .OR. abs(val2+1.) > epsy) CALL exit(1)
76
77print*,'Checking linear regression with missing data'
78CALL stat_linear_regression(s3, s4, val1, val2)
79print*,'regression coefficients: ',val1,val2
80IF (abs(val1-15.) > epsy .OR. abs(val2+1.) > epsy) CALL exit(1)
81
82print*,'Checking percentiles'
83valv = stat_percentile(s2, (/0.,25.,50.,75.,100./))
84print*,'percentiles: ',valv
85IF (abs(valv(1)-s2(6)) > epsy) CALL exit(1)
86IF (abs(valv(5)-s2(1)) > epsy) CALL exit(1)
87
88print*,'Checking percentiles with missing data'
89valv = stat_percentile(s3, (/0.,25.,50.,75.,100./))
90print*,'percentiles: ',valv
91IF (abs(valv(1)-s3(2)) > epsy) CALL exit(1)
92IF (abs(valv(5)-s3(5)) > epsy) CALL exit(1)
93
94print*,'Checking binning'
95CALL stat_bin(s1, bin, 4, 3.5, 11.5)
96print*,'bin population: ',bin
97IF (any(bin /= (/1,2,2,1/))) CALL exit(1)
98CALL stat_bin(s2, bin, 4, 3.5, 11.5)
99print*,'bin population: ',bin
100IF (any(bin /= (/1,2,2,1/))) CALL exit(1)
101
102print*,'Checking binning with missing data'
103CALL stat_bin(s3, bin, 4, 3.5, 11.5)
104print*,'bin population: ',bin
105IF (any(bin /= (/0,2,2,0/))) CALL exit(1)
106CALL stat_bin(s4, bin, 4, 3.5, 11.5)
107print*,'bin population: ',bin
108IF (any(bin /= (/0,1,1,0/))) CALL exit(1)
109
110print*,'Checking mode'
111val1 = stat_mode_histogram(s1, 4, 3.5, 11.5)
112print*,'mode: ',val1
113IF (abs(val1-6.5) > epsy) CALL exit(1)
114val1 = stat_mode_histogram(s2, 4, 3.5, 11.5)
115print*,'mode: ',val1
116IF (abs(val1-6.5) > epsy) CALL exit(1)
117
118print*,'Checking mode with missing data'
119val1 = stat_mode_histogram(s3, 4, 3.5, 11.5)
120print*,'mode: ',val1
121IF (abs(val1-6.5) > epsy) CALL exit(1)
122val1 = stat_mode_histogram(s4, 4, 3.5, 11.5)
123print*,'mode: ',val1
124IF (abs(val1-6.5) > epsy) CALL exit(1)
125
126END PROGRAM simple_stat_test
Compute the average of the random variable provided, taking into account missing data.
Bin a sample into equally spaced intervals to form a histogram.
Compute the linear correlation coefficient between the two random variables provided,...
Compute the linear regression coefficients between the two random variables provided,...
Compute the mode of the random variable provided taking into account missing data.
Compute a set of percentiles for a random variable.
Compute the variance of the random variable provided, taking into account missing data.
Definitions of constants and functions for working with missing values.
Module for basic statistical computations taking into account missing data.

Generated with Doxygen.