Changeset 36303 in project
- Timestamp:
- 08/17/18 06:48:42 (16 months ago)
- Location:
- release/5/statistics/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
release/5/statistics/trunk/statistics.egg
r36274 r36303 7 7 (build-dependencies compile-file srfi-13 ) 8 8 (dependencies srfi-1 srfi-25 srfi-69 vector-lib) 9 (test-dependencies test )9 (test-dependencies test srfi-1) 10 10 (components (extension statistics (custom-build "build.sh")))) 11 11 -
release/5/statistics/trunk/statistics.scm
r36274 r36303 178 178 ) 179 179 180 (import scheme (chicken base) (chicken foreign) (chicken format) (chicken keyword) (chicken sort)) 181 (import srfi-1 182 (only srfi-13 string<) 183 srfi-25 184 srfi-69 185 vector-lib) 180 (import scheme (chicken base) (chicken foreign) (chicken format) (chicken keyword) (chicken sort) 181 srfi-1 (only srfi-13 string<) srfi-25 srfi-69 vector-lib) 186 182 187 183 ;; --------------------------------------------------------------------------- … … 1496 1492 (t-test (/ b (sqrt (/ res-ms Lxx)))) 1497 1493 (t-sign (t-significance t-test (- n 2) #:tails ':both))) 1498 (format #t "~%Intercept = ~ f, slope = ~f, r = ~f, R^2 = ~f, p = ~f~%"1494 (format #t "~%Intercept = ~A, slope = ~A, r = ~A, R^2 = ~A, p = ~A~%" 1499 1495 a b r r2 t-sign) 1500 1496 (values a b r r2 t-sign)))) -
release/5/statistics/trunk/tests/run.scm
r36274 r36303 1 1 ;; some tests for statistics package 2 2 3 (import test statistics )3 (import test statistics srfi-1) 4 4 5 5 ;; -- to help the tests … … 121 121 ) 122 122 123 (print (binomial-probability 10 0 0.5)) 124 125 123 126 (test-group "distributional functions" 124 127 125 (test-ec (: pair '((0 0.0009765625) (1 0.009765625) (2 0.0439453125) (3 0.1171875) 126 (4 0.205078125) (5 0.24609375) (6 0.205078125) 127 (7 0.1171875) (8 0.0439453125) (9 0.009765625) 128 (10 0.0009765625))) 129 (binomial-probability 10 (car pair) 0.5) 130 (=> =5) (cadr pair)) 131 132 (test-ec (: pair '((0 0.0) (1 0.0009765625) (2 0.0107421875) (3 0.0546875) 128 (test-assert "binomial-probability" 129 (every 130 (lambda (pair) 131 (=5 (binomial-probability 10 (car pair) 0.5) (cadr pair))) 132 '((0 0.0009765625) (1 0.009765625) (2 0.0439453125) (3 0.1171875) 133 (4 0.205078125) (5 0.24609375) (6 0.205078125) 134 (7 0.1171875) (8 0.0439453125) (9 0.009765625) 135 (10 0.0009765625)))) 136 137 138 (test-assert "binomial-cumulative-probability" 139 (every 140 (lambda (pair) 141 (=5 (binomial-cumulative-probability 10 (car pair) 0.5) (cadr pair))) 142 '((0 0.0) (1 0.0009765625) (2 0.0107421875) (3 0.0546875) 133 143 (4 0.171875) (5 0.376953125) (6 0.623046875) 134 144 (7 0.828125) (8 0.9453125) (9 0.9892578125) 135 (10 0.9990234375))) 136 (binomial-cumulative-probability 10 (car pair) 0.5) 137 (=> =5) (cadr pair)) 138 139 (test-ec (: pair '((0 0.0000) (1 0.0005) (2 0.0023) (3 0.0076) (4 0.0189) (5 0.0378) 140 (6 0.0631) (7 0.0901) (8 0.1126) (9 0.1251) (10 0.1251) 141 (11 0.1137) (12 0.0948) (13 0.0729) (14 0.0521) 142 (15 0.0347) (16 0.0217) (17 0.0128) (18 0.0071) 143 (19 0.0037))) 144 (poisson-probability 10 (car pair)) 145 (=> =4) (cadr pair)) 146 147 (test-ec (: pair '((0 0.0000) (1 0.0000) (2 0.0005) (3 0.0028) (4 0.0103) (5 0.0293) 148 (6 0.0671) (7 0.1301) (8 0.2202) (9 0.3328) (10 0.4579) 149 (11 0.5830) (12 0.6968) (13 0.7916) (14 0.8645) 150 (15 0.9165) (16 0.9513) (17 0.9730) (18 0.9857) (19 0.9928))) 151 (poisson-cumulative-probability 10 (car pair)) 152 (=> =4) (cadr pair)) 153 154 (test-ec (: pair '((0 0.0088) (1 0.0270) (2 0.0648) (3 0.1210) (4 0.1760) 155 (5 0.1995) (6 0.1760) (7 0.1210) (8 0.0648) 156 (9 0.0270)(10 0.0088))) 157 (normal-pdf (car pair) 5 4) 158 (=> =4) (cadr pair)) 159 160 (test (convert-to-standard-normal 5 6 2) 161 => -1/2) 162 163 (test-ec (: pair '((-2.0 0.0228) (-1.6 0.0548) (-1.2 0.1151) (-0.8 0.2119) 164 (-0.4 0.3446) ( 0.0 0.5000) ( 0.4 0.6554) 165 ( 0.8 0.7881) ( 1.2 0.8849) ( 1.6 0.9452))) 166 (phi (car pair)) 167 (=> =4) (cadr pair)) 168 169 (test-ec (: pair '((0.1 -1.2815515713806909) (0.2 -0.8416212245351449))) 170 (z (car pair)) 171 (=> =5) (cadr pair)) 172 173 (test (t-distribution 1 0.9) 174 (=> =5) 3.07763671875) 175 176 (test (t-distribution 10 0.9) 177 (=> =5) 1.3721923828125) 178 179 (test (chi-square 10 0.4405) 180 (=> =5) 10) 181 182 (test (chi-square 3 0.1718) 183 (=> =5) 5) 184 185 (test (chi-square-cdf 10 10) 186 (=> =5) 0.559506714934786) 187 188 (test (chi-square-cdf 5 3) 189 (=> =5) 0.828202855703266) 145 (10 0.9990234375)))) 146 147 (test-assert "binomial-cumulative-probability" 148 (every 149 (lambda (pair) 150 (=4 (poisson-probability 10 (car pair)) (cadr pair))) 151 '((0 0.0000) (1 0.0005) (2 0.0023) (3 0.0076) (4 0.0189) (5 0.0378) 152 (6 0.0631) (7 0.0901) (8 0.1126) (9 0.1251) (10 0.1251) 153 (11 0.1137) (12 0.0948) (13 0.0729) (14 0.0521) 154 (15 0.0347) (16 0.0217) (17 0.0128) (18 0.0071) 155 (19 0.0037)))) 156 157 (test-assert "poisson-cumulative-probability" 158 (every 159 (lambda (pair) 160 (=4 (poisson-cumulative-probability 10 (car pair)) (cadr pair))) 161 '((0 0.0000) (1 0.0000) (2 0.0005) (3 0.0028) (4 0.0103) (5 0.0293) 162 (6 0.0671) (7 0.1301) (8 0.2202) (9 0.3328) (10 0.4579) 163 (11 0.5830) (12 0.6968) (13 0.7916) (14 0.8645) 164 (15 0.9165) (16 0.9513) (17 0.9730) (18 0.9857) (19 0.9928)))) 165 166 167 (test-assert "normal-pdf" 168 (every 169 (lambda (pair) 170 (=4 (normal-pdf (car pair) 5 4) (cadr pair))) 171 '((0 0.0088) (1 0.0270) (2 0.0648) (3 0.1210) (4 0.1760) 172 (5 0.1995) (6 0.1760) (7 0.1210) (8 0.0648) 173 (9 0.0270)(10 0.0088)))) 174 175 (test-assert "phi" 176 (every 177 (lambda (pair) 178 (=4 (phi (car pair)) (cadr pair))) 179 '((-2.0 0.0228) (-1.6 0.0548) (-1.2 0.1151) (-0.8 0.2119) 180 (-0.4 0.3446) ( 0.0 0.5000) ( 0.4 0.6554) 181 ( 0.8 0.7881) ( 1.2 0.8849) ( 1.6 0.9452)))) 182 183 (test-assert "z" 184 (every 185 (lambda (pair) 186 (=5 (z (car pair)) (cadr pair))) 187 '((0.1 -1.2815515713806909) (0.2 -0.8416212245351449)))) 188 189 (test "convert-to-standard-normal" 190 -1/2 191 (convert-to-standard-normal 5 6 2)) 192 193 (test-assert "t-distribution" 194 (=5 3.07763671875 195 (t-distribution 1 0.9))) 196 197 (test-assert "t-distribution" 198 (=5 1.3721923828125 199 (t-distribution 10 0.9))) 200 201 (test-assert "chi-square" 202 (=5 (chi-square 10 0.4405) 203 10)) 204 205 (test-assert "chi-square" 206 (=5 (chi-square 3 0.1718) 5)) 207 208 (test-assert "chi-square-cdf" 209 (=5 (chi-square-cdf 10 10) 210 0.559506714934786)) 211 212 (test-assert "chi-square-cdf" 213 (=5 (chi-square-cdf 5 3) 214 0.828202855703266)) 215 ) 216 217 (test-group "tests of confidence intervals" 218 219 (let-values (((upper-bound lower-bound) (binomial-probability-ci 10 0.8 0.9))) 220 (test-assert "binomial-probability-ci" (=5 upper-bound 0.724273681640625)) 221 (test-assert "binomial-probability-ci" (=5 lower-bound 0.851547241210938)) 222 ) 223 224 (let-values (((upper-bound lower-bound) (poisson-mu-ci 10 0.9))) 225 (test-assert "poisson-mu-ci" (=5 upper-bound 8.305419921875)) 226 (test-assert "poisson-mu-ci" (=5 lower-bound 10.0635986328125))) 227 228 (let-values (((upper-bound lower-bound) (normal-mean-ci 0.5 0.1 10 0.8))) 229 (test-assert "normal-mean-ci" (=5 upper-bound 0.491747852700165)) 230 (test-assert "normal-mean-ci" (=5 lower-bound 0.508252147299835))) 231 232 (let-values (((upper-bound lower-bound) (normal-mean-ci-on-sequence '(1 2 3 4 5) 0.9))) 233 (test-assert "normal-mean-ci-on-sequence" (=5 upper-bound 2.90535368828478)) 234 (test-assert "normal-mean-ci-on-sequence" (=5 lower-bound 3.09464631171522))) 190 235 ) 191 236 192 (test-group "tests of confidence intervals" 193 194 (let-values (((upper-bound lower-bound) (binomial-probability-ci 10 0.8 0.9))) 195 (test upper-bound (=> =5) 0.724273681640625) 196 (test lower-bound (=> =5) 0.851547241210938)) 197 198 (let-values (((upper-bound lower-bound) (poisson-mu-ci 10 0.9))) 199 (test upper-bound (=> =5) 8.305419921875) 200 (test lower-bound (=> =5) 10.0635986328125)) 201 202 (let-values (((upper-bound lower-bound) (normal-mean-ci 0.5 0.1 10 0.8))) 203 (test upper-bound (=> =5) 0.491747852700165) 204 (test lower-bound (=> =5) 0.508252147299835)) 205 206 (let-values (((upper-bound lower-bound) (normal-mean-ci-on-sequence '(1 2 3 4 5) 0.9))) 207 (test upper-bound (=> =5) 2.90535368828478) 208 (test lower-bound (=> =5) 3.09464631171522)) 209 210 ;; -- tests of hypothesis testing 211 212 (test (z-test 40 1 #:mu 50 #:sigma 10 #:tails ':negative) 213 (=> =5) 0.15865525) 214 (test (z-test 40 10 #:mu 50 #:sigma 10 #:tails ':negative) 215 (=> =5) 0.000783) 216 (test (z-test 40 5 #:mu 50 #:sigma 10) 217 (=> =5) 0.025347) 218 219 (test (z-test 11/5 5 #:mu 2 #:sigma 1) 220 (=> =5) 0.65472085) 221 222 (test (z-test-on-sequence '(1 1 2 3 4) #:mu 2 #:sigma 1) 223 (=> =5) 0.65472085) 224 225 (test (t-test-one-sample 5 0.8 3 6) 226 (=> =5) 0.162781641721079) 227 228 (test (t-test-one-sample-on-sequence '(5 6 7) 5.9) 229 (=> =5) 0.878433865229034) 230 231 (test (correlation-test-two-sample 0.9 100 0.85 50) 232 (=> =5) 0.224083300908794) 233 234 (test (t-test-paired 7/3 0.57735 3) 235 (=> =5) 0.0198039411803931) 236 237 (test (t-test-paired-on-sequences '(4 3 5) '(1 1 3)) 238 (=> =5) 0.0198039411803931) 239 240 ; correlation-test-two-sample-on-sequences 237 (test-group "hypothesis testing" 238 239 (test-assert "z-test" 240 (=5 (z-test 40 1 #:mu 50 #:sigma 10 #:tails ':negative) 241 0.15865525)) 242 (test-assert "z-test" 243 (=5 (z-test 40 10 #:mu 50 #:sigma 10 #:tails ':negative) 244 0.000783)) 245 (test-assert "z-test" 246 (=5 (z-test 40 5 #:mu 50 #:sigma 10) 247 0.025347)) 248 249 (test-assert "z-test" 250 (=5 (z-test 11/5 5 #:mu 2 #:sigma 1) 251 0.65472085)) 252 253 (test-assert "z-test-on-sequence" 254 (=5 (z-test-on-sequence '(1 1 2 3 4) #:mu 2 #:sigma 1) 255 0.65472085)) 256 257 (test-assert "t-test-one-sample" 258 (=5 (t-test-one-sample 5 0.8 3 6) 259 0.162781641721079)) 260 261 (test-assert "t-test-one-sample-on-sequence" 262 (=5 (t-test-one-sample-on-sequence '(5 6 7) 5.9) 263 0.878433865229034)) 264 265 (test-assert "correlation-test-two-sample" 266 (=5 (correlation-test-two-sample 0.9 100 0.85 50) 267 0.224083300908794)) 268 269 (test-assert "t-test-paired" 270 (=5 (t-test-paired 7/3 0.57735 3) 271 0.0198039411803931)) 272 273 (test-assert "t-test-paired-on-sequences" 274 (=5 (t-test-paired-on-sequences '(4 3 5) '(1 1 3)) 275 0.0198039411803931)) 276 277 ) 278 279 241 280 242 281 (let-values (((s p) (spearman-rank-correlation '((4 5) (10 8) (3 6) (1 2) (9 10) (2 3) (6 9) (7 4) (8 7) (5 1))))) 243 (test s (=> =5) (/ 113 165)) 244 (test p (=> =5) 0.0288827975067328)) 245 246 ;; -- tests of sample size estimates 247 248 (test (t-test-one-sample-sse 5.0 5.2 0.5) 249 => 163) 250 251 (let-values (((n1 n2) (t-test-two-sample-sse 5.1 0.5 5.2 0.3))) 252 (test n1 => 1040) 253 (test n2 => 1040)) 254 255 (test (correlation-sse 0.80 #:alpha 0.05 #:1-beta 0.9) 256 => 11) ;; NOTE: Not same as some on-line sites describe ... 257 258 ;; -- tests of correlation and regression 259 260 (let-values (((a b r r2 p) (linear-regression '((1.0 0.1) (2.0 0.3) (3.0 0.8))))) 261 (test a (=> =5) -0.3) 262 (test b (=> =5) 0.35) 263 (test r (=> =5) 0.970725343394151) 264 (test r2 (=> =5) 0.942307692307692) 265 (test p (=> =5) 0.154420958311267)) 266 267 (test (correlation-coefficient '((1.0 0.1) (2.0 0.3) (3.0 0.8))) 268 (=> =5) 0.970725343394151) 269 270 ;; -- tests of significance tests 271 272 (test (t-significance 0.2 5) 273 (=> =5) 0.849360513995829) 274 275 (test (t-significance 0.2 5 #:tails ':both) 276 (=> =5) 0.849360513995829) 277 278 (test (t-significance 0.2 5 #:tails ':positive) 279 (=> =5) 0.424680256997915) 280 281 (test (t-significance 0.2 5 #:tails ':negative) 282 (=> =5) 0.575319743002086) 283 284 (test (f-significance 1.5 8 2) 285 (=> =5) 0.920449812578091) 286 287 (test (f-significance 1.5 8 2 #:one-tailed? #t) 288 (=> =5) 0.460224906289046) 289 290 (test (binomial-test-two-sample 0.2 100 0.3 50) 291 (=> =5) 0.245930683028145) 292 293 (test (fisher-exact-test 10 20 30 40) 294 (=> =5) 0.5066621427235114) 295 296 (test (lambert-W0 1.0) 297 (=> =5) 0.567143290410) 298 299 (test (lambert-Wm1 1.0) 300 (=> =5) 0.567143290410) 282 (test-assert "spearman-rank-correlation" (=5 s (/ 113 165))) 283 (test-assert "spearman-rank-correlation" (=5 p 0.0288827975067328))) 284 285 (test-group "sample size estimates" 286 287 (test "t-test-one-sample-sse" 163 (t-test-one-sample-sse 5.0 5.2 0.5)) 288 289 (let-values (((n1 n2) (t-test-two-sample-sse 5.1 0.5 5.2 0.3))) 290 (test "t-test-two-sample-sse" 1040 n1) 291 (test "t-test-two-sample-sse" 1040 n2)) 292 293 (test "correlation-sse" 11 (correlation-sse 0.80 #:alpha 0.05 #:1-beta 0.9)) 294 ) ;; NOTE: Not same as some on-line sites describe ... 295 296 (test-group "correlation and regression" 297 298 (let-values (((a b r r2 p) (linear-regression '((1.0 0.1) (2.0 0.3) (3.0 0.8))))) 299 (test "linear-regression" -0.3 a) 300 (test-assert "linear-regression" (=5 b 0.35)) 301 (test-assert "linear-regression" (=5 r 0.970725343394151)) 302 (test-assert "linear-regression" (=5 r2 0.942307692307692)) 303 (test-assert "linear-regression" (=5 p 0.154420958311267)) 304 ) 305 306 (test-assert "correlation-coefficient" 307 (=5 0.970725343394151 (correlation-coefficient '((1.0 0.1) (2.0 0.3) (3.0 0.8))))) 308 ) 309 310 (test-group "significance tests" 311 312 (test-assert "t-significance" (=5 (t-significance 0.2 5) 0.849360513995829)) 313 314 (test-assert "t-significance" (=5 (t-significance 0.2 5 #:tails ':both) 0.849360513995829)) 315 316 (test-assert "t-significance" (=5 (t-significance 0.2 5 #:tails ':positive) 0.424680256997915)) 317 318 (test-assert "t-significance" (=5 (t-significance 0.2 5 #:tails ':negative) 0.575319743002086)) 319 320 (test-assert "f-significance" (=5 (f-significance 1.5 8 2) 0.920449812578091)) 321 322 (test-assert "f-significance" (=5 (f-significance 1.5 8 2 #:one-tailed? #t) 0.460224906289046)) 323 324 (test-assert "binomial-test-two-sample" (=5 (binomial-test-two-sample 0.2 100 0.3 50) 0.245930683028145)) 325 326 (test-assert "fisher-exact-test" (=5 (fisher-exact-test 10 20 30 40) 0.5066621427235114)) 327 328 (test-assert "lambert-W0" (=5 (lambert-W0 1.0) 0.567143290410)) 329 330 (test-assert "lambert-Wm1" (=5 (lambert-Wm1 1.0) 0.567143290410)) 331 ) 301 332 302 333 (test-exit)
Note: See TracChangeset
for help on using the changeset viewer.