% This is a simple LaTex sample document that gives a submission format
%   for IEEE PAMI-TC conference submissions.  Use at your own risk.

% Make two column format for LaTex 2e.
\documentclass[10pt,twocolumn]{article} %,twocolumn
\usepackage[dvips]{graphicx,graphics}
\usepackage{times,amsmath,amsfonts}

% Use following instead for LaTex 2.09 (may need some other mods as well).
% \documentstyle[times,twocolumn]{article}

% Set dimensions of columns, gap between columns, and paragraph indent
\setlength{\textheight}{9.9in} \setlength{\textwidth}{6.9in}
%\setlength{\columnsep}{0.3125in} \setlength{\topmargin}{0in}
\setlength{\headheight}{0in} \setlength{\headsep}{-1in}
\setlength{\parindent}{1pc}
\setlength{\oddsidemargin}{-.2in}  % Centers text.
\setlength{\evensidemargin}{-.2in}

% Add the period after section numbers.  Adjust spacing.
\newcommand{\Section}[1]{\vspace{-8pt}\section{\hskip -1em.~~#1}\vspace{-3pt}}
\newcommand{\SubSection}[1]{\vspace{-3pt}\subsection{\hskip -1em.~~#1}
        \vspace{-3pt}}
\newcommand{\bqn}{\begin{eqnarray}}
\newcommand{\eqn}{\end{eqnarray}}
\newcommand{\diff}[1] {\frac{\partial}{\partial #1}}
\newcommand{\jacob}[3]{\frac{\partial^2 #3}{\partial #1 \partial #2}}
\newcommand{\der}[2]{\frac{\partial #2}{\partial #1}}
\begin{document}

% Don't want date printed
%\date{January 23, 2003}

% Make title bold and 14 pt font (Latex default is non-bold, 16pt)
\title{Stat 312: Lecture 18\\
Least squares Estimation}

% For single author (just remove % characters)
\author{Moo K. Chung\\
mchung@stat.wisc.edu}
%\date{Feb 20, 2003}
% For two authors (default example)
\maketitle \thispagestyle{empty}
\subsection*{Concepts}
\begin{enumerate}
\item {\em Least squares estimation}. Given paired data
$(x_1,y_1)$, $\cdots$, $(x_n,y_n)$, we find a line that minimizes
the {\em sum of the squared errors} (SSE):
$$SSE = \sum_{j=1}^n r_j^2 = \sum_{j=1}^n (y_j - \hat y_j)^2 =
\sum_{j=1}^n (y_j - \beta_0 - \beta_1 x_j)^2.$$ Then the {\em
regression line} is $y = \hat a\beta_0 + \hat \beta_1 x$.\\
\item By differentiating SSE with respect to $\beta_0$ and $\beta_1$,
we get {\em normal equations}:
$$\beta_0 +  \overline x \beta_1 =\overline y$$
$$ \overline x \beta_0 + \overline{x^2} \beta_1 = \overline{xy}$$
Solving these equations, we get $\hat \beta_1 =
\frac{S_{xy}}{S_{xx}}$ and $\hat \beta_0 = \overline y - \overline
x \frac{S_{xy}}{S_{xx}}$, where the sample covariance $S_{xy} =
n(\overline{xy} -\bar{x}\bar{y})$.
\item Outliers are data points with unusually large residuals.
Outliers might cause the lack of fit of a regression line.
\item $\sigma^2$ determines the amount of variability
inherent in the linear model. An unbiased estimator of $\sigma^2$
is $\hat \sigma^2 =\frac{SSE}{n-2}.$ One simple way of computing
this is to use
$$SSE = S_{yy}- \hat \beta_1 S_{xy} = S_{yy} - S_{xy}^2/S_{xx}.$$
\end{enumerate}
\subsection*{In-class problems}

{\em Example 1.} 10 students took two midterm exams.\\
Student\hspace{0.35cm}  $\|$  01  02  03  04 05 06 07 08 09 10\\
Midterm 1$\|$ 80 75 60 90 99 60 55 85 65 70\\
Midterm 2$\|$ 70 60 70 72 95 66 60 80 70 60\\
Let's find the regression line.
\begin{verbatim}
> x<-c(80, 75, 60, 90, 99, 60, 55,
85, 65, 70)
> y<-c(70, 60, 70, 72, 95, 66, 60,
80, 70, 60)
> lm(y~x)
Call: lm(formula = y ~ x)
Coefficients: (Intercept)      x
              29.4827       0.5523
\end{verbatim}
Let's see if we are getting the same result using Concept 3.

\begin{verbatim}
> cov(x,x)
[1] 209.8778
> var(x)
[1] 209.8778
> beta1 <- cov(x,y)/cov(x,x)
> beta0 <- mean(y) - mean(x)*beta1
> c(beta0,beta1)
[1] 29.482662  0.552332
\end{verbatim}
{\em Example 2.} One student who got 99 felt he did not need to
take the second exam. So he stayed at home playing PS2 and got 0
in the second midterm exam (PS2 = Sony's play station). Let's see
how his score influence the regression line.
\begin{verbatim}
> lm(y~x)
Call: lm(formula = y ~ x)
Coefficients: (Intercept)      x
                 113.27    -0.71
\end{verbatim}
\begin{figure}[t]
\centering
\renewcommand{\baselinestretch}{1}
\includegraphics[scale=0.35]{outlier.ps}
%\caption{The regression line for example 1.}
\end{figure}
{\em Example 3.} Estimate ${\bf Var}(Y_j)$ in the linear model in
Example 1.
\begin{verbatim}
> (cov(y,y)-beta1*cov(x,y))/8
[1] 6.498408
\end{verbatim}
\subsection*{Self-study problems}
Example 12.5., 12.6., 12.7., 12.8.
\subsection*{Homework 6}
Due April 10 (Thursday) 11:00am.\\ 9.40., 9.48., 9.50., 12.16..
12.18.
\end{document}
