首页 > > 详细

代写STAT2003、辅导Python编程语言

Mathematical Probability (STAT2003/STAT7003)
Assignment 2
The due date/time is given on Blackboard. STAT7003 students have additional question(s), marked
with a star (*).
1. Suppose a random variable X has pdf f given by.
(a) Derive the cdf F of X. [2 marks]
(b) Specify pseudo-code for an inverse-transform method to simulate X. [2 marks]
(c) Implement the algorihm in (b) to simulate 10,000 independent realizations of X. Use these to
verify that the algorithm is sampling correctly from the pdf f . [4 marks]
2. Let X have pdf.
(a) Plot f (x) for x ∈ [0, 20], using Python. [2 marks]
(b) Let g be the pdf defined by.
Find a constant c ≥ 1 such that c g(x) ≥ f (x) for all x. [2 marks]
(c) Write pseudo code for an acceptance–rejection algorithm to simulate X. [3 marks]
(d) Implement the algorithm in (c) in Python and simulate 10,000 independent samples. You may
use the following Python code as a framework for the implementation and for verifying that
the algorithm is sampling correctly from f . [4 marks]
import matplotlib.pyplot as plt
from numpy.random import rand
from numpy import arange, cos, pi, zeros
alpha = 2/pi
def f(x):
return alpha*(1 - cos(x))/x**2
def g(x):
# complete yourself
1
def Ginv(u):
# complete yourself
N = 10000 # sample size
xx = zeros(N) # array to store the samples. Set to zeros initially
# Put here the acceptance rejection method that fills the vector xx
for i in arange(1,N):
# complete yourself
# ....
xx[i] = x
xxtrunc = xx[xx < 20] # vector that contains only samples less than 20
plt.figure(figsize = [4,2])
# plot only the histogram for samples less than 20
plt.hist(xxtrunc,bins=100,density=True)
t = arange(0, 20, 0.01)
plt.plot(t,f(t)) #plot the true pdf
3. Let X and Y be two discrete random variables with joint probability mass function (pmf)

(a) Determine the (marginal) pmf of Y . [1 mark]
(b) Find P(X ≤ 3,Y ≤ ?1). [1 mark]
(c) Find Var(X). [2 marks]
(d) Calculate Cov(3X, 4Y). [2 marks]
(e) (*) Find E (Y?n). [1 mark]
(f) (*) Find the pmf of Z = (X ? 2)2. [2 marks]
(g) (*) What proportion of the distribution of X is within 1.5 standard deviations of the mean?
[2 marks]
4. The owner of a laundry shop is replacing 10 of their washing machines with a new model. The
lifetime (in years) of this new model of washing machine can be modelled by a Gamma distribution
with mean 8 years and variance 16 years.
(a) Specify the probability density function (pdf) of the lifetime of this new model of washing
machine. [2 marks]
(b) The new model washing machine comes with a warranty period of five years. What is the
probability that at least 7 of the 10 washing machines will have a lifetime beyond the warranty
period? [3 marks]
2
5. A local restaurant serves both dine-in and takeaway customers. Suppose that the time until the
next dine-in customer can be modelled by an exponential distribution with mean three minutes.
Similarly, the time until the next takeaway customer can be modelled by an exponential distribution
with mean two minutes, independent to the distribution of dine-in customer. What is the probability
that the next customer will be a takeaway customer? [4 marks]
6. Let X and Y be two continuous random variables with finite variances.
(a) Show that Cov(X + Y, X ? Y) = Var(X) ? Var(Y). [3 marks]
(b) Show that E [XE(Y | X)] = E(XY). [1 mark]
(c) Find the correlation between X and Y ? E(Y | X). [3 marks]
(d) Show that Var [Y ? E(Y | X)] = E [Var(Y | X)]. [3 marks]
7. Let X ~ Exp(1) and Y = XU2, where U ~ U(0, 1) is independent of X.
(a) Give the joint pdf of X and Y and specify the region where it is non-zero. [3 marks]
(b) Sketch or simulate a typical point cloud of many independent realizations of the vector (X,Y).
[2 marks]
(c) Find the (marginal) pdf of Y and express it in terms of the cdf Φ of the standard normal
distribution. You may use Mathematica or Wolfram Alfa to verify your answer. [3 marks]
(d) Derive the conditional pdf of X given Y = 1. [2 marks]
8. * Let X have pdf in Question 2.
(a) Find EX. [1 mark]
(b) Find E cos(tX) for all t ∈ [0, 1]. You may use here Mathematica or Wolfram Alfa. [2 marks]
(c) Let T ~ U(0, 1) be independent of X. By conditioning on T , calculate E(TX) and E cos(TX).
Verify your answers via simulation, using the acceptance–rejection method in Question 2.
[3 marks]

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

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