MA10212辅导、讲解Lab 3 CJ、讲解R程序语言、R辅导 解析Java程序|讲解Java程序
- 首页 >> 其他 MA10212: Computer Lab 3 CJ, Mar 2019
For homework: Problem 1
Freddy Fisher is planning to spend 5 hours on the river bank catching as
many fish as he can. Let T1 denote the waiting time (in minutes) until he
catches his first fish, T2 the time between catching fish 1 and fish 2, and
so forth. We shall assume the Ti
, i = 1, 2, . . ., are independent and each
Ti ~ Exp(0.1), where 0.1 is the rate parameter.
(a) (4 marks) Write code to simulate values T1, . . . , T100, the first 100
between-fish intervals. The intention is that there are more than enough Tis
to describe what happens in 5 hours of fishing. Check this assumption holds
by finding the sum T1 + . . . + T100 and noting that it is a lot higher than 300
(you should get an answer in the range 800 to 1200, or thereabouts).
Now find the times X1, X2, . . . , at which fishes are caught (in minutes since
Freddy started fishing), setting X1 = T1, X2 = T1 + T2, etc. You may
wish to start by defining a vector y of length 100 and using the command
y[n]=sum(t[1:n]) to put the sum of the first n elements of the vector
t = (T1, . . . , T100) in element n of y. After completing this process, you
should find that some values y[n] exceed 300 — and you need to remove
these. Experiment with the commands y < k and x = y[yconstant k to discover a neat way of selecting the elements of y that you want
to retain. Check that your final vector x contains the correct information.
(b) (2 marks) Create a function sample.x that simulates one sequence
of the times at which fish are caught. The command x=sample.x() should
produce a vector x containing the sequence of fish-catching times. Call your
function to check that it produces sensible looking results.
(c) (5 marks) Write code to generate 1000 realisations of Freddy’s 5 hour
fishing trip. In each case note the total number of fish caught in the five hour
period and call these numbers N1, . . . , N1000.
Madame Cholet insists that the number of fish caught should follow a
Poisson distribution. Let μ be the mean of the observed values N1, . . . , N1000.
Compare the histogram of your sample of values N1, . . . , N1000 with that of
a sample from a Poisson distribution with mean μ to see if the data agree
with Madame Cholet’s theory.
Continue this investigation in an appropriate manner so that you can give
a firm conclusion as to whether or not Madame Cholet’s claim is correct.
Present appropriate graphical displays to support your argument. (You may
find it useful to refer back to the methods used in Lab Sheet 2, Problem 2.)
3MA10212: Computer Lab 3 CJ, Mar 2019
(d) (3 marks) Generate a new sample of 1000 realisations of Freddy’s
fish-catching adventure. In each case note W, the time Freddy had to wait
between the first and second fish that he caught. Put the values of these
waiting times W in the vector Wsample.
What distribution do the data in Wsample appear to follow? Does this agree
with your expectations?
(e) (6 marks) Now generate a new sample of 1000 realisations of Freddy’s
fish-catching expedition. This time find V , the length of the between-fish
interval that contains the mid-point of Freddy’s 5 hour stay at the river bank.
So, if fish are caught at times X1, . . . , XN , you need to find V = Xi+1 ? Xi
where i is such that Xi < 150 and Xi+1 > 150. (You might experiment with
the commands max(x[xk]) for a specified constant k to
find a neat way to carry out this calculation.) Put the values of these interval
lengths V in the vector Vsample.
What distribution did you expect the data in Vsample to follow? Is this the
case? Can you find a distribution that fits the data in Vsample?
Compare the means of the data in the vectors Wsample and Vsample. Think
about how these interval lengths arise and give a plausible explanation for
why the data in Vsample should be so different from the values in Wsample.
(f) (2 marks) You are asked to advise on the design of a study into the
provision of healthcare services. The investigators plan to analyse data from
a National Health Service data-base to see how long people have to wait
between the time their doctor decides they need a hip replacement and the
time the hip replacement operation is performed. The proposal is to extract
information about their waiting times for all patients who were in the process
of waiting for a hip replacement on 1 July 2017.
Given what you have observed in the fish-catching example, what comments
would you make to these investigators?
Presentation (3 marks)
Your submission should be well organized and easy to follow.
Tidy up your output by deleting any errors and unnecessary commands.
Give each plot a title and label the x and y axes.
Answer the questions as stated and use colour to highlight your answers and
distinguish these from output produced directly by R.
For homework: Problem 1
Freddy Fisher is planning to spend 5 hours on the river bank catching as
many fish as he can. Let T1 denote the waiting time (in minutes) until he
catches his first fish, T2 the time between catching fish 1 and fish 2, and
so forth. We shall assume the Ti
, i = 1, 2, . . ., are independent and each
Ti ~ Exp(0.1), where 0.1 is the rate parameter.
(a) (4 marks) Write code to simulate values T1, . . . , T100, the first 100
between-fish intervals. The intention is that there are more than enough Tis
to describe what happens in 5 hours of fishing. Check this assumption holds
by finding the sum T1 + . . . + T100 and noting that it is a lot higher than 300
(you should get an answer in the range 800 to 1200, or thereabouts).
Now find the times X1, X2, . . . , at which fishes are caught (in minutes since
Freddy started fishing), setting X1 = T1, X2 = T1 + T2, etc. You may
wish to start by defining a vector y of length 100 and using the command
y[n]=sum(t[1:n]) to put the sum of the first n elements of the vector
t = (T1, . . . , T100) in element n of y. After completing this process, you
should find that some values y[n] exceed 300 — and you need to remove
these. Experiment with the commands y < k and x = y[y
to retain. Check that your final vector x contains the correct information.
(b) (2 marks) Create a function sample.x that simulates one sequence
of the times at which fish are caught. The command x=sample.x() should
produce a vector x containing the sequence of fish-catching times. Call your
function to check that it produces sensible looking results.
(c) (5 marks) Write code to generate 1000 realisations of Freddy’s 5 hour
fishing trip. In each case note the total number of fish caught in the five hour
period and call these numbers N1, . . . , N1000.
Madame Cholet insists that the number of fish caught should follow a
Poisson distribution. Let μ be the mean of the observed values N1, . . . , N1000.
Compare the histogram of your sample of values N1, . . . , N1000 with that of
a sample from a Poisson distribution with mean μ to see if the data agree
with Madame Cholet’s theory.
Continue this investigation in an appropriate manner so that you can give
a firm conclusion as to whether or not Madame Cholet’s claim is correct.
Present appropriate graphical displays to support your argument. (You may
find it useful to refer back to the methods used in Lab Sheet 2, Problem 2.)
3MA10212: Computer Lab 3 CJ, Mar 2019
(d) (3 marks) Generate a new sample of 1000 realisations of Freddy’s
fish-catching adventure. In each case note W, the time Freddy had to wait
between the first and second fish that he caught. Put the values of these
waiting times W in the vector Wsample.
What distribution do the data in Wsample appear to follow? Does this agree
with your expectations?
(e) (6 marks) Now generate a new sample of 1000 realisations of Freddy’s
fish-catching expedition. This time find V , the length of the between-fish
interval that contains the mid-point of Freddy’s 5 hour stay at the river bank.
So, if fish are caught at times X1, . . . , XN , you need to find V = Xi+1 ? Xi
where i is such that Xi < 150 and Xi+1 > 150. (You might experiment with
the commands max(x[x
find a neat way to carry out this calculation.) Put the values of these interval
lengths V in the vector Vsample.
What distribution did you expect the data in Vsample to follow? Is this the
case? Can you find a distribution that fits the data in Vsample?
Compare the means of the data in the vectors Wsample and Vsample. Think
about how these interval lengths arise and give a plausible explanation for
why the data in Vsample should be so different from the values in Wsample.
(f) (2 marks) You are asked to advise on the design of a study into the
provision of healthcare services. The investigators plan to analyse data from
a National Health Service data-base to see how long people have to wait
between the time their doctor decides they need a hip replacement and the
time the hip replacement operation is performed. The proposal is to extract
information about their waiting times for all patients who were in the process
of waiting for a hip replacement on 1 July 2017.
Given what you have observed in the fish-catching example, what comments
would you make to these investigators?
Presentation (3 marks)
Your submission should be well organized and easy to follow.
Tidy up your output by deleting any errors and unnecessary commands.
Give each plot a title and label the x and y axes.
Answer the questions as stated and use colour to highlight your answers and
distinguish these from output produced directly by R.