| 1 | /// \ingroup newran |
| 2 | ///@{ |
| 3 | |
| 4 | /// \file test_out.cpp |
| 5 | /// Statistical tests - bodies. |
| 6 | |
| 7 | |
| 8 | // *************** classes for carrying out tests *********************** // |
| 9 | |
| 10 | // definitions of library classes and function |
| 11 | |
| 12 | #define WANT_MATH |
| 13 | #define WANT_STREAM |
| 14 | |
| 15 | #include "include.h" |
| 16 | #include "str.h" |
| 17 | #include "utility.h" |
| 18 | #include "test_out.h" |
| 19 | #include "format.h" |
| 20 | |
| 21 | #ifdef use_namespace |
| 22 | using namespace NEWRAN; |
| 23 | using namespace RBD_STRING; |
| 24 | using namespace RBD_COMMON; |
| 25 | #endif |
| 26 | |
| 27 | |
| 28 | const char* BaseTest::Header = |
| 29 | "Test distrib. param. 1 param. 2 statistic n. stat. -lg sig"; |
| 30 | |
| 31 | void BaseTest::WrapUp(double sig_prob) |
| 32 | { |
| 33 | SigProb = sig_prob; |
| 34 | |
| 35 | if (sig_prob == 0.0) cout << " 9999 "; |
| 36 | |
| 37 | else if (sig_prob <= 0.1) |
| 38 | { |
| 39 | |
| 40 | Format F6; F6.FormatType(Format::DEC_FIGS); |
| 41 | F6.Width(6); F6.Precision(2); F6.Suffix(" "); |
| 42 | cout << F6 << -log10(sig_prob); |
| 43 | } |
| 44 | else cout << " < 1 "; |
| 45 | |
| 46 | if (sig_prob <= 0.001) cout << "***"; |
| 47 | else if (sig_prob <= 0.01) cout << "** "; |
| 48 | else if (sig_prob <= 0.05) cout << "* "; |
| 49 | else cout << " "; |
| 50 | |
| 51 | cout << endl; |
| 52 | } |
| 53 | |
| 54 | void NormalTestUpper::DoTest() |
| 55 | { |
| 56 | double sd = sqrt(Var); |
| 57 | double nts = (Statistic - Mean) / sd; |
| 58 | Format S12; S12.Width(12); S12.Suffix(" "); S12.Alignment(Format::LEFT); |
| 59 | Format F10; |
| 60 | F10.FormatType(Format::SIG_FIGS); |
| 61 | F10.Precision(5); F10.Width(10); F10.Suffix(" "); |
| 62 | Format D10; |
| 63 | D10.FormatType(Format::DEC_FIGS); |
| 64 | D10.Precision(5); D10.Width(10); D10.Suffix(" "); |
| 65 | cout << S12 << LongName; |
| 66 | cout << "Norm. (up) "; |
| 67 | cout << F10 << Mean << sd << Statistic << D10 << nts; |
| 68 | |
| 69 | WrapUp(cdfnml(-nts)); |
| 70 | } |
| 71 | |
| 72 | void NormalTestTwoSided::DoTest() |
| 73 | { |
| 74 | double sd = sqrt(Var); |
| 75 | double nts = (Statistic - Mean) / sd; |
| 76 | Format S12; S12.Width(12); S12.Suffix(" "); S12.Alignment(Format::LEFT); |
| 77 | Format F10; |
| 78 | F10.FormatType(Format::SIG_FIGS); |
| 79 | F10.Precision(5); F10.Width(10); F10.Suffix(" "); |
| 80 | Format D10; |
| 81 | D10.FormatType(Format::DEC_FIGS); |
| 82 | D10.Precision(5); D10.Width(10); D10.Suffix(" "); |
| 83 | cout << S12 << LongName; |
| 84 | cout << "Norm. (2s) "; |
| 85 | cout << F10 << Mean << sd << Statistic << D10 << nts; |
| 86 | WrapUp(2.0 * cdfnml(-fabs(nts))); |
| 87 | } |
| 88 | |
| 89 | void ChiSquaredTestUpper::DoTest() |
| 90 | { |
| 91 | double nts = (Statistic - DF) / sqrt((Real)(2 * DF)); |
| 92 | Format S12; S12.Width(12); S12.Suffix(" "); S12.Alignment(Format::LEFT); |
| 93 | Format F10; |
| 94 | F10.FormatType(Format::SIG_FIGS); |
| 95 | F10.Precision(5); F10.Width(10); F10.Suffix(" "); |
| 96 | Format D10; |
| 97 | D10.FormatType(Format::DEC_FIGS); |
| 98 | D10.Precision(5); D10.Width(10); D10.Suffix(" "); |
| 99 | Format I10; |
| 100 | I10.FormatType(Format::INTEGER); |
| 101 | I10.Precision(5); I10.Width(10); I10.Suffix(" "); |
| 102 | cout << S12 << LongName; |
| 103 | cout << "Chisq (up) "; |
| 104 | cout << I10 << DF << "" << F10 << Statistic << D10 << nts; |
| 105 | WrapUp(cdf_chisq(Statistic, DF, true)); |
| 106 | } |
| 107 | |
| 108 | void ChiSquaredTestLower::DoTest() |
| 109 | { |
| 110 | double nts = (Statistic - DF) / sqrt((Real)(2 * DF)); |
| 111 | Format S12; S12.Width(12); S12.Suffix(" "); S12.Alignment(Format::LEFT); |
| 112 | Format F10; |
| 113 | F10.FormatType(Format::SIG_FIGS); |
| 114 | F10.Precision(5); F10.Width(10); F10.Suffix(" "); |
| 115 | Format D10; |
| 116 | D10.FormatType(Format::DEC_FIGS); |
| 117 | D10.Precision(5); D10.Width(10); D10.Suffix(" "); |
| 118 | Format I10; |
| 119 | I10.FormatType(Format::INTEGER); |
| 120 | I10.Precision(5); I10.Width(10); I10.Suffix(" "); |
| 121 | cout << S12 << LongName; |
| 122 | cout << "Chisq (up) "; |
| 123 | cout << I10 << DF << "" << F10 << Statistic << D10 << nts; |
| 124 | WrapUp(cdf_chisq(Statistic, DF, false)); |
| 125 | } |
| 126 | |
| 127 | void ChiSquaredTestTwoSided::DoTest() |
| 128 | { |
| 129 | double nts = (Statistic - DF) / sqrt((Real)(2 * DF)); |
| 130 | Format S12; S12.Width(12); S12.Suffix(" "); S12.Alignment(Format::LEFT); |
| 131 | Format F10; |
| 132 | F10.FormatType(Format::SIG_FIGS); |
| 133 | F10.Precision(5); F10.Width(10); F10.Suffix(" "); |
| 134 | Format D10; |
| 135 | D10.FormatType(Format::DEC_FIGS); |
| 136 | D10.Precision(5); D10.Width(10); D10.Suffix(" "); |
| 137 | Format I10; |
| 138 | I10.FormatType(Format::INTEGER); |
| 139 | I10.Precision(5); I10.Width(10); I10.Suffix(" "); |
| 140 | cout << S12 << LongName; |
| 141 | cout << "Chisq (2s) "; |
| 142 | cout << I10 << DF << "" << F10 << Statistic << D10 << nts; |
| 143 | double Up = cdf_chisq(Statistic, DF, true); |
| 144 | double Lo = cdf_chisq(Statistic, DF, false); |
| 145 | WrapUp(2.0 * (Lo < Up ? Lo : Up)); |
| 146 | } |
| 147 | |
| 148 | void QuasiUniformLower::DoTest() |
| 149 | { |
| 150 | Format S12; S12.Width(12); S12.Suffix(" "); S12.Alignment(Format::LEFT); |
| 151 | Format F10; |
| 152 | F10.FormatType(Format::SIG_FIGS); |
| 153 | F10.Precision(5); F10.Width(10); F10.Suffix(" "); |
| 154 | cout << S12 << LongName; |
| 155 | cout << "Q.U. (lo) "; |
| 156 | cout << F10 << "" << "" << Statistic << ""; |
| 157 | |
| 158 | WrapUp(Statistic); |
| 159 | } |
| 160 | |
| 161 | void UniformLower::DoTest() |
| 162 | { |
| 163 | Format S12; S12.Width(12); S12.Suffix(" "); S12.Alignment(Format::LEFT); |
| 164 | Format D10; |
| 165 | D10.FormatType(Format::DEC_FIGS); |
| 166 | D10.Precision(5); D10.Width(10); D10.Suffix(" "); |
| 167 | cout << S12 << LongName; |
| 168 | cout << "Unif. (lo) "; |
| 169 | cout << D10 << "" << "" << Statistic << ""; |
| 170 | |
| 171 | WrapUp(Statistic); |
| 172 | } |
| 173 | |
| 174 | void KS_Upper::DoTest() |
| 175 | { |
| 176 | Format S12; S12.Width(12); S12.Suffix(" "); S12.Alignment(Format::LEFT); |
| 177 | Format D10; |
| 178 | D10.FormatType(Format::DEC_FIGS); |
| 179 | D10.Precision(5); D10.Width(10); D10.Suffix(" "); |
| 180 | cout << S12 << LongName; |
| 181 | cout << "K.S. (up) "; |
| 182 | cout << D10 << "" << "" << Statistic << ""; |
| 183 | |
| 184 | WrapUp(KS_probabilities(Statistic)); |
| 185 | } |
| 186 | |
| 187 | ///@} |
| 188 |