%% nclexample.tex
%%    GRS - 09/10/09 (updated to current format)
%%    GRS - 12/10/06 (updated to current format)
%%    DJW - 17/10/98
%% Example of using the nclexam style fle with latex2e:
%%  needs style file nclexam.sty .
%% (Style file also works with old latex.)

\documentclass[11.5pt,a4paper]{article}
%% NB: 11 pt is needed for most verbose front-page instructions.
%\documentclass[11pt,a4paper]{article}

\usepackage{nclexam2,amsmath,amssymb}
\usepackage{graphicx,ifthen,color,microtype}

%%ngrs:  set write-on paper booleans to false here
%%  (set appropriately below, if nec., with appropriate rubrics)
\newboolean{writeon} 
\setboolean{writeon}{false}
\newboolean{writeonsectaonly}
\setboolean{writeonsectaonly}{false}

\newcommand{\expt}{\mathsf{E}}
\newcommand{\var}{\mathsf{var}}
\newcommand{\cov}{\mathsf{cov}}

%% Declare exam information here

\moduleno{CIV2002 SPECIMEN PAPER}
\modulename{Environmental Extremes: Mid--semester test} %% Use mixed case
\semester{2}              %% Use 0 for resits
\year{2015/2016}
%\month{AUGUST}           %% Upper case. Needed only for resits (\semester{0})
%\year{2010}              %% Just use year in August for resits
\prof{Fawcett}             %% Module leader (not currently used)

%% Choose the rubric appropriate for the paper:
%%   Rubric A: Stage 1, Stage 4 papers w/ no choice.
%%     (No sections, all compulsory.)
%%   Rubric B: Stage 2-3 papers, plus Stage 4 variants of Stage 3 papers
%%     (with different Section A:B splits).
%%     (Sections A and B, all compulsory.)
%%   Rubric D: Stage 4 papers w/ choice.
%%     (No sections, some choice.)
%%   Rubric E: MAS8114 only.
%%     (Compulsory section A, choose 1 of 3 in Section B.)

\rubric{A}                %% NB: need comment out \sect{A}, \sect{B}, below.
\numquestions{TWO}       %% Upper case. Number of questions.
%% Write time in hours and minutes
\time{50 minutes}  %% For Stage 1
%\time{2 hour 15 minutes}  %% For Stage 4 module w/o significant ICA
%\time{2 hour}             %% For Stage 4 module w/ significant ICA
%% Set booleans to true for write-on format.
%% roughpages are only added if writeon is true
%% (nb: roughpages must be defined if writeon is true, even if 0 are needed)
\setboolean{writeon}{true}  %% Set to true (false) for (non-)write-on format
%\roughpages{2}            %% No. of rough work pages at end of paper

%\rubric{B}
%\numSectA{THREE}            %% Upper case.  Number of section A questions.
%\numSectB{FOUR}            %% Upper case.  Number of section A questions.
%\time{1 hour 30 minutes}  %% For 10 credit papers. Write in hours and minutes.
%\time{2 hour 15 minutes}  %% For 20 credit papers. Write in hours and minutes.
%\setboolean{writeon}{true}  %% Set to true (false) for (non-)write-on format
%\setboolean{writeonsectaonly}{true}  %% Subsidiary choice
%\roughpages{0}              %% No. of rough work pages at end of paper

%\rubric{D}                %% NB: need comment out \sect{A}, \sect{B}, below.
%% Should be either:
%%  4 of 6 questions for 2 1/4 hour exam (Stage 4 module w/o significan ICA);
%%  3 of 4 questions for 2 hour exam     (Stage 4 module w/  significan ICA).
%\numquestions{SIX}       %% Upper case.  Number of questions.
%\attempt{FOUR}             %% Upper case.  Number of questions to attempt.
%\time{2 hour 15 minutes} %% Write in hours and minutes
%\numquestions{FOUR}       %% Upper case.  Number of questions.
%\attempt{THREE}             %% Upper case.  Number of questions to attempt.
%\time{2 hour} %% Write in hours and minutes

%\rubric{E}
%\time{2 hours 15 minutes} %% Write in hours and minutes

%% Use one of these (or define new combinations), if needed.
\extrainstructions{}  
%\extrainstructions{Calculators may be used.}
%\extrainstructions{Calculators may not be used.}

%\extrainstructions{Graph paper and statistical tables will be provided.} 
%\extrainstructions{Graph paper will be provided.} 
%\extrainstructions{Statistical tables will be provided.} 

\extrainfo{} % usually blank
\briefextrainfo{} % usually blank

% for further details, see the style file itself.

%%ngrs: add macro for answer gap.  
%% NB: Only inserts gap if writeon is true
\newcommand{\answergap}[1]{\ifthenelse{\boolean{writeon}}{         

\parbox[c][0.7cm][c]{\textwidth}{\bf Answer:} 
\parbox[c][#1][c]{\textwidth}{}
}{}
}

%%%ngrs: add macro for margins for write-on papers
\definecolor{MyGray}{rgb}{0.7,0.7,0.7}
\newcommand\marginline{
\setlength{\unitlength}{1.0cm}
\begin{picture}(0,0)
  \put(0,2){\textcolor{MyGray}{\line(0,-1){40}}}
\end{picture}
}

%%%ngrs: add macro for subsection marks, for questions worth > 20 marks
\newcommand{\submarks}[1]{\ \newline \makebox[5.39truein]{\ \hfill [\bf #1\ marks]}}
\newcommand{\subsinglemark}[1]{\ \newline \makebox[5.39truein]{\ \hfill [\bf #1\ mark]}}
\begin{document}
\makefront % produce the front page

%%%ngrs: change fancyhdr to add margins for write-on pages
\ifthenelse{\boolean{writeon}}{\fancyhead[L]{{\marginline}\textcolor{MyGray}{Please leave margins blank}}}{}


\vspace{1cm}

\textbf{Exponential distribution}:

\vspace{0.05cm}

If $X\sim Exp(\lambda)$, then it has distribution function
\[
F_{X}(x;\lambda)=1-e^{-\lambda x},
\]
$x>0,\lambda>0$.

\vspace{1cm}

\textbf{Generalised Extreme Value distribution}:

\vspace{0.05cm}

If $X\sim GEV(\mu,\sigma,\xi)$ then it has distribution function
\[
G_{X}(x;\mu,\sigma,\xi)=\left\{ \begin{array}{c c}
\textrm{exp}\left\{-\left[1+\xi\left(\displaystyle \frac{x-\mu}{\sigma}\right)\right]_{+}^{-1/\xi}\right\}, &\xi \neq 0; \\
& \\
\textrm{exp}\left\{-\textrm{exp}\left[-\left(\displaystyle \frac{x-\mu}{\sigma}\right)\right]\right\}, &\xi=0, \end{array} \right.
\]
$-\infty<\mu<\infty,-\infty<\xi<\infty, \sigma>0, a_{+}=\textrm{max}(0,a).$

\vspace{1cm}

\textbf{Generalised Pareto distribution}:

\vspace{0.05cm}

If $X\sim GPD(\tilde{\sigma},\xi)$ then it has distribution function
\[
H_{X}(x;\tilde{\sigma},\xi)= \left\{ \begin{array}{c c} 
             1-\left(1+\displaystyle \frac{\xi x}{\tilde{\sigma}}\right)_{+}^{-1/\xi}, &\xi\neq 0; \\
& \\
             1-\textrm{exp}\left(-\displaystyle \frac{x}{\tilde{\sigma}}\right) &\xi=0,\end{array} \right.
\]
$-\infty<\xi<\infty, \tilde{\sigma}>0, a_{+}=\textrm{max}(0,a)$. 

\vspace{1cm}




\newpage
\raggedright
%\sect{A} % begin Section A 


\begin{question}{Total = 9}
\begin{itemize}
\item [(a)] For the GPD, we have:
\[
P(X>x) = \lambda_{u}\left[1+\xi\left(\frac{x-u}{\sigma}\right)\right]_{+}^{-1/\xi}.
\]
Thus, for location A, we have:
\[
P\left(X_{A}>32\right) = 0.009\left[1+0.184\left(\frac{32-30}{7.440}\right)\right]^{-1/0.184} = 0.006923.
\]
Similarly, for location B we have $P\left(X_{B}>32\right) = 0.004051$.  Hence, assuming independence, we have
\[
P\left(X_{A},X_{B}>32\right) = 0.006923 \times 0.004051 = 0.00002805.
\]
\item [(b)] 
\begin{itemize}
\item [(i)] We must transform the margins to be unit Fr\'{e}chet-distributed.
\item [(ii)] We would differentiate $G(x,y)$ with respect to $x$ only (where $x$ represents threshold excesses at location A).  We would then substitute the transformed threshold exceedance into this derivative for the rainfall total at location A (i.e. $\tilde{x}_{A}$ for $x$) and the transformed threshold for location B (i.e. $\tilde{u}_{B}$ for $y$).  
\item [(iii)] \textcolor{red}{[There was a typo in the question here - should be ``32mm = ...'' and NOT ``50mm = ...'']}  

We have
\[
P\left(X_{A}, X_{B}>32\right) = 1-\textrm{exp}\left\{-(986.461^{-1/0.623}+1605.221^{-1/0.623})^{0.623}\right\} = 0.00128.
\]
This value is almost 46 times larger than when we assumed independence.  This could result in huge under-protection if a flood defence was built to protect against such a combination of extremes at both locations, and rainfall between the locations was assumed independent. 
\end{itemize}
\end{itemize}
\end{question}
\end{document}


After each of the following statements, delete as appropriate. {\small \textbf{(4 marks)}}
\\
\\
The 50 year return level for daily temperatures in Seville, Spain, is $44.7^{\textrm{o}}\textrm{C}$.  Thus, in the next 100 years we will see temperatures of at least $44.7^{\textrm{o}}\textrm{C}$ on two days.  {\large \textbf{TRUE/\textcolor{white}{FALSE}}}
\\
\\
In the limit, the shape parameters in the Generalised Extreme Value distribution and the Generalised Pareto distribution are equivalent.   {\large \textbf{\textcolor{white}{TRUE}/FALSE}}
\\
\\
Confidence intervals for return levels using the profile log-likelihood usually have a higher upper bound than those obtained assuming Normality.  {\large \textbf{\textcolor{white}{TRUE}/FALSE}}
\\
\\
A Fr\'{e}chet distribution might be appropriate for data on sunshine hours as the limiting distribution has a finite upper bound.  {\large \textbf{TRUE/\textcolor{white}{FALSE}}}

\vspace{0.75cm}

\item [(b)] Analyses of extreme wind speeds (miles per hour) at a location on the US east coast are summarised in the table below. Values in parentheses are standard errors.  

\vspace{0.5cm}

\begin{center}
\begin{tabular}{|c|c c c|c c c|} \hline
                &\multicolumn{3}{c|}{Estimated parameters}   &\multicolumn{3}{c|}{Return level estimates $\hat{z}_{r}$} \\
                & Location        &Scale     &Shape         &$r=10$   &$r=50$  & $r=200$    \\ \hline
Annual maxima: GEV &67.2    &7.3  &--1.2   &73.1  &72.5    &85.3  \\ 
                    & (13.3)      &(2.2)      &(0.2)        &(10.0)    &(11.3)   &(13.5) \\  \hline
Threshold excesses: GPD & ---     &6.8   &0.1    &73.6   &78.3  &86.2  \\ 
                        &         &(1.9)      &(0.1)       &(15.2)      &(7.1)    &(6.9) \\ \hline
\end{tabular}
\end{center}

\vspace{0.5cm}

Identify \textbf{four} things in this table which you think are suspicious, and say \textit{why} you think they are suspicious.  {\small \textbf{(8 marks)}}
\answergap{0cm}
{\color{white}

\begin{itemize}
\item $\xi=-1.2$ in the GEV - very unusual, and technically MLEs for $\xi$ don't exist for $\xi<-1$
\item In the annual maxima analysis, $\hat{z}_{50}<\hat{z}_{10}$.  IMpossible, as $z_{r}$ increases as $r$ increases, as we're moving further into the tail.
\item Larger standard errors for $\hat{z}_{10}$ in the threshold analysis - not impossible, but unusual given the potential for including more data here.
\item Decreasing standard errors in the threshold analysis for return levels as $r$ increases -- these usually get larger as we extrapolate further away from the data.
\end{itemize}
}

\vspace{3.5cm}


\end{itemize}

\end{question}

\newpage

\begin{center}
\textit{[This page has been left blank for your solution to the last question, \textbf{should you need it}]}
\end{center}

\vspace{17cm}



\newpage


\begin{longquestion}{Total = 38}

\vspace{-1.3cm}

\noindent At midday every day since January 1st 1965 the sea level at a location in the Venetian Lagoon, $X$ centimetres, has been recorded.  These sea level recordings are complete to the end of last year (2015).  

\begin{itemize}
\item [(a)] Analysts at the \textit{European Climate Data Consortium} (ECDC) extract the set of annual maximum sea levels from records at this location and store them in the vector \texttt{anmax} in \textsf{R}.  Use the ECDC's (edited) output below to help you answer the following questions.
\begin{verbatim}
> library(ismev)
> gev.fit(anmax)$cov          
$conv
[1] 0

$nllh
[1] 10.7145

$mle
[1] 111.09925486  17.17548761  -0.07673265

            [,1]        [,2]         [,3]
[1,]  6.90642105  1.16790535 -0.057843529
[2,]  1.16790535  3.25213339 -0.036209952
[3,] -0.05784353 -0.03620995  0.005405396
\end{verbatim}

\vspace{0.3cm}

\begin{itemize}
\item [(i)] The generalised extreme value (GEV) distribution has been fitted to the set of annual maxima.  Circle the value of the maximised GEV likelihood. {\small \textbf{(1 mark)}}

\vspace{0.5cm}

\begin{center}
\begin{tabular}{c c c c c c c c}
  \textbf{10.7145}  &     &\textcolor{white}{\textbf{0.0000222}} &     &\textbf{--10.7145} &   & \textbf{227.5612}
\end{tabular}
\end{center}

\vspace{0.5cm}

\item [(ii)] Would you be satisfied that the function used has obtained the maximum likelihood estimates of the GEV?  Briefly explain. {\small \textbf{(2 marks)}}
\answergap{0cm}
{\color{white} Yes -- the convergence code is zero.}

\vspace{2cm}

\item [(iii)] Obtain 95\% confidence intervals for each of the estimated GEV parameters. \\ {\small \textbf{(6 marks)}}
\answergap{0cm}
{\color{white}
\begin{eqnarray*}
\mu &:& 111.099 \pm 1.96 \times \sqrt{6.906} = (105.948, 116.250) \\
\sigma &:& 17.175 \pm 1.96 \times \sqrt{3.252} = (13.640, 20.710) \\
\xi &:& -0.077 \pm 1.96 \times \sqrt{0.005} = (-0.216, 0.062)
\end{eqnarray*}
}


\end{itemize}

\newpage

\begin{center}
\textit{[Part of this page has been left blank for your solution to the previous question]}
\end{center}

\vspace{6cm}
\begin{itemize}
\item [(iv)] Estimate the 100 year return level for this location in the Venetian Lagoon. \\ {\small \textbf{(3 marks)}}
\answergap{0cm}
{\color{white}
\[
\hat{z}_{100} = 111.099 + \frac{17.175}{-0.077}\left[\left(-\textrm{log}\left(1-\frac{1}{100}\right)\right)^{0.077}-1\right] = 177.63\textrm{ cm}.
\]}

\vspace{2cm}

\item [(v)] Current research suggests catastrophic flooding in Venice if sea levels at this location exceed two metres.  Use the fitted GEV to estimate the probability of catastrophic flooding in Venice in any given future year. {\small \textbf{(3 marks)}} 
\answergap{0cm}
{\color{white}
\[
P(X>200) = 1-\textrm{exp} \left\{\left[1-0.077\left(\frac{200-111.099}{17.175}\right)\right]^{1/0.077}\right\} = 0.0014.
\]
}
 
\end{itemize}

\newpage

\item [(b)] Researchers at \textit{Ca' Foscari} University, in Venice, adopt a different modelling approach to the ECDC.  Their investigations suggest an exponential distribution for the daily sea level observations at this location, that is,
\[
X|\zeta \sim \textrm{\it Exp}(\zeta).
\]
They decide to take a threshold-based approach to modelling sea level extremes. 
\begin{itemize}
\item [(i)] Show that, above some high threshold $u$, the distribution of excess over $u$ is Generalised Pareto (GP) with scale $1/\zeta$ and shape 0. {\small \textbf{(7 marks)}}
\answergap{0cm}

{\color{white}
We need
\begin{eqnarray*}
\frac{1-F(u+y)}{1-F(u)}  &=& \frac{1-\left\{1-\textrm{exp}\left[-\zeta(u+y)\right]\right\}}{1-\left\{1-\textrm{exp}\left[-\zeta u\right]\right\}} \\
& & \\
  &=&\frac{e^{-\zeta(u+y)}}{e^{-\zeta u}}  \\
& & \\
&=&  e^{-\zeta y} (*).
\end{eqnarray*}

(*) is the survival function of an exponential distribution; thus, the GPD shape parameter is $\xi=0$.  Comparing $e^{-y/\sigma}$ to $e^{-\zeta y}$ we see that the GPD scale parameter must be $\sigma=1/\zeta$, so we have
\[
\textrm{GPD}\left(\sigma=1/\zeta, \xi=0 \right) \sim \textrm{exp}(1/\sigma).
\]
}


\newpage

\item [(ii)] Construct the log-likelihood function for the GP scale parameter in (i) and obtain the maximum likelihood estimator for this parameter.  Confirm that your estimator does indeed maximise the log-likelihood. {\small \textbf{(6 marks)}}  

\answergap{0cm}
{\color{white}
\noindent Can use $\textrm{exp}(\zeta)$ then set $\hat{\sigma}=1/\hat{\zeta}$, or use directly:
\begin{eqnarray*}
h(\sigma|\boldsymbol{y}) &=& \prod_{i=1}^{n} \left(\frac{1}{\sigma}\right) e^{-\left(\frac{1}{\sigma}\right)y_{i}} \\
& & \\
&=&\sigma^{-n}e^{-n \bar{y} \sigma^{-1}}.
\end{eqnarray*}
Thus,
\begin{eqnarray*}
\textrm{log }h(\sigma|\boldsymbol{y}) &=&-n \textrm{log }\sigma -n\bar{y}\sigma^{-1},
\end{eqnarray*}
and therefore
\begin{eqnarray*}
\frac{d}{d \sigma}\textrm{log }h(\sigma|\boldsymbol{y}) &=& -n\sigma^{-1}+n\bar{y}\sigma^{-2} \quad (**) \quad \textrm{and} \\
 & & \\
\frac{d^{2}}{d \sigma^{2}} \textrm{log }h(\sigma|\boldsymbol{y}) &=& \frac{n}{\sigma^{2}} - \frac{2n\bar{y}}{\sigma^{3}}.
\end{eqnarray*}
Equating (**) to zero, replacing $\sigma$ with $\hat{\sigma}$ and solving for $\hat{\sigma}$ gives
\begin{eqnarray*}
n \hat{\sigma}^{2} &=& n \bar{y} \hat{\sigma} \\
& & \\
        \hat{\sigma} &=& \bar{y}.
\end{eqnarray*}
Checking for a maximum, when $\hat{\sigma}=\bar{y}$ we have:
\[
\frac{d^{2}}{d \sigma^{2}} \textrm{log }h(\sigma|\boldsymbol{y}) = -\frac{n}{\bar{y}^{2}} < 0,
\]
hence we have a maximum.
}


\newpage

\item [(iii)] The $r$-year return level for this model is given by
\[
z_{r} = u+\frac{\textrm{ log}(rn_{y}\lambda_{u})}{\zeta},
\]
where $\lambda_{u}=\textrm{Pr}(X>u)$ and $n_{y}$ is the average number of observations per year.  765 sea level observations exceed a chosen threshold of $u=145\textrm{cm}$, giving
\[
\sum_{i=1}^{765}(x_{i}-u) = 3912.2\textrm{ cm}.
\]
Estimate the 100 year return level using the threshold-based approach for modelling extremes. {\small \textbf{(5 marks)}}\\
\textit{[Hint: 12 years are leap years over the data collection period 1965--2015]}  
\answergap{0cm}
{\color{white}
\begin{eqnarray*}
\hat{\lambda}_{u} &=& \frac{765}{(12 \times 366)+(39\times 365)} = 0.041 \\
& & \\
\hat{\zeta}  &=& \left(\frac{3912.2}{765}\right)^{-1} = 0.1955.
\end{eqnarray*}
Thus
\[
\hat{z}_{100} = 145 + \frac{\textrm{log }(100\times 365.25 \times 0.041)}{0.1955} = 182.399 \textrm{ cm}.
\]
}


\newpage

\item [(iv)] Complete the following variance-covariance matrix for $(\hat{\lambda}_{u},\hat{\zeta})^{\textsf{T}}$.  You may use the space below to show any working, should you need to. {\small \textbf{(2 marks)}} 
\answergap{0cm}
\[
V = \left(\begin{array}{c c} \\
            \_  \_  \_  \textcolor{white}{ 2.11} \_  \_ \_   \times 10^{-6}             &\textcolor{white}{LFLFLF}\_  \_  \_  \_ \textcolor{white}{0}  \_ \_  \_ \_ \textcolor{white}{LFL}    \\
& \\
& \\
  0                    & \textcolor{white}{LFL} 5.2307   \\ \end{array} \right).
\]
\vspace{3.2cm}


\end{itemize}

%\item [(c)] In (a)(iv) and (b)(iii) you estimated the 100-year return level for this location in the Venetian Lagoon using a block maxima approach, and a threshold-based approach, respectively.  Explain how you think the standard errors for this return level would differ between these two modelling approaches.  Justify your answer, but do not attempt to calculate the standard errors.  {\small \textbf{(2 marks)}}
%\answergap{6.5cm}

\item [(c)] Describe two potential problems with the threshold-based approach used throughout part (b).  Why might these problems not be an issue in the analysis in part (a)?  {\small \textbf{(3 marks)}}
\answergap{0cm}

{\color{white}
\begin{itemize}
\item Seasonal variability 
\item Dependence
\item Not an issue in a block maxima analysis as we oinly have one observation per year 00 usually more than enough to avoid such issues
\end{itemize}
}

\vspace{7cm}

\end{itemize}
\end{longquestion}


\theend

\end{document}
