Description
1 Lab
In this lab, you will learn how to use R to find a minimum of function and to generate random variables from a given CDF which does not have its inverse in closed form.
1. Function nlm() in R can be used to find a minimum of a nonlinear function.
a. Define a function )) in R and use nlm() to find the minimum of this function.
b. As you have learned, to generate a random variable Z from a continuous distribution with given CDF FZ(z), one can follow these steps:
i. Generate U โผ U(0,1)
ii. Compute Z = FZโ1(U)
The quantile function FZโ1(q) might not be available in closed form and can be computed numerically. For a strictly increasing CDF FZ(z) there exists a unique solution to the equation: FZ(zq) = q. It implies the function GZ(z) = (FZ(z)โq)2 attains its minimum (which is zero) at z = zq. The point zq at which this minimum is attained can be found using nlm() function in R, and one can follow these steps to generate a random variable Z in this case:
i. Generate U โผ U(0,1)
ii. Compute Z = argminz(FZ(z) โ U)2
Use this approach to generate a sample of size N = 1000 from a continuous random variable with the PDF:
,
Draw a histogram of the generated data.
2. A similar approach can be used to generate a random pair (X,Y ) from a continuous bivariate distribution with given joint CDF FX,Y (x,y). Define
,
where FX(x) and fX(x) are the marginal CDF and PDF of X, respectively. Assuming FX(x) and FY |X(y|x) are strictly increasing and continuously differentiable functions of x and y, respectively, one can follow these steps to generate a random pair (X,Y ):
a. Generate independent UX โผ U(0,1) and UY โผ U(0,1)
b. Compute
c. Compute
The inverse CDFs FXโ1 and can be computed numerically using nlm() function if they are not available in closed form.
a. Bonus: Show that the joint CDF of (X,Y ) generated using the algorithm above is FX,Y .
b. Use this algorithm to generate a sample of size N = 1000 from a continuous bivariate random variable (X,Y ) with the joint PDF:
,
Draw a scatter plot of the generated data.
2 Workshop
1. a. A random sample X1,…,Xn of size n is taken from a Poisson distribution with mean ฮป > 0.
i. Show the maximum likelihood estimator of ฮป is ฮปห = Xยฏ.
ii. Suppose with n = 40 we observe 5 zeros, 7 ones, 12 twos, 9 threes, 5 fours, 1 five, and 1 six. What is the maximum likelihood estimate of ฮป.
b. Find the maximum likelihood estimator, ฮธห, if X1,ยทยทยท ,Xn is a random sample from the following probability density function:
f(x;ฮธ) = (1/2)exp(โ|x โ ฮธ|),โโ < x < โ,0 < ฮธ < โ
This involves minimizing , which is difficult. Try n = 5 and a sample 6.1, -1.1, 3.2, 0.7, 1.7.Then deduce the MLE.
2. Let f(x;ฮธ) = ฮธxฮธโ1, 0 < x < 1, ฮธ โ โฆ = {ฮธ : 0 < ฮธ < โ} and let X1,…,Xn denote a random sample from this distribution. Note that
a. Sketch the p.d.f. of X for ฮธ = 1/2 and ฮธ = 2.
b. Show that ) is the maximum likelihood estimator of ฮธ.
c. For each of the following three sets of observations from this distribution compute the maximum likelihood estimates and the methods of moments estimates.
X Y
Z
0.0256 0.9960 0.4698
0.3051 0.3125 0.3675
0.0278 0.4374 0.5991
0.8971 0.7464 0.9513
0.0739 0.8278 0.6049
0.3191 0.9518 0.9917
0.7379 0.9924 0.1551
0.3671 0.7112 0.0710
0.9763 0.2228 0.2110
0.0102 0.8609 0.2154
(Pni=1 ln(xi) = โ18.2063, Pni=1 ln(yi) = โ4.5246, Pni=1 ln(zi) = โ10.42968, Pni=1 xi = 3.7401, Pni=1 yi = 7.0592, Pni=1 zi = 4.6368.)
3. Let X1,…,Xn be a random sample from the exponential distribution whose p.d.f. is f(x;ฮธ) = (1/ฮธ)exp(โx/ฮธ), 0 < x < โ, 0 < ฮธ < โ.
a. Show that Xยฏ is an unbiased estimator of ฮธ.
b. Show that the variance of Xยฏ is ฮธ2/n. What is a good estimate of ฮธ if a random sample of size 5 yielded the values 3.5, 8.1, 0.9, 4.4 and 0.5?
4. Let X1,…,Xn be a random sample from a distribution having finite variance ฯ2. Show that is an unbiased estimator of ฯ2. HINT: Write
!
and compute E(S2).
5. Let X1,…,Xn be a random sample of size n from the distribution with p.d.f. f(x;ฮธ) = (1/ฮธ)x(1โฮธ)/ฮธ, 0 < x < 1.
a. Show the mean of X is E(X) = 1/(1 + ฮธ).
b. Show the maximum likelihood estimator of ฮธ is
c. Is the MLE unbiased? (You can do this using integration by parts combined with
rules about expectation of the sample mean.)
d. Show the method of moments estimator of ฮธ is
.
Reviews
There are no reviews yet.