% 302f13Assignment1.tex                 REVIEW
\documentclass[12pt]{article} 
%\usepackage{amsbsy} % for \boldsymbol and \pmb 
\usepackage{graphicx} % To include pdf files!
\usepackage{amsmath}
\usepackage{amsbsy}
\usepackage{amsfonts}
\usepackage[colorlinks=true, pdfstartview=FitV, linkcolor=blue, citecolor=blue, urlcolor=blue]{hyperref} % For links
\usepackage{fullpage}
%\pagestyle{empty} % No page numbers


\begin{document}
%\enlargethispage*{1000 pt} 

\begin{center}   
{\Large \textbf{STA 302f13 Assignment One}}\footnote{Copyright information is at the end of the last page.}
\vspace{1 mm}
\end{center}

\noindent
The following formulas will be supplied with Quiz One.
\begin{center}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{ll}
$E(g(X)) = \int_{-\infty}^\infty g(x) \, f_{_X}(x) \, dx$, &
$E(g(\mathbf{X})) =  
\int_{-\infty}^\infty \cdots \int_{-\infty}^\infty g(x_1, \ldots, x_p) \, 
f_{_\mathbf{X}}(x_1, \ldots, x_p) \, dx_1 \ldots dx_p $   \\ 
$Var(X) = E[(X-\mu_{_X})^2]$ &
$Cov(X,Y) = E[(X-\mu_{_X})(Y-\mu_{_Y})]$    
\end{tabular}
\renewcommand{\arraystretch}{1.0}
\end{center}

\vspace{3mm}

\begin{enumerate} 

     \item Let $X$ be a continuous random variable and let $a$ be a constant. Using the expression for $E(g(X))$ above, show $E(a)=a$.

     \item Let $X_1$ and $X_2$ be continuous random variables. Using the expression for $E(g(\mathbf{X}))$ above, show $E(X_1+X_2) = E(X_1)+E(X_2)$. If you assume independence, you get a zero. 

     \item \label{prod} Let $Y_1$ and $Y_2$ be continuous random variables that are \emph{independent}. Using the expression for $E(g(\mathbf{Y}))$, show $E(Y_1 Y_2) = E(Y_1)E(Y_2)$. Draw an arrow to the place in your answer where you use independence, and write ``This is where I use independence."
     
     \item Using the definitions of variance covariance along with familiar properties of expected value (no integrals), show the following:
        \begin{enumerate} 
            \item $Var(Y) = E(Y^2)-\mu_Y^2$
            \item $Cov(X,Y)=E(XY)-E(X)E(Y)$
            \item If $X$ and $Y$ are independent, $Cov(X,Y) = 0$. Of course you may use Problem~\ref{prod}.
        \end{enumerate} 

    \item In the following, $X$ and $Y$ are random variables, while $a$ and $b$  are fixed constants. For each pair of statements below, one is true and one is false (that is, not true in general). State which one is true, and prove it. Zero marks if you prove both statements are true, even if one of the proofs is correct. Use definitions and familiar properties of expected value, not integrals.
    \begin{enumerate}
        \item $ Var(aX) = a Var(X)$ or $ Var(aX) = a^2 Var(X)$
        \item $ Var(aX+b) = a^2  Var(X) + b^2$ or $ Var(aX+b) = a^2  Var(X)$ % Important
        \item $ Var(a)=0$ or $ Var(a)=a^2$
        \item $Cov(X+a,Y+b)=Cov(X,Y)+ab$ or $Cov(X+a,Y+b)=Cov(X,Y)$ % Important
        \item $Var(aX+bY)=a^2Var(X)+b^2Var(Y)$ or $Var(aX+bY)=a^2Var(X)+b^2Var(Y)+2abCov(X,Y)$
    \end{enumerate}

\pagebreak

     \item Let $Y_1, \ldots, Y_n$ be numbers, and $\overline{Y}=\frac{1}{n}\sum_{i=1}^nY_i$. Show
         \begin{enumerate} 
            \item $\sum_{i=1}^n(Y_i-\overline{Y})=0$
            \item $\sum_{i=1}^n(Y_i-\overline{Y})^2=\sum_{i=1}^nY_i^2 \,-\, n\overline{Y}^2$
            \item The sum of squares $Q_m = \sum_{i=1}^n(Y_i-m)^2$ is minimized when $m = \overline{Y}$.
        \end{enumerate}

     \item Let $Y_1, \ldots, Y_n$ be independent random variables with $E(Y_i)=\mu$ and $Var(Y_i)=\sigma^2$ for $i=1, \ldots, n$. For this question, please use definitions and familiar properties of expected value, not integrals.
         \begin{enumerate} 
            \item Find $E(\sum_{i=1}^nY_i)$.
            \item Find $Var\left(\sum_{i=1}^n Y_i\right)$. Show your work. Draw an arrow to the place in your answer where you use independence, and write ``This is where I use independence."
            \item Using your answer to the last question, find $Var(\overline{Y})$. 
            \item A statistic $T$ is an \emph{unbiased estimator} of a parameter $\theta$ if $E(T)=\theta$. Show that $\overline{Y}$ is an unbiased estimator of $\mu$. This is very quick. 
            \item Let $a_1, \ldots, a_n$ be constants and define the linear combination $L$ by $L = \sum_{i=1}^n a_i X_i$. What condition on the $a_i$ values makes $L$ an unbiased estimator of $\mu$?
            \item Is $\overline{Y}$ a special case of $L$?  If so, what are the $a_i$ values?
            \item What is $Var(L)$? 
        \end{enumerate}

        \item Let $Y_1, \ldots, Y_n$ be a random sample from a normal distribution with mean $\mu$ and variance $\sigma^2$, so that $T = \frac{\sqrt{n}(\overline{Y}-\mu)}{S} \sim t(n-1)$. This is something you don't need to prove, for now. 
    \begin{enumerate}
        \item Derive a $(1-\alpha)100\%$ confidence interval for $\mu$. ``Derive" means show all the high school algebra. Use the symbol $t_{\alpha/2}$ for the number satisfying $Pr(T>t_{\alpha/2})= \alpha/2$.
        \item \label{ci} A random sample with $n=23$ yields $\overline{Y} = 2.57$ and a sample variance of $S^2=5.85$. Using the critical value $t_{0.025}=2.07$, give a 95\% confidence interval for $\mu$. The answer is a pair of numbers.
        \item Test $H_0: \mu=3$ at $\alpha=0.05$. 
            \begin{enumerate}
                \item Give the value of the $T$ statistic. The answer is a number.
                \item State whether you reject $H_0$, Yes or No.
                \item Can you conclude that $\mu$ is different from 3? Answer Yes or No.
                \item If the answer is Yes, state whether $\mu>3$ or $\mu<3$. Pick one.
            \end{enumerate}
        \item Show that using a $t$-test, $H_0:\mu=\mu_0$ is rejected at significance level $\alpha$ if and only the $(1-\alpha)100\%$ confidence interval for $\mu$ does not include $\mu_0$. The problem is easier if you start by writing the set of $Y_1, \ldots, Y_n$ values for which $H_0$ is \emph{not} rejected.  
        \item In Question~\ref{ci}, does this mean $Pr\{1.53<\mu<3.61\}=0.95$? Answer Yes or No and briefly explain.
    \end{enumerate}

    \item In \emph{Linear models in statistics}, do problems 2.3, 2.4 and 2.14 parts a, b, and h. Review Chapter 2 or your linear algebra text as necessary. The answers are in the back of the book. The \emph{trace} of a square matrix $\mathbf{A}$, denoted $tr(\mathbf{A})$, is the sum of the diagonal elements. 

    \item \label{firstmat} Which statement is true? (Quantities in boldface are matrices of constants.)
        \begin{enumerate}
            \item $\mathbf{A(B+C) = AB+AC}$
            \item $\mathbf{A(B+C) = BA+CA}$
            \item Both a and b
            \item Neither a nor b
        \end{enumerate}
    \item Which statement is true?
        \begin{enumerate}
            \item $a\mathbf{(B+C)}=a\mathbf{B} + a\mathbf{C}$
            \item $a\mathbf{(B+C)}=\mathbf{B}a + \mathbf{C}a$
            \item Both a and b
            \item Neither a nor b
        \end{enumerate}

    \item Which statement is true?
        \begin{enumerate}
            \item $\mathbf{(B+C)A = AB+AC}$
            \item $\mathbf{(B+C)A = BA+CA}$
            \item Both a and b
            \item Neither a nor b
        \end{enumerate}

    \item Which statement is true?
        \begin{enumerate}
            \item $\mathbf{(AB)^\prime = A^\prime B^\prime}$
            \item $\mathbf{(AB)^\prime = B^\prime A^\prime}$
            \item Both a and b
            \item Neither a nor b
        \end{enumerate}

    \item Which statement is true?
        \begin{enumerate}
            \item $\mathbf{A^{\prime\prime} = A }$
            \item $\mathbf{A^{\prime\prime\prime} = A^\prime }$
            \item Both a and b
            \item Neither a nor b
        \end{enumerate}

\pagebreak 

    \item Suppose that the square matrices $\mathbf{A}$ and $\mathbf{B}$ both have inverses. Which statement is true?
        \begin{enumerate}
            \item $\mathbf{(AB)}^{-1} = \mathbf{A}^{-1}\mathbf{B}^{-1}$
            \item $\mathbf{(AB)}^{-1} = \mathbf{B}^{-1}\mathbf{A}^{-1}$
            \item Both a and b
            \item Neither a nor b
        \end{enumerate}
    \item Which statement is true?
        \begin{enumerate}
            \item $\mathbf{(A+B)^\prime = A^\prime + B^\prime}$
            \item $\mathbf{(A+B)^\prime = B^\prime + A^\prime }$
            \item $\mathbf{(A+B)^\prime = (B+A)^\prime}$
            \item All of the above
            \item None of the above
        \end{enumerate}

    \item Which statement is true?
        \begin{enumerate}
            \item $(a+b)\mathbf{C} = a\mathbf{C}+ b\mathbf{C}$
            \item $(a+b)\mathbf{C} = \mathbf{C}a+ \mathbf{C}b$
            \item $(a+b)\mathbf{C} = \mathbf{C}(a+b)$
            \item All of the above
            \item None of the above
        \end{enumerate}

    \item Let $\mathbf{A}$ be a square matrix with the determinant of $\mathbf{A}$ (denoted $|\mathbf{A}|$) equal to zero. What does this tell you about $\mathbf{A}^{-1}$? No proof is required here.
        
    \item Recall that $\mathbf{A}$ symmetric means $\mathbf{A=A^\prime}$. Let $\mathbf{X}$ be an $n$ by $p$ matrix. Prove that $\mathbf{X^\prime X}$ is symmetric.
    \item Recall that an inverse of the matrix $\mathbf{A}$ (denoted $\mathbf{A}^{-1}$) is defined by two properties: $\mathbf{A}^{-1}\mathbf{A=I}$ and $\mathbf{AA}^{-1}=\mathbf{I}$. Prove that inverses are unique, as follows. Let $\mathbf{B}$ and $\mathbf{C}$ both be inverses of $\mathbf{A}$. Show that $\mathbf{B=C}$. 
    \item Let $\mathbf{X}$ be an $n$ by $p$ matrix with $n \neq p$. Why is it incorrect to say that $(\mathbf{X^\prime X})^{-1}= \mathbf{X}^{-1}\mathbf{X}^{\prime -1}$?

\end{enumerate}

\vspace{5mm}

\noindent
\begin{center}\begin{tabular}{l}
\hspace{6in} \\ \hline
\end{tabular}\end{center}
This assignment was prepared by  \href{http://www.utstat.toronto.edu/~brunner}{Jerry Brunner},
Department of Statistical Sciences, University of Toronto. It is licensed under a 
\href{http://creativecommons.org/licenses/by-sa/3.0/deed.en_US}
     {Creative Commons Attribution - ShareAlike 3.0 Unported License}. Use any part of it as you like and share the result freely. The \LaTeX~source code is available from the course website:
\href{http://www.utstat.toronto.edu/~brunner/oldclass/302f13} {\small\texttt{http://www.utstat.toronto.edu/$^\sim$brunner/oldclass/302f13}}

\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% t-test question
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

> set.seed(2222)
> x = rnorm(23,2,2)
> t.test(x,mu=3)

	One Sample t-test

data:  x
t = -0.8458, df = 22, p-value = 0.4068
alternative hypothesis: true mean is not equal to 3
95 percent confidence interval:
 1.527200 3.619482
sample estimates:
mean of x 
 2.573341 

> s2 = round(var(x),2); s2
[1] 5.85
> xbar=round(mean(x),2); xbar
[1] 2.57
> t = sqrt(23)*(xbar-3)/sqrt(s2); t
[1] -0.8526179
> cv = round(qt(0.975,22),2); cv
[1] 2.07
> xbar - cv *sqrt(s2/23)
[1] 1.526039
> xbar + cv *sqrt(s2/23)
[1] 3.613961

