Lab 7. Binomial Probability Lab 7. Binomial Probability Introduction In this lab we are going to be using binomial probability to determine whether or not heads is a better choice than tails for any...

1 answer below »
just aswers


Lab 7. Binomial Probability Lab 7. Binomial Probability Introduction In this lab we are going to be using binomial probability to determine whether or not heads is a better choice than tails for any particular coin. First, I will walk you through a hypothetical scenario and then you will flip a coin of your choice and test to see whether with that coin your probabilities really are 50-50 for heads or tails. …honestly this lab really is just about how to find the coin that is the easiest for you to cheat with. Your future self will thank me when you start winning a much larger number of coin tosses! Learning Outcomes By the end of today’s class you should be able to do the following in R: · Use the dbinom() function to calculate probability · Use the geom_bar() function to make a bar plot · Use the geom_line() function to make a probability function · Use the melt() function from the reshape2 package to turn wide-format data into long-format data · Determine if the coins in your pocket really do have fair odds or not Part 1: My Coin Flip Part 1.1 My Data To start with, we are going to look at a hypothetical scenario: where I flipped a quarter 10 times and got heads 9 times. I am going to save my results as a variable named Heads and a variable named Tails. Heads = 9 Tails = 1 Part 1.2 Plotting It I would like to make a bar plot of my data, looking at what I got compared to what I would expect normally with a coin that has 50-50 odds for either side (so, 5 Tails, 5 Heads). To do that I’m going to make a data frame using the data.frame() function. This function will have three columns: Type (whether it was expected or what I actually measured), Heads (the number of heads expected and measured), and Tails (the number of tails expected and measured). Use the c()function to make these columns. mycoin <- data.frame(type="c("Expected"," "got"),="" heads="c(5," heads),="" tails="c(5," tails))="" what="" we="" have="" just="" made="" is="" called="" wide="" format="" data,="" where="" we="" have="" a="" lot="" of="" columns="" and="" very="" few="" variables.="" to="" plot="" this="" using="" ggplot2="" we="" need="" to="" make="" it="" into="" long="" format="" data.="" the="" easiest="" way="" to="" do="" that="" is="" to="" use="" the="" reshape2="" package,="" which="" as="" its="" name="" suggests="" is="" intended="" to="" help="" you="" reshape="" data.="" you="" will="" need="" to="" install="" it="" first="" and="" then="" load="" the="" library.="" install.packages("reshape2")="" library("reshape2")="" to="" turn="" your="" data="" from="" wide="" format="" into="" long="" format="" you="" need="" to="" use="" the="" melt()="" function.="" the="" results="" of="" this="" function="" is="" you="" have="" a="" long="" format="" data="" set="" that="" has="" two="" new="" column="" names:="" variable="" and="" value.="" longcoins=""><- melt(mycoin)="" now="" we="" can="" use="" ggplot2="" to="" create="" a="" barplot="" of="" our="" data.="" don’t="" forget="" to="" load="" your="" library!="" library("ggplot2")="" use="" the="" stat="identity" and="" position="dodge" arguments="" to="" separate="" out="" your="" groups="" nicely.="" ggplot(longcoins,="" aes(x="variable," y="value," fill="Type))+" geom_bar(stat="identity" ,="" position="dodge" )="" part="" 1.3="" actual="" probability="" in="" my="" example,="" i="" flipped="" a="" coin="" 10="" times="" and="" heads="" came="" up="" nine="" times.="" is="" that="" actually="" unusual?="" or="" is="" that="" something="" you="" could="" reasonably="" expect="" by="" random="" chance?="" to="" find="" out,="" we="" are="" going="" to="" use="" the="" dbinom()="" function.="" this="" function="" takes="" several="" arguments:="" ·="" the="" number="" of="" successes="" (defined="" here="" as="" the="" number="" of="" heads)="" ·="" the="" total="" number="" of="" trials="" a.k.a.="" the="" number="" of="" times="" i="" flipped="" the="" coin="" ·="" the="" probability="" of="" success="" (or="" getting="" heads)="" in="" order,="" these="" are="" x,="" size,="" and="" prob.="" dbinom(x="Heads," size="10," prob=".5)" this="" gives="" you="" the="" exact="" probability="" of="" getting="" 9/10="" as="" heads.="" question="" 1:="" what="" is="" the="" probability="" of="" getting="" a="" single="" heads="" out="" of="" 10="" tosses?="" use="" dbinom()="" to="" find="" your="" answer="" 1.="" 0.001="" 1.="" 0.05="" 1.="" 0.009="" 1.="" 0.1="" just="" like="" any="" other="" data,="" binomial="" data="" has="" a="" probability="" distribution.="" essentially,="" given="" the="" number="" of="" trials="" that="" you="" have,="" how="" likely="" is="" it="" to="" get="" eight,="" or="" seven,="" or="" six="" heads,="" etc.?="" you="" can="" look="" at="" this="" using="" the="" same="" function="" dbinom()="" with="" a="" few="" modifications.="" instead="" of="" giving="" it="" a="" single="" value,="" we="" use="" a="" colon="" to="" specify="" a="" range="" of="" values="" -="" here,="" from="" 0="" to="" 10.="" dbinom(x="0:10," size="10," prob=".5)" and="" because="" we="" would="" like="" to="" be="" able="" to="" plot="" this="" in="" ggplot2,="" we="" will="" need="" to="" make="" it="" into="" a="" data="" frame.="" here,="" our="" x="" is="" every="" possible="" number="" of="" heads="" from="" 0="" to="" 10,="" and="" our="" y="" is="" the="" probability="" for="" each="" number="" of="" heads.="" coin.prob=""><- data.frame(x="0:10," y="dbinom(x=0:10," size="10," prob=".5))" now="" we="" can="" make="" a="" probability="" distribution,="" using="" the="" geom_line()="" function="" to="" connect="" our="" probabilities="" and/or="" using="" the="" geom_bar()function="" to="" make="" a="" bar="" plot="" of="" those="" probabilities.="" ggplot(coin.prob,="" aes(x="x," y="y))+" geom_bar(stat="identity" )+="" geom_line(col="dodgerblue" )="" it="" can="" be="" helpful="" to="" see="" where="" your="" results="" lie="" on="" this="" distribution,="" which="" is="" easiest="" with="" the="" geom_vline()="" code:="" ggplot(coin.prob,="" aes(x="x," y="y))+" geom_bar(stat="identity" )+="" geom_line(col="dodgerblue" )+="" geom_vline(xintercept="Heads," col="red" )="" question="" 2:="" look="" at="" the="" probability="" of="" getting="" 9="" out="" of="" 10="" heads.="" is="" this="" statistically="" significant?="" or="" should="" you="" expect="" this="" to="" happen="" by="" random="" chance="" a="" fair="" amount="" of="" the="" time?="" 1.="" p="">< 0.05,="" this="" is="" something="" that="" happens="" a="" lot="" 1.="" p="">< 0.05,="" this="" is="" something="" that="" is="" uncommon,="" and="" may="" indicate="" your="" coin="" doesn’t="" have="" 50:50="" odds.="" part="" 2:="" double="" check="" your="" understanding="" before="" we="" send="" you="" off="" on="" your="" own="" to="" test="" the="" coins="" in="" your="" pocket="" for="" maximum="" cheatability,="" double="" check="" your="" understanding="" using="" the="" following="" questions:="" question="" 3:="" if="" you="" have="" 5="" heads="" out="" of="" 15="" coin="" tosses,="" what="" is="" the="" probability="" of="" that="" happening?="" 1.="" 0.5="" 1.="" 0.05="" 1.="" 0.09="" 1.="" 0.009="" question="" 4:="" if="" you="" have="" 25="" heads="" out="" of="" 150="" coin="" tosses,="" what="" is="" the="" probability="" of="" that="" happening?="" 1.="" 0.5="" 1.="" 0.05="" 1.="" 0.001="" 1.="">< 0.001="" question="" 5:="" which="" of="" the="" following="" distributions="" correctly="" captures="" the="" full="" probability="" distribution="" of="" 150="" coin="" tosses?="" a.="" ggplot(data.frame(x="1:150," y="dbinom(1:150," 150,="" prob=".5))," aes(x="x," y="y))+" geom_line()="" b.="" ggplot(data.frame(x="0:150," y="dbinom(0:150," 150,="" prob=".5))," aes(x="x," y="y))+" geom_line()="" c.="" ggplot(data.frame(x="0:15," y="dbinom(0:15," 150,="" prob=".5))," aes(x="x," y="y))+" geom_line()="" question="" 6:="" according="" to="" the="" graphic="" below,="" where="" the="" black="" line="" is="" the="" probability="" distribution="" for="" that="" number="" of="" trials="" and="" the="" red="" line="" is="" the="" number="" of="" heads="" actually="" counted,="" is="" this="" number="" of="" heads="" commonly="" expected="" by="" random="" chance?="" (hint:="" look="" at="" where="" the="" red="" line="" and="" black="" line="" cross="" on="" the="" y="" axis!)="" 1.="" yes,="" this="" number="" of="" heads="" happens="" a="" fair="" amount="" 1.="" no,="" this="" number="" of="" heads="" is="" not="" very="" likely="" (p="">< 0.05)="" 1.="" no,="" this="" number="" of="" heads="" is="" not="" likely="" at="" all="" (p="">< 0.001) part 3: how to cheat and prosper part 3.1 your coin for the second part of this lab, you are going to create an r script walkthrough of your results. you are going to perform this experiment, and then test your results to see if your coin really is behaving according to a 50:50 probability. but first: question 7: what type of coin are you using for your experiment? ie, a dirty quarter from 1995, a well-cared for susan b anthony coin, a shiny new euro, a coin from an arcade that shut down in the 80’s, etc? question 8: why do you think the type, age, and condition of the coin matters? how might that affect probability? part 3.2 - flip your coin 30 times record the number of heads and tails in your r script as values called heads and tails. these should add up to 30, or you’re going to have some problems! part 3.3 - create a bar plot of the expected versus observed values edit the data frame-creating code, the melt code, and the geom_bar() code for your data, and place these in your script. part 3.4 - create a probability plot of 30 coin tosses. edit the dbinom() code and geom_line code and place these in your script. question 9: upload your script for the above sections. copy-paste your code, do not upload a picture. part 4 - interpretation read through this smithsonian magazine article on coin flipping percentages: https://www.smithsonianmag.com/science-nature/gamblers-take-note-the-odds-in-a-coin-flip-arent-quite-5050-145465423/ the long and short of it is that it turns out that many coins don’t actually have 50:50 odds of landing on one side or the other (all of your childhood soccer referees lied to you!). the odds might not be that different, but 51:49 is still a difference. your coin may or may not have similar issues. question 10: how might you change your dbinom() code if you knew your coin actually didn’t have a 50/50 shot of landing on one side? what argument would you need to modify? question 11: look back at your results. do you think that your coin actually had 50:50 odds for both sides, or is it biased in one direction or another? if you were going to try and pick the most likely side, which would you pick? explain your answer. the end! upload your answers to d2l by monday at midnight. 0.001)="" part="" 3:="" how="" to="" cheat="" and="" prosper="" part="" 3.1="" your="" coin="" for="" the="" second="" part="" of="" this="" lab,="" you="" are="" going="" to="" create="" an="" r="" script="" walkthrough="" of="" your="" results.="" you="" are="" going="" to="" perform="" this="" experiment,="" and="" then="" test="" your="" results="" to="" see="" if="" your="" coin="" really="" is="" behaving="" according="" to="" a="" 50:50="" probability.="" but="" first:="" question="" 7:="" what="" type="" of="" coin="" are="" you="" using="" for="" your="" experiment?="" ie,="" a="" dirty="" quarter="" from="" 1995,="" a="" well-cared="" for="" susan="" b="" anthony="" coin,="" a="" shiny="" new="" euro,="" a="" coin="" from="" an="" arcade="" that="" shut="" down="" in="" the="" 80’s,="" etc?="" question="" 8:="" why="" do="" you="" think="" the="" type,="" age,="" and="" condition="" of="" the="" coin="" matters?="" how="" might="" that="" affect="" probability?="" part="" 3.2="" -="" flip="" your="" coin="" 30="" times="" record="" the="" number="" of="" heads="" and="" tails="" in="" your="" r="" script="" as="" values="" called="" heads="" and="" tails.="" these="" should="" add="" up="" to="" 30,="" or="" you’re="" going="" to="" have="" some="" problems!="" part="" 3.3="" -="" create="" a="" bar="" plot="" of="" the="" expected="" versus="" observed="" values="" edit="" the="" data="" frame-creating="" code,="" the="" melt="" code,="" and="" the="" geom_bar()="" code="" for="" your="" data,="" and="" place="" these="" in="" your="" script.="" part="" 3.4="" -="" create="" a="" probability="" plot="" of="" 30="" coin="" tosses.="" edit="" the="" dbinom()="" code="" and="" geom_line="" code="" and="" place="" these="" in="" your="" script.="" question="" 9:="" upload="" your="" script="" for="" the="" above="" sections.="" copy-paste="" your="" code,="" do="" not="" upload="" a="" picture.="" part="" 4="" -="" interpretation="" read="" through="" this="" smithsonian="" magazine="" article="" on="" coin="" flipping="" percentages:="" https://www.smithsonianmag.com/science-nature/gamblers-take-note-the-odds-in-a-coin-flip-arent-quite-5050-145465423/="" the="" long="" and="" short="" of="" it="" is="" that="" it="" turns="" out="" that="" many="" coins="" don’t="" actually="" have="" 50:50="" odds="" of="" landing="" on="" one="" side="" or="" the="" other="" (all="" of="" your="" childhood="" soccer="" referees="" lied="" to="" you!).="" the="" odds="" might="" not="" be="" that="" different,="" but="" 51:49="" is="" still="" a="" difference.="" your="" coin="" may="" or="" may="" not="" have="" similar="" issues.="" question="" 10:="" how="" might="" you="" change="" your="" dbinom()="" code="" if="" you="" knew="" your="" coin="" actually="" didn’t="" have="" a="" 50/50="" shot="" of="" landing="" on="" one="" side?="" what="" argument="" would="" you="" need="" to="" modify?="" question="" 11:="" look="" back="" at="" your="" results.="" do="" you="" think="" that="" your="" coin="" actually="" had="" 50:50="" odds="" for="" both="" sides,="" or="" is="" it="" biased="" in="" one="" direction="" or="" another?="" if="" you="" were="" going="" to="" try="" and="" pick="" the="" most="" likely="" side,="" which="" would="" you="" pick?="" explain="" your="" answer.="" the="" end!="" upload="" your="" answers="" to="" d2l="" by="" monday="" at="">
Answered Same DayOct 19, 2021

Answer To: Lab 7. Binomial Probability Lab 7. Binomial Probability Introduction In this lab we are going to be...

Pooja answered on Oct 20 2021
143 Votes
#9#
Heads = 20
Tails = 10
mycoin <- data.frame(Type= c("Expected", "Got"),
Heads = c(15, Heads),
Tails = c(15, Tails))
install.packages("reshape2")
library("reshape2")
longcoins <- melt(mycoin)
library("ggplot2")
ggplot(longcoins, aes(x = variable,...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here