/* Hypothesis testing in Picat. From Statistics101 (Resample Stats) http://www.statistics101.net/QuickReference.pdf Page 46 """ Here is another example of hypothesis testing, this one taken from CliffsQuickReview Statistics p. 80, example 5: “A professor wants to know if her introductory statistics class has a good grasp of basic math. Six students are chosen at random from the class and given a math proficiency test. The professor wants the class to be able to score at least 70 on the test. The six students get scores of 62 92 75 68 83 95. Can the professor be at least 90 percent certain that the mean score for the class on the test would be at least 70?” -> probability: 0.0304 """ Cf my Gamble model gamble_hypothesis_testing2.rkt This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import ppl_distributions, ppl_utils. import util. % import ordset. main => go. /* mean = 79.3167 var : m Probabilities (truncated): 79.316666666666663: 0.0166000000000000 81.316666666666663: 0.0108000000000000 79.816666666666663: 0.0105000000000000 77.316666666666663: 0.0103000000000000 ......... 68.25: 0.0001000000000000 67.749999999999986: 0.0001000000000000 66.249999999999986: 0.0001000000000000 63.75: 0.0001000000000000 mean = 79.4332 Percentiles: (0.001 65.766350000000003) (0.01 68.63333333333334) (0.025 69.966666666666654) (0.05 71.299999999999997) (0.1 73.149999999999991) (0.25 76) (0.5 79.466666666666654) (0.75 82.799999999999997) (0.84 84.166666666666671) (0.9 85.649999999999991) (0.95 87.166666666666671) (0.975 88.666666666666671) (0.99 90.166666666666671) (0.999 93) (0.9999 94.000049999999646) (0.99999 94.450005000000601) HPD intervals: HPD interval (0.9): 71.95000000000000..87.64999999999999 Histogram (total 10000) 63.750: 1 (0.000 / 0.000) 64.519: 3 (0.000 / 0.000) 65.287: 6 # (0.001 / 0.001) 66.056: 11 # (0.001 / 0.002) 66.825: 19 ## (0.002 / 0.004) 67.594: 28 ### (0.003 / 0.007) 68.362: 43 #### (0.004 / 0.011) 69.131: 84 ######## (0.008 / 0.019) 69.900: 105 ########## (0.011 / 0.030) 70.669: 110 ########## (0.011 / 0.041) 71.438: 187 ################## (0.019 / 0.060) 72.206: 198 ################### (0.020 / 0.080) 72.975: 316 ############################## (0.032 / 0.111) 73.744: 296 ############################ (0.030 / 0.141) 74.513: 407 ###################################### (0.041 / 0.181) 75.281: 439 ######################################### (0.044 / 0.225) 76.050: 384 #################################### (0.038 / 0.264) 76.819: 579 ###################################################### (0.058 / 0.322) 77.588: 596 ######################################################## (0.060 / 0.381) 78.356: 590 ####################################################### (0.059 / 0.440) 79.125: 640 ############################################################ (0.064 / 0.504) 79.894: 579 ###################################################### (0.058 / 0.562) 80.662: 617 ########################################################## (0.062 / 0.624) 81.431: 505 ############################################### (0.051 / 0.674) 82.200: 558 #################################################### (0.056 / 0.730) 82.969: 623 ########################################################## (0.062 / 0.792) 83.737: 357 ################################# (0.036 / 0.828) 84.506: 414 ####################################### (0.041 / 0.869) 85.275: 307 ############################# (0.031 / 0.900) 86.044: 270 ######################### (0.027 / 0.927) 86.812: 240 ####################### (0.024 / 0.951) 87.581: 123 ############ (0.012 / 0.963) 88.350: 142 ############# (0.014 / 0.978) 89.119: 73 ####### (0.007 / 0.985) 89.888: 57 ##### (0.006 / 0.991) 90.656: 45 #### (0.004 / 0.995) 91.425: 17 ## (0.002 / 0.997) 92.194: 19 ## (0.002 / 0.999) 92.963: 6 # (0.001 / 0.999) 93.731: 6 # (0.001 / 1.000) var : p Probabilities: false: 0.9717000000000000 true: 0.0283000000000000 mean = [false = 0.9717,true = 0.0283] Percentiles: (0.001 false) (0.01 false) (0.025 false) (0.05 false) (0.1 false) (0.25 false) (0.5 false) (0.75 false) (0.84 false) (0.9 false) (0.95 false) (0.975 true) (0.99 true) (0.999 true) (0.9999 true) (0.99999 true) HPD intervals: show_hpd_intervals: data is not numeric Histogram (total 10000) false : 9717 ############################################################ (0.972 / 0.972) true : 283 ## (0.028 / 1.000) */ go ?=> Scores = [62.9,92.0,75.0,68.0,83.0,95.0], println(mean=Scores.mean), reset_store, run_model(10_000,$model(Scores),[show_probs_trunc,mean, show_percentiles, show_hpd_intervals,hpd_intervals=[0.9], show_histogram % min_accepted_samples=1000,show_accepted_samples=true ]), nl, % show_store_lengths,nl, % fail, nl. go => true. model(Scores) => Sample = resample(Scores), M = Sample.mean, % What is the probability of a mean < 70 P = check(M < 70), add("m",M), add("p",P).