<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/answer-probability-questions-with-simulation/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.r-exercises.com/2017/08/20/answer-probability-questions-with-simulation/"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a rel="nofollow" href="https://i0.wp.com/www.r-exercises.com/wp-content/uploads/2017/08/die.jpg" target="_blank"><img sizes="(max-width: 300px) 100vw, 300px" src="https://i0.wp.com/www.r-exercises.com/wp-content/uploads/2017/08/die-300x222.jpg?resize=300%2C222" alt="" class="wp-image-7507" data-recalc-dims="1"></a></p>
<p>Probability is at the heart of data science. Simulation is also commonly used in algorithms such as the bootstrap. After completing this exercise, you will have a slightly stronger intuition for probability and for writing your own simulation algorithms.</p>
<p>Most of the problems in this set have an exact analytical solution, which is not the case for all probability problems, but they are great for practice since we can check against the exact correct answer.</p>
<p>To get the most out of the exercises, it pays off to read the instructions carefully and think about what the solution should be before starting to write <code>R</code> code. Often this helps you weed out irrelevant information that can otherwise make your algorithm unnecessarily complicated.</p>
<p>Answers are available <a rel="nofollow" href="http://www.r-exercises.com/2017/08/20/answer-probability-questions-with-simulation-solutions/" target="_blank">here</a>.</p>
<p><strong>Exercise 1</strong><br>
In 100 coin tosses, what is the probability of having the same side come up 10 times in a row?</p>
<p>You might want to use some of the following functions to answer this question:<code>sample(), rbinom(), rle()</code>.</p>
<p><strong>Exercise 2</strong><br>
Six kids are standing in line. What is the probability that they are in alphabetical order by name? Assume no two children have the same exact name.</p>
<p><strong>Exercise 3</strong><br>
Remember the kids from the last question? There are three boys and three girls. How likely is it that all the girls come first?</p>
<p><strong>Exercise 4</strong><br>
In six coin tosses, what is the probability of having a different side come up with each throw, that is, that you never get two tails or two heads in a row?</p>
<p><strong>Exercise 5</strong><br>
A random five-card poker hand is dealt from a <a rel="nofollow" href="https://en.wikipedia.org/wiki/Standard_52-card_deck" target="_blank">standard deck.</a> What is the chance of a flush (all cards are the same suit)?</p>
<p><strong>Exercise 6</strong><br>
In a random thirteen-card hand from a standard deck, what is the probability that none of the cards is an ace and none is a heart (♥)?</p>
<div>
<aside><img src="http://www.r-exercises.com/2017/08/20/answer-probability-questions-with-simulation/"></aside>
<div><strong>Learn more</strong> about probability functions in the online course <a rel="nofollow" href="http://www.r-exercises.com/product/statistics-with-r-advanced-level/" target="_blank">Statistics with R – Advanced Level</a>. In this course you will learn how to
<ul>
<li>work with different binomial and logistic regression techniques,</li>
<li>know how to compare regression models and choose the right fit,</li>
<li>and much more.</li>
</ul>
</div>
</div>
<p><strong>Exercise 7</strong><br>
At four parties each attended by 13, 23, 33, and 53 people respectively, how likely is it that at least two individuals share a birthday at each party? Assume there are no leap days, that all years are 365 days, and that births are uniformly distributed over the year.</p>
<p><strong>Exercise 8</strong><br>
A famous coin tossing game has the following rules: The player tosses a coin repeatedly until a tail appears or tosses it a maximum of 1000 times if no tail appears. The initial stake starts at 2 dollars and is doubled every time heads appears. The first time tails appears, the game ends and the player wins whatever is in the pot. Thus the player wins 2 dollars if tails appears on the first toss, 4 dollars if heads appears on the first toss and tails on the second, 8 dollars if heads appears on the first two tosses and tails on the third, and so on. Mathematically, the player wins 2<sup>k</sup> dollars, where k equals the number of tosses until the first tail. What is the probability of profit if it costs 15 dollars to participate?</p>
<p><strong>Exercise 9</strong><br>
Back to coin tossing. What is the probability the pattern heads-heads-tails appears before tails-heads-heads?</p>
<p><strong>Exercise 10</strong><br>
Suppose you’re on a game show, and you’re given the choice of three doors. Behind one door is a car; behind the others, goats. You pick a door, say #1, and the host, who knows what’s behind the doors, opens another door, say #3, which has a goat. He then says to you, “Do you want to pick door #2?” What is the probability of winning the car if you use the strategy of first picking a random door and then switching doors every time? Note that the host will always open a door you did not pick, and it always reveals a goat.</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/07/25/hacking-statistics-exercises-part-4/" title="Hacking statistics or: How I Learned to Stop Worrying About Calculus and Love Stats Exercises (Part-4)" target="_blank">Hacking statistics or: How I Learned to Stop Worrying About Calculus and Love Stats Exercises (Part-4) </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/08/17/probability-functions-beginner/" title="Probability functions beginner" target="_blank">Probability functions beginner </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2016/08/12/combinations-exercises/" title="Combinations Exercises" target="_blank">Combinations Exercises </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/start-here-to-learn-r/" target="_blank">Explore all our (>1000) R exercises</a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/r-courses/" target="_blank">Find an R course using our R Course Finder</a> directory</li>
</ol>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.r-exercises.com/2017/08/20/answer-probability-questions-with-simulation/"> R-exercises</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/TyZh2GiMvuY" height="1"></a></div>