Problema Monty Hall En R

Páginas: 7 (1723 palabras) Publicado: 28 de mayo de 2012
Tutorial

Solving the Monty Hall Problem with Simulations: A super-simple intro to loops and if statements in R

Bodo Winter1

Last updated: January 12, 2012

Introduction Have you heard of the Monty Hall problem? In this simple tutorial, we’re going to solve this problem by means of simulation – if you haven’t worked with loops and if statements in R before, this will be useful for you.If you already know this stuff – stay tuned… the tutorial might still be fun! So, what’s the Monty Hall problem 2 ? Monty Hall was the host of the famous gameshow Let’s make a deal which was popular in the 70s and had many offshoots in other countries (e.g. Geh aufs Ganze! in Germany). After a series of deals, each competitor in this show would be confronted with three doors, only one of whichlead to the desired prize – usually a car. Behind the other two doors were things that nobody would want, e.g. a goat.

1

For updates and other tutorials, check my webpage www.bodowinter.com. If you have any suggestions, please write me an email: bodo@bodowinter.com 2 For an extensive overview, check Wikipedia: http://en.wikipedia.org/wiki/Monty_Hall_problem

1

(Source:http://en.wikipedia.org/wiki/Monty_Hall_problem)

The competitor would initially choose a door and then the host would open one of the remaining doors (always one that didn’t conceal the prize, of course). After that, the participant was given the choice to switch doors or not to switch doors. So, in the above picture, let’s say you initially chose door 1. Monty Hall opens door 3 and there is – lo and behold – agoat. Now you’re given the choice to stay at door 1 or to switch to door 2. What is a better strategy, to switch or not to switch? Or does it matter at all? Before you read on, think about this for a second: What is your initial and intuitive response?

Marilyn vos Savant, once in the Guinness Book of Records for having the highest measured IQ, published a solution to the Monty Hall problem inher column in the magazine Parade… This solution indicated that it’s actually a better strategy to switch doors. To many, this seemed extremely counterintuitive because at first sight, the probability behind each of the doors should be the same: 1/3 a chance of winning the prize. A deluge of letters to the editors flooded in, some 10,000 responses, stating how Ms. vos Savant was wrong, she just hadto be! How could she dare to publish such a simple logical mistake, how preposterous!! Many of the letters were from highly educated people. In the end, they were all proven wrong and Marilyn’s solution stood the test of time.

2

So, why don’t we try to answer this question for ourselves, using R. We will solve the Monty Hall problem in a brute force fashion, simply by simulating a 10,000runs of choices between three doors… and calculating whether switching or not switching is better. The R code that we need to do for this is super-simple3. Have a quick look at the R code in the box, that’s all we’re going to need! The tutorial will guide you through this code.

So, let’s get started!!! First, we need to make a vector “doors” with three doors: “A”, “B” and “C”.

Then, we need tocreate an object into which we store all the information that is generated by the loop.

3

It’ll be really good for you if you have Tinn-R (http://sciviews.org/Tinn-R/) or any other external device to store your R code (e.g. a text editor). Then you can type everything in, and as soon as you’re finished with the loop, copy it into the R console.

3

Now, we need the loop. The generalstructure of loops in R is the following: You put everything that should be executed repeatedly into the curly brackets. Into the regular brackets, you define how often the loop should be executed. The expression i in 1:1000 means that your so-called “running variable” i will be chosen from the vector of numbers between 1 and 1000, so the variable i will be “1” in the first run-through, “2” in the...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • monty hall
  • Dilema de Monty Hall
  • problemas de r
  • Problemas E/R
  • Problem Tica Del R O Atuel
  • Problema Modelo E/R
  • Problemas e/r de base de datos
  • Resolucion De Problemas R

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS