Question Details
--title: "Roulette" output: html_document --## Introduction In this home work you will write two functions that simulate various...
title: "Roulette"
output: html_document
---
## Introduction
In this home work you will write two functions that simulate various bets in
roulette. Review the slides from class to see the possible bets and their pay
offs.
The home work aims to give you practice in the following aspects of function
writing:
* Identify the parameters to a function and write a signature for the function
* Use if/else statements to control the flow of code evaluation
* Compare the efficiency of vectorized computations to for loops
Additionally, you will compare various betting strategies.
## A First Function
In class, we wrote a function to simulate betting red in roulette. We reproduce
this function here for your convenience.
```{r betRed}
betRed = function(numBets, betAmt = 1) {
winLoss = sample(rep(c(-1, 1), c(20, 18)),
size = numBets, replace = TRUE)
netGain = sum(winLoss * betAmt)
return(netGain)
}
```
We compares the net gain of two types of betting strategies: 100 bets of 1
dollar on red and 1 bet of 100 dollars on red. To do this we repeated the
betting process 10,000 times to see the kinds of net gains we might get with
each strategy.
```{r}
gain100B.1D =
replicate(10000, betRed(numBets = 100, betAmt = 1))
gain1B.100D =
replicate(10000, betRed(numBets = 1, betAmt = 100))
```
We examine the distribution of the 10,000 outcomes from these betting strategies
with a plot. We wrote a function to make this plot as we plan to make several
plots and figure it's easier to keep them all consistent with this function,
`plotGains`
```{r,include=FALSE}
plotGains =
function(gain1, gain2 = NULL, bw = 2,
title = 'Compare Betting Strategies')
{
gains = data.frame(
gain = c(gain1, gain2),
strat = rep(c(1,2),
times = c(length(gain1), length(gain2)))
)
require(ggplot2)
Solution details:
Answered
QUALITY
Approved
ANSWER RATING
This question was answered on: Jan 02, 2020
PRICE: $15
Solution~000.zip (25.37 KB)
This attachment is locked

Pay using PayPal (No PayPal account Required) or your credit card . All your purchases are securely protected by .
About this Question
STATUSAnswered
QUALITYApproved
DATE ANSWEREDJan 02, 2020
EXPERTTutor
ANSWER RATING
YES, THIS IS LEGAL
We have top-notch tutors who can do your essay/homework for you at a reasonable cost and then you can simply use that essay as a template to build your own arguments.
You can also use these solutions:
- As a reference for in-depth understanding of the subject.
- As a source of ideas / reasoning for your own research (if properly referenced)
- For editing and paraphrasing (check your institution's definition of plagiarism and recommended paraphrase).
NEW ASSIGNMENT HELP?
Order New Solution. Quick Turnaround
Click on the button below in order to Order for a New, Original and High-Quality Essay Solutions. New orders are original solutions and precise to your writing instruction requirements. Place a New Order using the button below.
WE GUARANTEE, THAT YOUR PAPER WILL BE WRITTEN FROM SCRATCH AND WITHIN A DEADLINE.
