--- title: "Lab2CodePractice" author: "Kenya Amano" date: "10/9/2020" output: pdf_document editor_options: chunk_output_type: console --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ## Prerequisite ```{r} # Good practice to remove all objects from the workspace rm(list = ls()) # Use library() for packages you need, or source() for other R files. library(tidyverse) # Setting the seed ensures that we get the same random draw over and over again. set.seed(20201009) rnorm(5) # Check ``` ## 0. Calculate the following operations by hand (... meaning by R) a) $$ \sum\limits_{i=1}^{5} i = $$ b) $$ \prod\limits_{i=1}^{5} i = $$ c) $$ 5! \times 10^{3!} \times e^{4} = $$ ```{r} # a) # b) # c) ``` ## 1. Build a Bernoulli distribution using the sample() function, where the probability of "success" is 0.7. Run "?sample" if you are unsure how the function works. ```{r} # Create an imaginary person to flip the coin once for you sample(x = ) ``` ## 2. How do you know if it is working properly? Conduct simulation to check if the assigned probabilities are matached with the empirics ```{r} ``` ## 3. Plot the above Bernoulli distribution ```{r} ``` ## 4. Based on the above, generate a binomial distribution, with number of trials equal to 10, without using rbinom() ```{r} # Create an imaginary person to flip the coin ten times for you ``` ## 5. Plot the above binomial distribution ```{r} ``` ## 6. Explore the rbinom, dbinom, pbinom functions. What do they do? Answer the following questions: a) The probability of a coin landing on head is 0.7. If you were to flip the coin 10 times, what is the probability of getting exactly 7 heads? b) What is the probability of getting 7 heads or less? c) How do you know (b) is true? ```{r} # a) Pr(exactly 7 heads) # b) Pr(7 heads or less) # c) Double check ```