1  Activity 1

Welcome to the MTH 113 labs! At the start of the class, find a blank page in your notebook which you will hand in as your “lab report.” At the top of the page, please write your name, the lab number (Lab 1 today) and MTH 113.

For each question, provide the answer or output on your lab report. For example, the very first question, you should be writing down the values of your dice rolls. Then for question 2 you should write down both the table and provide a sketch of the bar graph that is created.

Any plots you are asked to provide do not need to be drawn super meticulously, just enough to communicate the rough size of everything.

1.1 Dice activity

Exercise 1.1  

  1. Take two dice and roll the pair of them 25 times, keeping track of the sum of their values (e.g. rolling a 4 and 5: ⚃⚄ is recorded as 9). Record this and following answers on your lab sheet. Fill those into the dice_rolls variable below.

Your numbers should be between 2 and 12.

  1. From the sum_count table
    1. report how many times you rolled a 2, 3, 4, etc.
    2. after you have done that, change the last line from sum_count to barplot(sum_count) and run that to get a barplot.
  2. Which sum (or sums) occurred the most number of times?
  3. Based on your data, are we more likely to roll a 2 or a 7?
  4. The function mean() returns the mean of a dataset. Run the next code box and report the mean of the data.
Note

It is likely the case that in 25 rolls there were some totals you never rolled, if so, report those numbers as 0.

1.2 Data activity

R, and it’s many packages, contain many different datasets for practicing its features. One of these is the starwars dataset. You can see the full dataset here.

Exercise 1.2  

  1. What types of variables are included in this dataset? Give an example for each type (quantitative discrete, quantitative continuous, qualitative)
  2. We can interact with this data set in R as starwars. Specifically we can use the $ operator to specify which column we wish to retrieve. Let’s use this now to create a pie chart of character gender in Star Wars. Make a quick sketch of the resulting chart.
  1. Replace the word gender in line 1 by different variables. For which of these is a pie chart a reasonable way to represent the data and which of these is a pie chart hard to read meaningful information from? You do not need to provide additional pie charts for these other variables.
    • gender
    • sex
    • homeworld
    • species

1.3 Syntax and Functions

  • mean(...) the mean or average of a list of numbers
  • $ takes a specific column from a dataset e.g. starwars$height
  • pie(...) creates a pie chart