R代写-MAS115
时间:2022-03-28
MAS115: SEMESTER 2 MINI-PROJECT
2021-22
BRYONY MOODY
PROJECT DESIGNED BY DR TIM HEATON
The problem - Cats and Mice
Expected Time to Survive. Suppose you are a mouse and you live in a house with 5 rooms
arranged in a floor plan as shown in Figure 1. You start in room 1 and every minute (starting
at t = 1) you move to a new room by choosing a door at random. In room 5 there is a sleeping
but hungry cat who will instantly wake up and eat you should you enter. How much longer can
you be expected to survive?
Figure 1. House plan with an exit
The computer part
Tasks.
• Write a function that will create a random value of X — the time until eaten given you
start in room 1.
• Create 10,000 random values of X.
• Estimate µ, the mean time until death.
1
2 BRYONY MOODY PROJECT DESIGNED BY DR TIM HEATON
The theoretical part
Conditioning. One of the most important concepts in probability is that of conditioning. The
idea is applicable if we are trying to calculate a hard probability or expectation for a random
variable X. To help us, what we can try and do is consider what extra information might make
the calculation easy. For example, suppose that knowing the value of another random variable
Y = y would help us with our initial calculation about X. Then we can condition on all the
possible values that Y can take and use the results that:
P (X = x) =
∑
y
P (X = x|Y = y)P (Y = y),(1)
E[X] =
∑
y
E[X|Y = y]P (Y = y).(2)
You should recognise Equation (1) as the “law of total probability” from MAS113. It can be
used to prove Equation (2) since:∑
y
E[X|Y = y]P (Y = y) =
∑
y
∑
x
xP (X = x|Y = y)P (Y = y)
=
∑
x
x
{∑
y
P (X = x|Y = y)P (Y = y)
}
=
∑
x
xP (X = x) by Equation (1)
= E[X].
How does this help with our problem? Let us start with what seems like a more general
problem by defining
µi = E[Time until Eaten|Start in room i].
At the moment it’s not easy to know how to find e.g.
µ2 = E[Time until Eaten|Start in room 2].
However, let’s try conditioning on what happens at t = 1 and we move to a new room at
random. To leave room 2 we can, as shown in the plan, choose two doors meaning we’ll move
to either room 1 or 3 (each with equal probability of 12). Let’s try and use Equation (2) and see
if it helps. Now,
µ2 =E[Time until Eaten|Start in room 2]
=E[Time until Eaten|Start in room 2,Move to room 1]P (Move to room 1)
+ E[Time until Eaten|Start in room 2,Move to room 3]P (Move to room 3).
Now that we’re in a new room we can see how long we’ve still got left to survive from that room
and note that
E[Time until Eaten|Start in room 2,Move to room 1] = 1 + E[Time until Eaten|Start in room 1],
⇒ µ2 = 1 + 0.5µ1 + 0.5µ3.
MAS115: SEMESTER 2 MINI-PROJECT 2021-22 3
Similar results hold unless we actually end up in room 5 in which case we get eaten straight
away
E[Time until Eaten|Start in room 5] = 0
Tasks.
• Repeat the above argument for all starting points to get similar linear equations for
µ1, . . . , µ5.
• Rearrange this system of linear equations into the form of a matrix equation Aµ = 1
where µ = (µ1, . . . , µ4)
T .
• Solve this matrix equation in R. Hint: Look at the solve() function
Probability of Escape
Now suppose there is an exit from the house, shown in Figure 2. As before you start in room
Figure 2. House plan with an exit
1 and move every minute by choosing a door at random from the room you are currently in.
What is the probability you will escape from the house without being eaten?
• Modify your computer code to create a random value of
Z =
{
0 if you are eaten
1 if you escape through the exit
the indicator function of escaping.
• Create 10,000 random values of Z and hence estimate ν, the probability of survival.
• Use a similar conditioning argument (but this time using Equation 1) to prove your
probability results.
The project write-up
You must write up your project, including any important R code and description of how it
works, in a RMarkdown report of up to 6 pages (including the computer code itself). It must
be a PDF or a penalty will be applied. The title should be ‘MAS115: Semester 2 Mini-project’,
and the author should be your registration number. Please do not include your name.
4 BRYONY MOODY PROJECT DESIGNED BY DR TIM HEATON
Your project will be peer-assessed. That is, it will be marked by your fellow students. You will
receive a mark out of 8 for the project itself, and a mark out of 2 for your involvement in the
peer-assessment. Overall, the project counts as 10% of your final module score.
Your write-up should not be much longer than 6 pages; if this seems problematic, contact
Bryony Moody.
You will submit the project online via the course website. The deadline for uploading the
projects is 11am at the end of Tuesday 29th March (Week 8). More details will follow for how
to upload via email.
Note. The peer assessment will take place online and will be due Friday 25th April. You will
be sent an email about how to do this after the mini-project deadline.
Late work and plagiarism
Late work. The School of Maths operates a zero tolerance policy on late work. Any work
submitted after the deadline may be given a mark of zero. Anybody with circumstances affecting
their ability to hand in the work must contact Bryony Moody in advance of the hand-in date.
Plagiarism. The project must be your own work. Whilst we encourage you to discuss the work
with friends and help each other out with R scripts, your final R code and write-up must be
your own. Where we judge that two or more pieces of work are too similar there is a possibility
of a mark of zero being awarded for those assignments. Please bear this in mind!
Final comments
Here are some final thoughts to help you with the project.
• Please make use of the MAS115 discussion board, accessed from the course website.
Even if you are able to do the project yourself, you may be able to help fellow students.
• Try to make your R script as tidy as possible; after all, it will be read by your fellow
students.
• Make your write-up as readable as possible by following the advice in the presentation
part of the course and feedback from the mini and group projects.
March 2022