首页 > > 详细

解析R编程、R辅导、辅导R、R语言讲解留学生、讲解R

Coursework 4: Monte Carlo integration
Submission: All solutions should be submitted on Moodle only and submitted to the Group Folder
for your Workshop Group. Submissions should include:
R script. le (XXX.R) { This should include all R code used in the coursework and the marker
should be able to open and run your R le without any other les.
pdf of solutions (XXX.pdf) { Typed solutions to the coursework questions. You may use the package
of your choice to produce the solutions (for example, LATEX or Word) but solutions must be typed
up.
For questions which state "Write a function :::", you are expected to provide R code to implement the
function and these should be provided in the R script. le. I have denoted the questions with [R].
For all other questions, you may make use of R functions but are not required to produce R code. However,
answers should be provided in the pdf of solutions with mathematical workings included if appropriate.
Only two les should be submitted and the le names must be of the form. XX YYYYYYYY ZZZZ.R
and XX YYYYYYYY ZZZZ.pdf, where XX denotes workshop group number (not lab group),
YYYYYYYY denotes your student number and ZZZZ denotes your name. For example, if you are John
Smith with student number 38009152 and in workshop W3, then your lenames should be:
W3 38009152 JohnSmith.R and W3 38009152 JohnSmith.pdf
Failure to follow the above procedures will lead to mark deductions.
Deadline: 17.00 on Friday 16 March (Week 19)
Extreme temperatures either hot or cold can present a severe risk to life. A young deers chances of
surviving its rst winter depends upon the minimum temperature over the course of the winter. Let T
denote the minimum temperature (in oC) over the winter with the survival probability given by
(T) = exp(0:5fT + 12g)1 + exp(0:5fT + 12g):
This corresponds to a 50% chance of surviving if the minimum temperature is 12oC.
Let X denote the minimum temperature for the winter and suppose that X has probability density
function
f(x) = 0:5 exp (0:5(x+ 7)) exp ( exp (0:5(x+ 7))) (x2R):
This is a Gumbel distribution with cumulative distribution function
F(x) = 1 exp ( exp (0:5(x+ 7))) (x2R):
The probability P that a deer survives a winter is
P = E
exp(0:5fX + 12g)
1 + exp(0:5fX + 12g)
Z 1
exp(0:5fx+ 12g)
1 + exp(0:5fx+ 12g)f(x)dx:
1. [R] Write a function phi with input t, temperature to compute the probability of a deer surviving
the winter given the minimum temperature is t. [2 marks]
2. [R] The function winter in Winter.R can be used to simulate n values from X. Using Monte Carlo
integration, and showing the R code, estimate P and denote the estimate ^P. [3 marks]
A scientist is interested in the probability that the minimum temperature will drop below 20oC during
the course of a winter. Let = P(X < 20).
3. Use Monte Carlo integration to integrate by drawing 10000 samples from the Gumbel distribution,
X. [1 mark]
4. [R] Write a function G in R for simulating n samples from a random variable Z with probability
density function, [2 marks]
g(z) =
0:5 exp(0:5(20 +z)) if z< 20
0 otherwise:
Hint: If W Exp(0:5), then Z = 20 W has the correct distribution.
5. [R] Write a function f in R for computing f(x), where f(x) is the probability density function of
the Gumbel distribution de ned above. [2 marks]
6. Derive an unbiased estimate of using samples z1;z2;:::;zn from the random variable Z. Express
your solution as simply as possible. [2 marks]
7. [R] Write a function to generate an unbiased estimate of using n samples from Z. Your function
should only have n, the number of samples as input and should call your function G to generate n
values from Z. Apply your function with n = 10000 to obtain an estimate of . [3 marks]
In the le Winter temp.txt are the minimum temperatures in oC for a given location for the past 50
years. We can read in the data using temps=scan("Winter temp.txt").
8. Find the median temperature from the sample. [1 mark]
9. [R] Write an R function to compute bootstrap estimates of the median temperature with inputs
the temperature data and boot, the number of bootstrap samples. [3 marks]
10. Using your bootstrap function and the data temps, estimate the probability that the median mini-
mum temperature is less than 8oC. [1mark]

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!