Ii to generate textttoutcometest the textttsample

Info icon This preview shows pages 2–3. Sign up to view the full content.

ii. To generate \texttt{outcome.test}, the \texttt{sample()} command draws from the values \texttt{0} and \texttt{1} with probabilities corresponding to those specified by \texttt{prob}. Which number corresponds to heads, and which corresponds to tails? \vspace{2.5cm} iii. Why is it important to sample with replacement? \vspace{3cm} b) The following code uses a \texttt{for} loop to repeat the experiment and record the results for the number of times specified by \texttt{number.replicates}. The term \texttt{k} is an index, used to keep track of each iteration of the loop; think of it as being similar to the *k* (or *i*) in sigma notation. The \texttt{vector()} function creates an empty vector with length \texttt{number.tosses} that is filled with \texttt{0}; later on, the results will be recorded in this vector, \texttt{number.heads.per.replicate}. ```{r simulateCoinTossing, eval = FALSE} #set the parameters prob.heads = 0.7 number.tosses = 10 number.replicates = 50 number.heads.per.replicate = vector("numeric", number.tosses) #set the seed set.seed(2014) #simulate the coin tosses for(k in 1:number.replicates){ outcome.replicate = sample(c(0,1), size = number.tosses, prob = c(1 - prob.heads, prob.heads), replace = TRUE) number.heads.per.replicate[k] = sum(outcome.replicate)
Image of page 2

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

} #view the results number.heads.per.replicate addmargins(table(number.heads.per.replicate)) #calculate the probability greater.than.5 = (number.heads.per.replicate > 5) table(greater.than.5) ``` i. The parameters of the experiment have already been filled in, with the probability of heads being 0.7 and the number of tosses set to 10. This code repeats the experiment 50 times, as specified by \texttt{number.replicates}. Run the code chunk. ii. How many heads were observed in the fourth replicate of the experiment? Hint: look at \texttt{number.heads.replicate}. \vspace{2cm} iii. Out of the 50 replicates, how often were 10 heads observed in a single experiment? \vspace{2cm} iv. From the displayed results of the simulation, calculate an estimate of the probability of observing 6 or more heads when a coin is tossed 10 times. \vspace{4cm}
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '16
  • banubaydil
  • Probability, 1cm, 3cm, 2.5cm, #store

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern