\section*{The education data}


\begin{verbatim}
> reading <- read.table("reading.dat", head=T)
> reading
   Group Pre1 Post1 
 1 Basal    4     5
 2 Basal    6     9
 3 Basal    9     5
 4 Basal   12     8
 5 Basal   16    10
 6 Basal   15     9
 7 Basal   14    12
 8 Basal   12     5
 9 Basal   12     8
10 Basal    8     7
11 Basal   13    12
12 Basal    9     4
....
> attach(reading, pos=1)
> ls()
[1] ".Last.value" "Group"       "Post1"       "Pre1"  
> motif()
\end{verbatim}
Now we want some plots of these data.  First off a side-by-side
boxplot is handy.
\begin{verbatim}
> boxplot(split(Pre1, Group))
\end{verbatim}
\psfig{figure=reading1.eps,angle=-90,width=4in}
and
\begin{verbatim}
> par(mfrow=c(2,2))
> qqnorm(split(Pre1,Group)$Basal)
> qqnorm(Pre1[Group=="DRTA"])    
> qqnorm(Pre1[Group=="Strat"])
\end{verbatim}
\psfig{figure=reading2.eps,angle=-90,width=4in}

The bosplots seem to say that there might be some differences, and the
qq plots (on 22 points each) look quite good.

Now for some simple summaries of the data.
\begin{verbatim}
> for (x in split(Pre1, Group)) {
+ print(summary(x)); print(var(x))}
 Min. 1st Qu. Median Mean 3rd Qu. Max. 
    4    8.25   11.5 10.5      12   16
[1] 8.833333
 Min. 1st Qu. Median  Mean 3rd Qu. Max. 
    6       8      9 10.14      12   19
[1] 11.171
 Min. 1st Qu. Median  Mean 3rd Qu. Max. 
    4    6.25    8.5 9.136      12   14
[1] 11.171
\end{verbatim}
The varinaces look about the same (the last two groups are exactly the
same).

Proceed to a simple model (one-way ANOVA).
\begin{verbatim}
> reading.aov <- aov(Pre1 ~ Group)
> summary(reading.aov)
          Df Sum of Sq  Mean Sq  F Value     Pr(F) 
Group      2   21.9394 10.96970 1.055613 0.3540521
Residuals 63  654.6818 10.39177                   

> anova(reading.aov)
Analysis of Variance Table

Response: Pre1

Terms added sequentially (first to last)
          Df Sum of Sq  Mean Sq  F Value     Pr(F) 
Group      2   21.9394 10.96970 1.055613 0.3540521
Residuals 63  654.6818 10.39177             
\end{verbatim}

What about the post data?

\begin{verbatim}
> post.aov <- aov(Post1 ~ Group)
> summary(post.aov); anova(post.aov)
          Df Sum of Sq  Mean Sq  F Value       Pr(F) 
Group      2  108.1212 54.06061 5.317437 0.007346757
Residuals 63  640.5000 10.16667                     
> Analysis of Variance Table

Response: Post1

Terms added sequentially (first to last)
          Df Sum of Sq  Mean Sq  F Value       Pr(F) 
Group      2  108.1212 54.06061 5.317437 0.007346757
Residuals 63  640.5000 10.16667                     
\end{verbatim}

Some plots to help with this analysis.....

\psfig{figure=reading3.eps,angle=-90,width=4in}
\newpage

\section*{What did we just do?}
So what have we just done.

Recall what the post part of the education data looks like. (I will not
make a habit or re-writing data!).

\begin{tabular}{rrr}
Basal & DRTA & Strat \\
     5&                      7&                      11\\
     9&                      5&                       4\\
     5&                     13&                       4\\
     8&                      5&                       4\\
    10&                     14&                       3\\
     9&                     14&                       8\\
    12&                     10&                      12\\
     5&                     13&                      14\\
     8&                     12&                      12\\
     7&                     11&                       7\\
    12&                      8&                       5\\
     4&                      7&                       9\\
     4&                     10&                       1\\
     8&                      8&                      13\\
     6&                      8&                       7\\
     9&                     10&                       5\\
     3&                     12&                       7\\
     5&                     10&                      11\\
     4&                     11&                      15\\
     2&                      7&                       9\\
     5&                      8&                       6\\
     7&                     12&                       4\\
\end{tabular}


We calculated an ANOVA table as

\begin{tabular}{rrrrrr}
Source & d.f. & SS & MS & F & p \\
Group & 2 & 108 & 54.06 & 5.31 & 0.0073 \\
Residuals & 63 & 640 & 10.16 \\
\end{tabular}

``Read'' this summary to say---''There appears to be a significant
group effect''   ({\bf Of course we still need to worry about
  residuals, influence, other diagnostics}, but not at this instant).

For now, lets consider how we did the computations and what it all
means.


\subsection*{Version 1}

$Y$ is the response variable (Post score) and Group is the indicator
variable of the groups.

We can proceed by doing just a simple linear regression like
$$
Y = \alpha + \beta_1 X_1 + \beta_2 X_2 + \beta_2 X_2 + e $$
where  $ X_1, X_2, X_3 $ are the indicator variables for the groups.

Of course, because of the linearity constraints, we can only do any
two of $ X_1, X_2, X_3 $.

Now, there are at least two ways of doing this computation.


\subsubsection*{Marginally by hand}
\begin{verbatim}
> mymod <- lm(Post1 ~ Group)
> summary(mymod)

Call: lm(formula = Post1 ~ Group)
Residuals:
    Min     1Q Median    3Q   Max 
 -6.773 -2.682 0.2273 2.295 7.227

Coefficients:
               Value Std. Error  t value Pr(>|t|) 
(Intercept)   8.0758   0.3925    20.5762   0.0000
     Group1   1.5455   0.4807     3.2151   0.0021
     Group2  -0.1515   0.2775    -0.5460   0.5870

Residual standard error: 3.189 on 63 degrees of freedom
Multiple R-Squared: 0.1444 
F-statistic: 5.317 on 2 and 63 degrees of freedom, the p-value is 0.007347 

Correlation of Coefficients:
       (Intercept) Group1 
Group1 0                 
Group2 0           0     
> anova(mymod)
Analysis of Variance Table

Response: Post1

Terms added sequentially (first to last)
          Df Sum of Sq  Mean Sq  F Value       Pr(F) 
Group      2  108.1212 54.06061 5.317437 0.007346757
Residuals 63  640.5000 10.16667          
\end{verbatim}

\newpage
\subsubsection*{Even more by hand}
Create the dummy variables by hand,
\begin{verbatim}
   Group Post1 x1 x2 x3 
 1 Basal     5  1  0  0
 2 Basal     9  1  0  0
 3 Basal     5  1  0  0
 4 Basal     8  1  0  0
 ....
23  DRTA     7  0  1  0
24  DRTA     5  0  1  0
25  DRTA    13  0  1  0
 ....
45 Strat    11  0  0  1
46 Strat     4  0  0  1
47 Strat     4  0  0  1
48 Strat     4  0  0  1
 ....
\end{verbatim}
and do the analysis from there.

\begin{verbatim}
> mymod2 <- lm(Post1 ~ x1 + x2)
> summary(mymod2)

Call: lm(formula = Post1 ~ x1 + x2)
Residuals:
    Min     1Q Median    3Q   Max 
 -6.773 -2.682 0.2273 2.295 7.227

Coefficients:
               Value Std. Error  t value Pr(>|t|) 
(Intercept)   7.7727   0.6798    11.4339   0.0000
         x1  -1.0909   0.9614    -1.1347   0.2608
         x2   2.0000   0.9614     2.0804   0.0416

Residual standard error: 3.189 on 63 degrees of freedom
Multiple R-Squared: 0.1444 
F-statistic: 5.317 on 2 and 63 degrees of freedom, the p-value is 0.007347 

Correlation of Coefficients:
   (Intercept)      x1 
x1 -0.7071            
x2 -0.7071      0.5000
> anova(mymod2)
Analysis of Variance Table

Response: Post1

Terms added sequentially (first to last)
          Df Sum of Sq  Mean Sq  F Value      Pr(F) 
x1         1   64.1212 64.12121 6.307004 0.01460276
x2         1   44.0000 44.00000 4.327869 0.04156606
Residuals 63  640.5000 10.16667            
\end{verbatim}

