1. In your lab report, construct a dataset named **students** that contains **12 engineering** majors, **5 math** majors, and **3 other** majors. ```{r} #### Exercise 1 # Your code should look like: XX <- c(rep("XX",XX), rep("XX",XX), rep("XX",XX)) ```

2. Randomly sample 3 students from your **students** dataset **without replacement.** ```{r} #### Exercise 2 # Below this line, type the code to sample 3 students ```

3. Run 10,000 replications of sampling 3 students from your **students** dataset **without replacement.** Then, construct a summary of your results with the `table` or `tally` commands. Finally, estimate the likelihood of choosing 3 math majors from your simulation. ```{r} #### Exercise 3a # Simulate 10,000 replications of sampling 3 students without replacement # Complete the code by replacing the XX values sampled_students <- do(XX) * sample(XX, size=XX, replace=XX) #### Exercise 3b # Use the tally() or table() commands to construct a table # If you use tally(), notice that your sampled_students dataset # contains 3 variables: V1, V2, and V3. ``` ```{r} #### Exercise 3c # Once you've generated your lab report, you can estimate # the likelihood of choosing 3 math majors. # Write your answer below this line ```

4. Use the `choose()` command to calculate the probability of choosing 3 math majors (out of the 12 engineering, 5 math, and 3 other majors in your fictitious class). Verify that this answer is similar to the likelihood you estimated in exercise #3. ```{r} #### Exercise 4 # Type your code below this line ```

5. Use the `dhyper()` command to calculate the probability of choosing 3 math majors (out of the 12 engineering, 5 math, and 3 other majors in your fictitious class). Although it seems as though you have 3 different types of objects, you really only have math majors and non-math majors. ```{r} #### Exercise 5 # Change the XX values in the code below dhyper(XX, XX, XX, XX) ```

6. In assignment #3, you were asked to analyze data regarding Nurse Gilbert. Out of the 257 shifts Nurse Gilbert worked, 40 deaths occurred. Out of the 1384 shifts she did **not** work, 34 deaths occurred. Use a simulation to estimate the likelihood of observing 40 or more deaths on her shifts if, in fact, Nurse Gilbert had no influence on those deaths. ```{r} #### Exercise 6a # I'll create the dataset for you nurse <- data.frame( shift = c( rep("Gilbert",257), rep("No Gilbert", 1384) ), death = c( rep("death", 40), rep("No death", 217), rep("death", 34), rep("No death", 1350) ) ) # Look at a tally of the dataset # Nothing for you to do with this one, either. tally(death ~ shift, data=nurse) # Replace the XX values below to simulate 10,000 replications of this experiment. shuffled_shifts <- do(XX) * # Run 10,000 replications tally( XX ~ shuffle(XX), # Insert the death and shift variables. data=nurse, format="data.frame")[1,3] # Access the number of deaths on her shifts ``` ```{r} #### Exercise 6b # Tally the results tally(~result, data=shuffled_shifts) # Replace the XX values below to create a histogram of the results histogram(~result, data=shuffled_shifts, type="count", width=1, xlab = "XX", # Label your x-axis v = XX, # Draw a vertical line at XX groups = (result >= XX) ) # Color all bars >= XX #### Exercise 6c # Replace the XX to estimate the p-value prop(~result>=XX, data=shuffled_shifts, format="prop") ```

7. Use the hypergeometric distribution to estimate the likelihood of observing 40 or more deaths on Nurse Gilbert's shifts. From this, what conclusions can you make? ```{r} #### Exercise 7 # Replace the XX values to estimate the likelihood 1-phyper(XX, XX, XX, XX) ```

8. Use simulation methods (shuffling) to replicate the free-throw example we completed at the end of activity #3. Follow the **Need for speed** example you just read in this lab. You'll need to generate a dataset, calculate sums, run 10,000 replications of a shuffling simulation, visualize the results, and estimate the p-value. ```{r} #### Exercise 7 # Type all your code below: ```

End of Lab Report #1