\documentclass[11pt]{article}
\usepackage{amsmath,amssymb}
%\usepackage{fancyhdr}

\parindent=0cm
\parskip .2cm
\textheight 21.7cm
%\pagestyle{fancy}

%\lhead{\nouppercase{\rightmark}}
%\rhead{\nouppercase{\leftmark}}
%\fancyhead[LE,RO]{\thepage}
%\fancyfoot[]{}

\def\bo#1{\mbox{\boldmath $#1$}}
\def\rang{\mathop{\rm rang}}
\def\tr{\mathop{\rm tr}}

\newtheorem{oppgave}{Oppgave}


\begin{document}
\thispagestyle{empty}

{\bf \Large Second mandatory assignment in STK3100/STK4100-f16 }

Posted:   Friday October 21th.

Deadline: Thursday November 10th, 14:30 pm.


This is the second out of two mandatory assignments in STK31000/STK4100-f16.
It consists of two problems. Both handwritten reports and answers
using a word processing system are acceptable. Where you use R (or some other
statistical package) the relevant part of the output must be enclosed or pasted
into the report. It is OK if you cooperate, but each student must deliver a separate
and individually formulated report. Also in case of cooperation it should be indicated
in the report whom the others are. There is more information at:
http://www.mn.uio.no/math/english/studies/admin/mandatory-assignments/index.html


The answers shall be delivered in the box in the hallway  on the 7'th floor
in  Niels Henrik Abels house. Use the standard front page. An English version can be
downloaded from \\
/english/studies/admin/compulsory-activities/mn-math-2015obligforside-eng.pdf \\
and a Norwegian from  \\
www.mn.uio.no/math/studier/admin/obligatorisk-innlevering/obligforside.pdf \\
Remember to indicate whether you attend STK3100 or STK4100.


\vspace{0.25 cm} \noindent \textbf{Problem 1}\\

Consider a one-way layout of the form
\begin{equation}
Y_{ij}=\mu +\alpha_i + \varepsilon_{ij},\;i=1,\ldots,I, \;j=1,\ldots,J
\label{eq:eq1}
\end{equation}
where $E(\varepsilon_{ij} )=0$ and $Var(\varepsilon_{ij} )=\sigma^2$ and
$ \varepsilon_{ij},\;i=1,\ldots,I, \;j=1,\ldots,J $ are
uncorrelated and the constraint $\sum_{i=1}^{I} \alpha_i=0$ is satisfied. For analyzing such
model it is known,  see e.g. Devore and Berk, that the following quantities
are important
\[
SSTr= J\sum_{i=1}^{I}(\bar{Y}_{i\cdot}-\bar{Y}_{\cdot \cdot})^2\;\; {\rm and} \;\;
SSE=\sum_{i=1}^{I}\sum_{j=1}^{J}(Y_{ij}-\bar{Y}_{i\cdot})^2
\]
where $\bar{Y}_{i\cdot}= \frac{\sum_{j=1}^{J}Y_{ij}}{J}$ and
$\bar{Y}_{\cdot \cdot}=\frac{\sum_{i=1}^{I}\sum_{j=1}^{J}Y_{ij}}{IJ}$.
They are also called the sum of squares between and within groups respectively.
\begin{itemize}
\item[a)] Assuming  the fixed effects model (\ref{eq:eq1}) what are the expected values of
SSTr and SSE?  What is a reasonable test statistic for the null hypothesis $\alpha_1=\cdots=\alpha_I=0$? What is the distribution of this statistic under the
null hypothesis if
we in addition assume that $\varepsilon_{ij} \sim N(0,\sigma^2),\;i=1,\ldots,I, \;j=1,\ldots,J$?
\end{itemize}
The random effects or variance component model corresponding to $(\ref{eq:eq1})$ is
\begin{equation}
Y_{ij}=\mu +A_i + \varepsilon_{ij},\;i=1,\ldots,I, \;j=1,\ldots,J
\label{eq:eq2}
\end{equation}
where
where $E(A_i)=E(\varepsilon_{ij} )=0$, $Var(A_i)=\sigma_A^2$, $Var(\varepsilon_{ij} )=\sigma^2$ and
$ A_i, \;\varepsilon_{ij},\;i=1,\ldots,I, \;j=1,\ldots,J $ are
uncorrelated.
\begin{itemize}
\item[b)] Find the expectations of SSTr and SSE under model (\ref{eq:eq2}).
\item[c)] Use the result in part b) to show that
\begin{eqnarray*}
\hat{\sigma}^2=\frac{SSE}{I(J-1)} \\
\hat{\sigma}_A^2=\frac{SSTr}{J(I-1)}- \frac{\hat{\sigma}^2}{J}
\end{eqnarray*}
are unbiased estimators of $\sigma^2$ and $\sigma_A^2$ respectively.
\end{itemize}
From now on we assume that also $ A_i \sim N(0,\sigma_A^2)$ and $\varepsilon_{ij} \sim N(0,\sigma^2),\;i=1,\ldots,I, \;j=1,\ldots,J$.
\begin{itemize}
\item[d)] Formulate model (\ref{eq:eq2}) as a linear mixed effects model
as it is defined in Zuur et al.
\item[e)] Explain why for model  (\ref{eq:eq2})
$SSE/\sigma^2 \sim \chi_{I(J-1)}^2$.
\item[f)] Explain why for model  (\ref{eq:eq2})
$SSTr/(J\sigma_A^2+\sigma^2) \sim \chi_{(I-1)}^2$.
\item[g)] Why are $SSTr$ and $SSE$ independent if
model (\ref{eq:eq2})  is assumed?
\item[h)] Use this to suggest a test for $H_0: \sigma_A^2=0$ versus
the alternative $H_A: \sigma_A^2 > 0$ and find an expression for
the power function.
\item[i)] Plot the power function for the case where
$I=3$, $J=5$, $\sigma^2=1$ and the level is 5\%.
\end{itemize}


\vspace{0.25 cm} \noindent \textbf{Problem 2}\\

The data set \texttt{pigs.txt} on the course web page   contains
weekly observations of the weights  of 16  pigs  for a
period of 9 weeks.


In this problem we will analyze the development of the
weights of the 16 pigs.
\begin{itemize}

  \item[a)]
  Compute the mean of the observed measurements  for each week
  and plot the means as a function of time.
  Plot also, in the same figure, the observed response
  profiles for each of the 16 pigs.
  Describe the main features of the plot.
\end{itemize}
Consider a model of the form
  \[
  Y_{i}=\mathbf{1}_{9}\beta_{1}+ \mathbf{t}_{9}\beta_{2} + \mathbf{e}_{i}, i=1,\ldots,16
  \]
  where the error terms $\mathbf{e}_{i}, i=1,\ldots,16$ are assumed to be independent,
  multivariate normally distributed with expectation $\mathbf{0}$ and a $9 \times 9$ covariance
  matrix $\Sigma$. The vectors $\mathbf{1}_{9}$ and $\mathbf{t}_{9}$ are defined as
  $\mathbf{1}_{9}=(1,1,1,1,1,1,1,1,1)'$ and $\mathbf{t}_{9}=(1,2,3,4,5,6,7,8,9)'$.
\begin{itemize}
\item[b)] Fit a model of the form described above
to the data and find the estimate of the covariance
matrix V. Consider both the case where the covariance matrix
V is unrestricted and the case where the nine variances, i.e. the
elements on the main diagonal of V, are assumed to be equal.
\end{itemize}
In the rest of the problem we consider a linear mixed  effects model of the
form
  \[
  Y_{i}=\mathbf{1}_{9}\beta_{1}+ \mathbf{t}_{9}\beta_{2} + Z_{i}\mathbf{b}_{i} +\epsilon_{i}, i=1,\ldots,16
  \]
  where $b_{i}, i=1,\ldots,16$ and $\epsilon _{i}, i=1,\ldots,16$
  are assumed to be independent,
  multivariate normally distributed random vectors with expectation $0$ and an unstructured  $ q \times q $ covariance
  matrix $G$ and $\sigma^{2}I_{9}$ respectively. The matrices $Z_{i}$ are $9 \times q $
  matrices.
\begin{itemize}
\item[c)] Fit a random intercept and slope model, i.e. let $q=2$ and $Z_{i}=(\mathbf{1}_{9},\mathbf{t}_{9}), i=1,\ldots,16$ and fit the
model to the measurements of the 16 pigs.
What are the estimates of the fixed effects and the estimates of
the variance and covariance of the random effects?
\item[d)] Now, consider a random intercept model, i.e. let $q=1$ and $Z_{i} =\mathbf{1}_{9}, i=1,\ldots,16$ and fit the
model to the measurements of the 16 pigs.
\item[e)] Discuss how the models in part d) and c)
can be compared using a likelihood ratio test.
\item[f)] Compute the estimated (marginal) covariance matrices of $Y_{i}$
using the estimates of the variances and covariances in the  models from parts c) and d) and compare them
to the estimates of $\Sigma$ you found in part b). What is
your impression?
%\item[h] What is the estimated distribution of the measurements
%taken in week 3 from the model fitted in part d) .


\end{itemize}


\end{document}
