John Travis

Mississippi College

MATH 353 - Introduction to Mathematical Probability and Statistics

Textbook:  Tanis and Hogg, A Brief Course in Mathematical Statistics

 

Conditional vs independent events

{{{id=1| %auto var('Ace Clubs Diamonds Hearts Jack King Queen Spades') suits = [Spades, Diamonds, Clubs, Hearts] values = [2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace] deck = [(value, suit) for suit in suits for value in values] full_deck = copy(deck) # to save a copy of the original deck for later use. pretty_print(html('Consider the full standard deck of 52 cards as a collection of ordered pairs (face,suit)')) for value in values: show([(value,suit) for suit in suits]) /// Consider the full standard deck of 52 cards as a collection of ordered pairs (face,suit) }}}

Let's consider the difference between picking two cards with replacement vs picking two cards without replacement.

{{{id=12| %auto print "Conditional Events - successively deal 5 cards w/o replacement" deck1 = copy(full_deck) history1=[] @interact def _(choice=['Hearts','Spades','Diamonds','Clubs','New Deck']): global deck1, history1 shuffle(deck1) if choice=='Hearts': suit = Hearts elif choice=='Spades': suit = Spades elif choice=='Diamonds': suit = Diamonds elif choice=='Clubs': suit = Clubs else: deck1 = copy(full_deck) shuffle(deck1) history1=[] if (Set(deck1).cardinality()<5): pretty_print('Deck is too small...get a new deck') elif choice<>'New Deck': hand = [deck1.pop() for card in range(5)] print "Click on a desired suit above to deal out another 5 card hand. The cards dealt:" show(hand) print "The remaining cards in the deck:" print deck1 num = Set(deck1).cardinality() pretty_print("\nThe number of remaining cards in the deck = %s"%str(num)) looking = [] for card in deck1: if card[1]==suit: looking.append(card) prob = float(Set(looking).cardinality())/num history1.append(prob) pretty_print('So, the remaining probability of getting a card from '+choice+' from the remaining cards is %s'%str(prob)) list_plot(history1).show(xmin=0,xmax=9,ymin=0,ymax=1,figsize=(5,2)) /// Conditional Events - successively deal 5 cards w/o replacement
choice 
}}}

Notice that the probability changes of getting a card from a given suit changes as progressive hands are dealt if the cards are not replaced before redealing.

{{{id=10| %auto print "Independent Events - Successively deal 5 cards but WITH replacement" #deck1 = copy(full_deck) history2=[] @interact def _(choice=['Heart','Spade','Diamond','Club']): if choice=='Hearts': suit = Hearts elif choice=='Spades': suit = Spades elif choice=='Diamonds': suit = Diamonds else: suit = Clubs deck1 = copy(full_deck) shuffle(deck1) hand = [deck1.pop() for card in range(5)] print "The cards dealt:" show(hand) print "Replacing this hand and reshuffling gives the remaining cards in the deck:" deck1 = copy(full_deck) shuffle(deck1) print(deck1) num = Set(deck1).cardinality() pretty_print("\nThe number of remaining cards in the deck = %s"%str(num)) looking = [] for card in deck1: if card[1]==suit: looking.append(card) prob = float(Set(looking).cardinality())/num history2.append(prob) pretty_print('So, the remaining probability of getting a '+choice+' from the remaining cards is %s'%str(prob)) list_plot(history2).show(xmin=0,xmax=9,ymin=0,ymax=1,figsize=(5,2)) /// Independent Events - Successively deal 5 cards but WITH replacement
choice 
}}}

The stuff below is just playing around with sampling.  Don't bother with this right now.

 

Events are independent provided the occurance of a first event does not likelihood of a subsequent event. 

Create an interact which picks random integers from 1 to 10 and then picks another random number from 1 to 10.

Two cases: 

{{{id=8| @interact def _(n = slider(10,2000,30,10,label='Number of samples')): Samples = range(n) max_pt=20 Domain = range(max_pt) A = [ZZ(int(max_pt*(random()))) for i in Samples] A1 = IndexedSequence(A,Samples) F = frequency_distribution(A) show(F) # G = points((x,F(x)) for x in Domain) G = A1.plot_histogram(eps=0.45,clr='green') G.show(ymin=0,ymax = max_pt,figsize=(10,3)) /// }}} {{{id=4| low = 0 high = 10 @interact def _(n=slider(1,100,1,label='Number of Trials'),replace=checkbox(false,label='With replacement?')): A = random_matrix(ZZ, 1, n, x=1, y=high+1) A1= zero_matrix(1,high) print A1 for k in range(1,high+1): print 'hi' temp = A(k) A1(temp) = A1(temp)+1 print A1 R = [low..high] A = IndexedSequence(A,R) G=A.plot_histogram(eps=0.5,clr='green') show(G,ymin=0) /// }}} {{{id=14| /// }}}