\documentstyle[11pt,bj,psfig,times]{article}

\begin{document}

\frenchspacing

\input info.tex

\def\title{Homework 2}
\def\due{SOLUTIONS}

\pagestyle{myheadings}
\markboth{\title}{\title}
\makeatletter
%\def\@oddhead{\hbox{}\bf\leftmark \hfil \rightmark}
\def\@oddhead{\bf\rightmark\hfil} %\rm\thepage}
\let\@evenhead\@oddhead
\newsavebox{\datebox}
\savebox{\datebox}{\llap{\term}{}}
\def\@oddfoot{\class\hfil\usebox{\datebox}}
\let\@evenfoot\@oddfoot
\makeatother

\begin{center}\large\bf
\title\\ 
\due \\
\end{center}

%\begin{problist}

\begin{enumerate}\setcounter{enumi}{1}

\item RPD Ex. 1.3(30)
\[
\begin{array}{rcl}
Y_i & = & \beta_0 + \beta_1 X_i + \varepsilon_i\\
\varepsilon_i & \sim & NID(0,\alpha^2)
\end{array}
\]

\[
\begin{array}{lrcl}
a. & E(Y_i) & = & E(\beta_0 + \beta_1 X_i + \varepsilon_i) = \beta_0 + \beta_1
X_i + E(\varepsilon_i) = \beta_0 + \beta_1 X_i\\
b. & \sigma^2(Y_i) & = & E\left[(\beta_0 + \beta_1 X_i + \varepsilon_i)^2\right] -
E^2(\beta_0 + \beta_1X_i + \varepsilon_i)\\
& & = & E\left[(\beta_0 + \beta_1 X_i)^2 + 2(\beta_0 + \beta_i X_i)\varepsilon_1 +
E^2_i\right] - (\beta_0 + \beta_1X_i)^2\\
& & = & (\beta_0 + \beta_1X_i)^2 + 0 + E(\varepsilon_i^2) - (\beta_0 +
\beta_iX_i)\\
& & = & \sigma^2\\
c. & Cov(Y_i,Y_{i^\prime}) & = & E\left[(\beta_0 + \beta_1 X_i + \varepsilon_i - \beta_0
- \beta_1 X_i)(\beta_0 + \beta_1 X_{i^\prime} + \varepsilon_{i^\prime} - \beta_0 -
\beta_i X_{i^\prime})\right]\\
& & = & E(\varepsilon_{i^\prime} \varepsilon_{i^\prime}) = 0 \quad , \quad i \neq {i^\prime}
\end{array}
\]


\item ~~

\[
\begin{array}{lrl}
a. &\mbox{Show:}&   \sum \hat{Y}_i e_i = 0\\

  &  \sum \hat{Y}_ie_i & =  
 \sum \hat{Y}_i(Y_i - \hat{Y}_i) = \sum (\hat{\beta}_0 + \hat{\beta}_i
X_i)(Y_i - \hat{\beta} - \hat{\beta}_i X_i)\\

 &  & =  \hat{\beta}_0 \sum Y_i + \hat{\beta}_i \sum X_i Y_i - n
\hat{\beta}^2_0 - \hat{\beta}_1 \hat{\beta}_0 \sum X_i - \hat{\beta}_1
\hat{\beta}_0 \sum X_i - \hat{\beta}^2_1 \sum X_i^2\\

 & &  =  \hat{\beta}_i \underbrace{(\sum Y_i - n \hat{\beta}_0 - \hat{\beta}_1 \sum
X_i)} + \hat{\beta}_1 \underbrace{(\sum X_i Y_i - \hat{\beta}_0 \sum X_i -
\hat{\beta}_1 \sum X_i^2)}\\

 &   & \hspace*{.5in} \mbox{Normal Equation 1} \hspace*{1in} \mbox{Normal Equation 2}\\

 & & =  \hat{\beta}_0 \cdot 0 + \hat{\beta_1} \cdot 0 = 0\\

b. & \mbox{Show:} & \sum Y_i = \sum \hat{Y}_i\\

 &  \sum Y_i & =  \sum (\bar{Y} - \beta_1 \bar{X} + \beta_1 X_i) = n
\bar{Y} - \beta_1   \sum (\bar{X} - X_i) = n \bar{Y} \quad
\mbox{QED}\\

c.  & \mbox{Show:} &  S_{YY} = SS_{\mbox{Reg}} + RSS\\
\end{array}
\]
\[
\begin{array}{rcl}
<=> & \sum(Y_i - \bar{Y})^2 = 
\sum(\hat{Y}_i - \bar{Y})^2 & + \sum(Y_i - \hat{Y}_i)^2\\
<=> & \sum Y_i^2 - 2 \bar{Y} \sum Y_i + n \bar{Y}^2 & = \sum
\hat{Y}_i^2 - 2 \bar{Y}\sum \hat{Y}_i + n \bar{Y}^2 + \sum Y_i^2\\
<=> & 0 & = 2 \left[\sum \hat{Y}_i^2 - \sum Y_i \hat{Y}_i\right]\\
<=> & 0 & = 2\left[\sum \hat{Y}_i^2 - \sum (\hat{Y}_i + e_i)
\hat{Y}_i\right]\\
<=> & 0 & = 2\left[\sum \hat{Y}_i^2 - \sum \hat{Y}_i^2 - \sum \hat{Y}_i
e_i\right]\\
<=> & 0 & = -2 \sum \hat{Y}_i e_i \quad \quad \\
<=> & 0 & =  \hspace*{.5in} 0 \hspace*{.5in} \mbox{QED}
\end{array}
\]

\clearpage

\item ~~

\[
\begin{array}{lrl}
a. & \mbox{Show:} &  \hat{\beta}_1 = r_{xy} \cdot \frac{S_Y}{S_X}\\
&  \hat{\beta}_1 & =  \frac{\sum\left(X_i - \bar{X}\right)(Y_i -
  \bar{Y})}{\sum(X_i - \bar{X})^2}  = \frac{S_Y}{S_X} \cdot
\frac{\sum\left(\frac{X_i - \bar{X}}{S_X}\right)\left(\frac{Y_i - \bar{Y}}{S_Y}\right)}
{\sum \frac{\left(X_i - \bar{X}\right)^2}{S_X^2}} = \frac{S_Y}{S_X} \cdot r_{XY}\\
b. & R^2 & =  \frac{S_{XY}^2}{S_{XX}S_{YY}} = \frac{\left[\sum (X_i -
  \bar{X})(Y_i - \bar{Y})\right]^2}{\sum (X_i - \bar{X})^2 \sum (Y_i -
  \bar{Y})^2} = \frac{\frac{1}{S^2_X S^2_Y} \cdot \left[\sum(X_i -
  \bar{X})(Y_i - \bar{Y})\right]^2}{\frac{1}{S_X^2 S^2_Y} \sum (X_i -
  \bar{X})^ \sum(Y_i - \bar{Y})^2}\\
& & = 
\frac{\left[\sum \frac{X_i - \bar{X}}{S_X} \cdot \frac{Y_i -
    \bar{Y}}{S_Y}\right]^2}
{\left[\sum\left(\frac{X_i - \bar{X}}{S_x}\right)^2 
\sum \left(\frac{Y_i - \bar{Y}}{S_Y}\right)^2\right]} = R^2_{XY}
\end{array}
\]

\noindent
* Other approach:



\[
\begin{array}{rcl}
SS_{\mbox{Reg}} & = & \sum(\hat{Y}_i - \bar{Y})^2 = 
\sum (\hat{\beta}_0
    + \hat{\beta}_i X_i - \bar{Y})^2 = \sum (\bar{Y} - \hat{\beta}_1
    \bar{X} + \hat{\beta}_1 X_i - \bar{Y})^2\\
&    = & \hat{\beta}_1^2 \sum(X_i - \bar{X})^2\\
=>R^2 & = & \frac{SS_{\mbox{Reg}}}{S_{YY}} = \frac{\hat{\beta}^2_1
    \sum(X_i - \bar{X})^2}{S_{YY}} = \frac{r^2_{XY} \cdot
    \frac{S^2_Y}{S^2_X} \cdot \sum(X_i - \bar{X})^2}{S_{YY}} =
    r^2_{XY}
\end{array}
\]



\item\label{angellreg} Regress {\tt Moral} on {\tt Ethnic}.
\begin{enumerate}
\item 
{\small
\begin{verbatim}
> myfit _ lm(Moral ~ Ethnic, data = angell)
> summary(myfit)

Call: lm(formula = Moral ~ Ethnic, data = angell)
Residuals:
    Min    1Q Median    3Q   Max 
 -6.678 -2.61 0.2493 2.297 6.693

Coefficients:
               Value Std. Error  t value Pr(>|t|) 
(Intercept)  14.4236   0.8251    17.4815   0.0000
     Ethnic  -0.1028   0.0221    -4.6450   0.0000

Residual standard error: 2.926 on 41 degrees of freedom
Multiple R-Squared: 0.3448 
F-statistic: 21.58 on 1 and 41 degrees of freedom, the p-value is 3.486e-05 

Correlation of Coefficients:
       (Intercept) 
Ethnic -0.8411    

> plot(angell$Ethnic,angell$Moral)
> abline(myfit)
\end{verbatim}
}%

\begin{center}
\mbox{\psfig{file=S/hw02p5a.ps,height=2.5in,angle=-90}}
\end{center}

From the summary of the regression and from the scatter plot we see
that {\tt Moral}  has a generally negative relationship with
{\tt Ethnic}.  This is borne out by the estimated regression
equation
\begin{eqnarray*}
        \hat y & = & \hat \beta_0 + \hat\beta_1 x \\
               &   & 14.4236  - 0.1028\cdot x
\end{eqnarray*}
The residual standard error is listed directly in the {\tt summary}
printout as well,
\[
        s = \sqrt{RSS/(n-2)} = 2.926 
\]
and the correlation between {\tt Ethnic} and {\tt Moral} is 
\[
        r_{xy} = \sqrt{R^2} = \sqrt{0.3448} = -0.5872
\]
(with the negative sign corresponding to the negative value of
$\hat\beta_1$).  

\item 
\begin{verbatim}
> plot(angell$Ethnic,residuals(myfit))
> abline(h=0) # or abline(0,0)
> qqenv(residuals(myfit))
\end{verbatim}
\begin{center}
\mbox{\psfig{file=S/hw02p5b1.ps,height=2in,angle=-90}}
\mbox{\psfig{file=S/hw02p5b2.ps,height=2in,angle=-90}}
\end{center}

The quantile normal plot (on the right) doesn't show any severe
violation of the assumption of normality for the residuals from the
regression, and the raw residual plot (on the left) doesn't show any
particular pattern of positive and negative residuals, and no unusual
features (outliers and the like).  On this basis, the regression looks
pretty good.  However, the raw residual plot does show that the {\tt
  Ethnic} variable is bunched up in lower values, with some right
skewing.
\end{enumerate}

\item ~\\
\begin{tabular}{p{2in}c}
\vspace*{-3in}
\begin{verbatim}
> attach(angell)
> par(mfrow=c(3,2))
> hist(Ethnic)
> qqenv(Ethnic)
> hist(sqrt(Ethnic))
> qqenv(sqrt(Ethnic)) 
> hist(log(Ethnic))  
> qqenv(log(Ethnic)) 
\end{verbatim}
&
\mbox{\psfig{file=S/hw02p6.ps,height=3in,angle=-90}}
\end{tabular}

{\tt Ethnic} has quite a lot of right skew, as we suspected from the
residual plot above.  {\tt sqrt{Ethnic}} still has some right skew,
though there are relatively few violations in the quantile-normal
plot.  {\tt log(Ethnic)} mostly removes the right skew (and maybe even
adds a little left skew), though we have not quite got a symmetric
distribution yet.  Still, among these three, {\tt log(Ethnic)} is
best.


\item {\small
\begin{verbatim}
> NewEthnic _ log(Ethnic)
> newfit _ lm(Moral ~ NewEthnic)
> summary(newfit)

Call: lm(formula = Moral ~ NewEthnic)
Residuals:
    Min     1Q  Median    3Q   Max 
 -6.242 -2.014 -0.2082 2.486 6.949

Coefficients:
               Value Std. Error  t value Pr(>|t|) 
(Intercept)  22.7138   2.5478     8.9150   0.0000
  NewEthnic  -3.5246   0.7678    -4.5906   0.0000

Residual standard error: 2.938 on 41 degrees of freedom
Multiple R-Squared: 0.3395 
F-statistic: 21.07 on 1 and 41 degrees of freedom, the p-value is 4.141e-05 

Correlation of Coefficients:
          (Intercept) 
NewEthnic -0.9844    
> plot(NewEthnic,Moral)
> abline(lm(Moral ~ NewEthnic))
> plot(Ethnic,Moral)
> lines(sort(Ethnic),fitted(lm(Moral ~ NewEthnic))[order(Ethnic)])
\end{verbatim}
}%
\begin{center}
\mbox{\psfig{file=S/hw02p7a.ps,height=2in,angle=-90}}
\mbox{\psfig{file=S/hw02p7b.ps,height=2in,angle=-90}}
\end{center}
I like the plot on the left (with the x-axis in the {\tt log(Ethnic)}
scale) for examining the regression, since I have some practice
``eyeballing'' a straight-line fit to data.  The plot on the right,
with the x-axis in the {\tt Ethnic} scale, is more useful for
discussion with a colleague, say, in sociology, since {\tt Ethnic} is
the variable of interest, not {\tt log(Ethnic)}.  Moreover, the plot
on the right clearly shows the steeper slope in the relationship
between {\tt Ethnic} and {\tt Moral} at low values of {\tt Ethnic},
which is totally obscured in the {\tt log(Ethnic)} plot; this increase
in slope for lower {\tt Ethnic} values might be scientifically
interesting to the sociologist.

Here are the corresponding residual plots:
\begin{center}
\mbox{\psfig{file=S/hw02p7res1.ps,height=2in,angle=-90}}
\mbox{\psfig{file=S/hw02p7res2.ps,height=2in,angle=-90}}
\end{center}
Since residual plots are mostly for assessing the goodness of the
regression, I would be inclined to stick with the plot on the
left--again, since it corresponds to a completely linear model, which
I am happier using my intuition with.

\end{enumerate}

\end{document}

  






%%%%%%%%%%%%%%%55

\item [The] {\tt Angell.dat} data set that we used last week came from a
  study by Angell (1951) on 43 US cities.  The variables collected were:
\begin{itemize}
\item {\tt Moral}: An index of ``moral'' or social integration,
  combining information on on the incidence of crime with data on
  social welfare expenditures.
\item {\tt Ethnic}: An index of ethnic heterogeneity, calculated from
  the proportions of nonwhites and foreign-born whites residing in the
  cities.
\item {\tt Geog}: An index of geographic mobility, constructed from
  the proportions of residents moving into and out of the cities.  
\item {\tt Region}: Region of the US where the city is: (E)ast,
  (S)outh, (W)est, or (M)id(W)est.
\end{itemize}
Angell argues that the moral integration of cities should decrease
with ethnic heterogeneity and geographic mobility.  In the next
several problems we briefly explore the relationship between {\tt
  Moral} and {\tt Ethnic}.

\item RPD, p. 30,  Ex. 1.3.

% \item RPD, p. 32, Ex. 1.18.  Also, show that $\sum X_i e_i = 0$, when the
%   simple linear regression equation includes the constant term $\beta_0$.

\item 
\begin{enumerate}
\item Show that $\sum \hat Y_i e_i = 0$, where $e_i = Y_i - \hat Y_i$.
\item Show that $\sum Y_i = \sum \hat Y_i$.
\item Use parts (a) and (b) to prove the ANOVA decomposition of the
total sum of squares, $S_{YY}$.  That is, demonstrate that
$S_{YY} = SS_{Reg} + RSS$. 
\end{enumerate}

\item 
\begin{enumerate}
\item Show that $\hat\beta_1 = r_{XY}\cdot\frac{S_Y}{S_X}$, where 
where $r_{XY}$ is the sample correlation between the $X$'s and the
$Y$'s, $S_Y^2$ is the sample variance of the $Y$'s and $S_X^2$ is the
sample variance of the $X$'s.  
\item Recall that $SS_{Reg}= \sum (\hat Y_i - \bar Y)^2 =
  \sum(\hat\beta_0 + \hat\beta_1 X_i - \bar Y)^2$.  From this, show
  that $SS_{Reg} = \hat\beta_1^2\sum (X_i - \bar X)^2$, and therefore
  $R^2=SS_{Reg}/SYY$ is equal to $(r_{XY})^2$.
\end{enumerate}

