- Parent Category: Programming Assignments' Solutions
We Helped With This R Programming Assignment: Have A Similar One?
|Subject||R | R Studio|
|More Info||Statistics Assignment|
Short Assignment Requirements
Must use Rstudio to make functions for the answers described: stated in question. Does not have to be in extreme R language as I am a beginner.
2. We next examine yet another game of chance - a card game. In a standard deck of playing cards, there are 52 cards, which can be broken down into 4 "suits" (hearts, diamonds, clubs, and spades) of 13 cards. Within each suit are cards numbered 2, 3, 4, 5, 6, 7, 8, 9, and 10, plus 4 extras: a jack, a queen, a king, and an ace. The game involves randomly drawing a card from the deck. If the card you draw is numbered 2 through 5, you win $1. If you draw a 6 through 10, you win $2. If you draw a jack, you lose (i.e., you win $0). If you draw a queen or king, you win $5. If you draw an ace, you win $20. a. (10 points) What is the maximum you are willing to pay for a chance to play? That is, what is the expected value of the game? zero skew? b. (20 points) Do you the payouts of this game to have a positive, negative, Write a sentence explaining your expectation. Use the expectation operators from class to compute the skewness statistic for this game. Does the sign of the skewness statistic confirm your expectation (i.e., += positive skew; -= negative skew)? c. (20 points) Use R to simulate this game. That is, you specify the number of times you want to play, and it generates the results of playing that number of times. Use the function to calculate the average gain per trial (i.e., the expected value) and skewness of the outcomes. Play the game 100,000 times. Does the expected value match what you calculated in (a)? Does the sign of the skewness match your expectation from (b)? Write a sentence or two discussing these results. 2
Distributed: 27 Sept 2018 Due: 4 Oct 2018, 1:00pm, in hard copy Please read each question carefully and be sure to provide answers for all requested components. Your answers to these questions should be typed using Word or another comparable program. For questions that require use of R, please include your syntax and output in your response. For all calculations, please provide full detail of how you arrive at your response, including your use of Excel or other computational resources. In your verbal answers to the questions, please be as specific as you can. Remember that in statistics, precise language is very important for effective communication. This exam is open-book and open-notes. You may use your textbook, lecture notes, homework answer keys, etc. to address the questions on the exam. Please do not discuss any aspect of the exam with the other students in the class or anyone else. If you get stuck on a question (especially how to implement something in R), please email me for clarification. 1. In this first question, we explore the utility of Bayes' theorem by examining the effectiveness of a recent egg recall. Over a 3-month period in 2010, 550 million eggs were recalled due to possible salmonella contamination out of a total 17.5 billion eggs produced in the US during that period. A risk assessment performed by the USDA several years back found that the baseline probability of salmonella contamination in eggs is about 1/100,000. Let's take this to be the probability of salmonella contamination given that an egg was not recalled. Finally, it's difficult to find definitive numbers, but let's assume that the probability tha an egg was contaminated with salmonella given that it was recalled was 1/1000. a. (20 points) An important question is whether the recall was effective at addressing the problem of contamination. What is the probability that an egg was recalled given that it was contaminated with salmonella? Use Bayes' theorem to calculate this value with the help of your favorite calculator. Does it appear that the recall was effective? Write a few sentences interpreting the probability value that you calculated. b. (20 points) Use R to simulate the answer to this question. That is, first generate an event B (an egg is recalled), for which the unconditional probability of "success" matches above. Then, generate an event A (an egg is contaminated), for which the probability of "success" varies depending on whether B was successful or not. Finally, select only trials where A is successful and compute how frequently B is successful. Run this simulation for 10,000,000 eggs and report the result. Does your simulated answer match the result of (a)? If the numbers do not match precisely, briefly describe why they differ. (NB: You may find a different approach that works, but I have found that this is easiest to accomplish with two separate for loops - one to generate the events, and one to pick out the ones that match your criteria. Also, it will likely take some time for your program to run with 10,000,000 eggs. You'll probably want to start with a smaller number [like 100,000] until you get your function up and running.) c. (10 points) In a random sample of 100 recalled eggs, what is the probability that at least one of the eggs is contaminated with salmonella? Be sure to show how you compute this value. 1