Back to Main Page

Sample Questions

Question one

Data = [0.576,0.439,2.262]

Names = {'Bob', 'Sandra ', 'Eliot'}

You have been given two lists of data (only part of the data shown above). One is called Data and the other is called Names. Data contains a list of reaction times (in seconds) from a simple target detection task. Names contains a list of names for the participants that took part in the experiment. The first value in Data belongs to the person named in the first value of Name etc.

Looking at the data, you notice that a few participants have very slow reaction times of several seconds when most participants have reaction times below one second. You decide that before analysing the data, you will remove the participants with the slow reaction times.

Your task is to clean the data of the very slow participants and to produce a list of names of the removed participants.

To solve this problem, you'll need to perform the following steps:

  1. Calculate the average reaction time of all the participants before removing any. You can use the function mean() to do this. (1 mark)

  2. Calculate the standard deviation of all the participants before removing any. You can use the function std() to do this. (1 mark)

  3. Calculate a cut-off value of two standard deviations above the mean. (1 mark)

  4. Determine the index values for the participants that will be removed using the cut-off calculated above. [hint: these are the participants with a reaction time greater than > the cut-off value.] (1 mark)

  5. Use the index values produced above to get a list of names for the removed participants. (2 marks)

  6. Produce a new data vector called DataClean that only contains the values that are faster than (i.e., less than <) the cut-off value. (2 marks)

Question two

The board game Monopoly is often played with two dice that are thrown at the same time. Throwing double 6s allows you to repeat your turn. How many throws, on average, does it take to throw double 6s (note: throwing the two dice at the same time counts as one throw). Solve this problem by programming a simulation. You can simulate a throw with the command outcome = randperm(6,1).

To solve this problem, you'll need to perform the following steps:

  1. Simulate the outcome of two dice by using two instances of randperm. (1 mark)

  2. Keep track of the number of times you simulate two dice throws before getting double 6s. (1 mark)

  3. Carry on stimulating dice throws until you have produced double 6s. (2 mark)

  4. Take note of how many times you needed to simulate the dice throws until you got a double 6s and store this value. [hint: you'll be repeating the simulation multiple times, so store this value in some sort of a list like a vector.] (2 marks)

  5. Repeat the simulation 100 times. (1 mark)

  6. At the end of the 100 simulations calculate the average number of times you had to throw the dice to get double 6s [hint: to do this you'll need to use the vector referred to in step 4.] (1 marks)

[hint: On each run of the simulation you will be recording the number of throws it took until you reached double 6s, so that last step can be solve by just working out the average of this list of numbers. You can use the function mean() to calculate the average of a list of numbers. To solve this problem you might need to use a while loop and a for loop].

Sample answers

Question one

% Question 1
DataMean = mean(Data);
DataSD = std(Data);
CutOff = DataMean + DataSD + DataSD;
SubsToRemove = find(Data > CutOff);
RemovedNames = Names(SubsToRemove);
DataClean = Data(Data < CutOff);

Question two

% Question 2
ThrowsToGet66 = [];
for i = 1 : 100
   ThisRun = 0;
   DoubleSix = false;
   while DoubleSix == false 
      Dice1 =  randperm(6,1);
      Dice2 =  randperm(6,1);
      ThisRun = ThisRun + 1;  
      if Dice1 == 6
          if Dice2 == 6
              ThrowsToGet66(i) = ThisRun;
              DoubleSix = true;