#!/usr/bin/env python # ----------------------------------------------------------------------------------- # # # ROOT macro for exercise on planning experiment. # # You are planning the "Lady Tasting Tea" experiment, serving 10 cups of tea (or # whatever you're testing). However, you are wondering, if you experiment is good # enough, and would like to improve on it (also beyond simply tasting tea). # # Author: Troels C. Petersen (NBI) # Email: petersen@nbi.dk # Date: 21st of October 2013 # # ----------------------------------------------------------------------------------- # from ROOT import * from array import array # Setting what to be shown in statistics box: gStyle.SetOptStat("emr") gStyle.SetOptFit(1111) verbose = True Nverbose = 10 r = TRandom3() r.SetSeed(93) SaveFigures = false Nexperiments = 100 Ntests = 10 Hist_Ncorrect = TH1F("Hist_Ncorrect", "Hist_Ncorrect", Ntests+1, -0.5, Ntests+0.5) # ------------------------------------------------------------------ # # Loop over number of experiments and make random choices: # ------------------------------------------------------------------ # for iexp in range (Nexperiments) : # Make Ntests tests of a random number: Ncorrect = 0 for itest in range (Ntests) : if (r.Uniform() > 0.5) : Ncorrect += 1 Hist_Ncorrect.Fill(Ncorrect) # ------------------------------------------------------------------ # # Show the distribution of results: # ------------------------------------------------------------------ # c0 = TCanvas("c0","", 20, 50, 600, 400) Hist_Ncorrect.GetXaxis().SetTitle("Number of correct answers") Hist_Ncorrect.GetYaxis().SetTitle("Frequency") Hist_Ncorrect.SetLineWidth(2) Hist_Ncorrect.SetLineColor(2) Hist_Ncorrect.Draw() c0.Update() if (SaveFigures) : c0.SaveAs("TestResult.png") raw_input( ' ... Press enter to exit ... ' ) # ----------------------------------------------------------------------------------- # # # Before starting looking at the program, sit down and calculate (either in hand, or # as a section in the beginning of this program) the probabilities of the outcome of # a 10-cup lady-tasting-tea experiment. Such a calculation is always healthy to get # a feel for the sensitivity of the experiment. # # Questions: # ---------- # 1) What is the chance that a person choosing at random gets all 10 tastings correct? # And given that this actually happens once in the above program, would you claim, # that I chose the "random" seed deliberately and not at random? # # 2) In the above example, each test is random, and there is no knowledge of how many # of each sample is being tested. How does the test change, when it is known, that # half of the samples are of one type and the other half of the opposite type? # # 3) Imagine that you are now conducting a beer tasting! You friend made the (drunk?) # claim, that he could always recognize a "Groen Tuborg". You decide to design an # experiment that can test this hypothesis. How would you do this? # - How sure do you want to be on the result? (i.e. p-value of all correct) # - How many types of beer would you use? # - What if you want to allow for one (or more) wrong identifications? # - How many times should your friend taste a beer sample? # - Will you tell him ahead of time, how many of each sample there are? # # 4) Imagine a prominent professor at NBI making a similar claim about sushi? You # can only ask him to taste 12 times (that is a full lunch, and you can not # afford more). If you get three samples, four from each restaurant, and you # allow for up to one misidentification, how sure can you be, that his claim is # reasonable? I.e. what is the p-value for a random guess to get 11 or 12 correct? # Calculate this both analytically and using a Monte Carlo simulation. # # ----------------------------------------------------------------------------------- #