MATH 377
MOCK MIDTERM EXAM - I
Financial and Actuarial Modelling in R
1.
(a) Use the following code to generate a vector of length 5 with entries filled with integer numbers between 0 and 9:
sample(0 : 9 , 5 , replace = T)
(i) Write an R program that returns TRUE if the elements of the vector are in increasing order. [3 marks]
(ii) Write an R program to compute the average of those entries that are above 2. Note: return 0 if none of the entries is above 2. [2 marks]
(b) Consider a vector of student grades with values 70, 80, 55, 67, 90, 92, 83, 74, 100, 87, 49, and a vector with the month of birth of the students with values ”Jan” , ”Nov” , ”Dec” , ”Feb” , ”Feb” , ”Nov” , ”Jun” , ”May” , ”Apr” , ”Jan” , ”Jul” .
(i) Create a data frame with the above data. [2 marks]
(ii) Find the average grade for those students born in February. [2 marks]
(c) We know that for |x| < 1
Use the series representation above, up to a finite number of terms N = 100, to compute log(0.3). [3 marks]
2. Let Y be Gamma distributed with shape parameter 2 and scale parameter
1, that is, the density function of Y is given by
y2−1e−y , y > 0 .
Now, consider
X = 1/Y .
(a) Write an R function to compute the distribution function of X .
|
[3 marks]
|
(b) Simulate a sample of size 2500 from X .
|
[2 marks]
|
(c) Approximate E[(1/Y2 )] using your simulated sample in (b).
|
[2 marks]
|
3. Let X be Lognormal distributed with parameters µ = −2 and σ = 2. Recall that the density function of a lognormal distribution with parameters µ ∈ R and σ > 0 is given by
x > 0 .
(a) Simulate a sample of size 1000 from X . [2 marks]
(b) With your simulated sample in (a), plot the loglikelihood function for param- eter values µ between -3 and -1, and σ between 1 and 3. [3 marks]
(c) Using the maximum likelihood estimation method, fit the following distribu- tions to the simulated data set:
(i) Lognormal. [2 marks]
(ii) Weibull. [2 marks]
(d) Which fitted distribution seems to describe the data better? Justify your answer. [2 marks]