Skip main navigation

Instructions for your second RStudio activity

How do you calculate the margin of error? What criteria should you use to select appropriate statistical tools?

In this RStudio activity, you will practice your R skills by running simulations of random experiments to calculate the margin of error for each experiment. To achieve this, you will:

  1. Explore probability by choosing appropriate statistical tools.
  2. Apply the corresponding code blocks in RStudio, as explained in the Activity 1 video and subsequent steps.

You will be given four specific tasks for you to complete in this RStudio activity. This activity will take approximately two hours to finish. To follow along more easily, keep this step, the task step you are working on, and your RStudio session open in separate browser tabs so you can refer to the instructions while you work. Model solutions are provided at the end of the step to help you review your work.

This activity demonstrates the Law of Large Numbers, showing how the frequencies of outcomes stabilise in long-term sequences of random trials. Such observations help develop statistical intuition by providing experimental support for the concept of probability.

In the R activity, you will be given the coding examples shared in Activity 1 to conduct your own simulations (e.g tossing a coin or rolling a dice) and verify the convergence of relative frequencies to their expected probabilities.

For instance, you may intuitively expect a probability of 1/2 for heads in a fair coin toss or 1/6 for rolling a six on a fair dice. By conducting long-term simulations, you can numerically evaluate these probabilities as the relative frequency of the event of interest (for example, sequences like ‘6666’ in dice rolls or shared birthdays in a group).

These experimental estimates of probabilities are approximate and depend on the specific sequence of random outcomes. They will vary if the sequence is repeated. The accuracy of these estimates improves with more replicated experiments. The reading explains how to estimate a confident margin of error (MOE) for a finite sequence of trials.

You can download the Zip file Lab-2-Lets-measure-probability from the ‘Downloads’ section below and then open the file in RStudio. 

Post session review

After completing your session, download the R script Lab-2-Model-solutions-lets-measure-probabability from the ‘Downloads’ section below to see the model solutions. Upload the file into your RStudio session to do the review and compare your answers to the ones given in the file.

Next steps

You are ready to start working in RStudio. Use this reading for the instructions. Select Next to move onto the first task. 

Practical ideas for accessing the reading during your session:

  • Open the reading on a second screen if available.
  • Print the reading as a PDF to review on another device.
  • Print it onto paper for reference while you work in RStudio.

Now, open your version of RStudio to begin working on the five topics.

This article is from the free online

Statistical Methods

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now