%\documentstyle[12pt]{statletter}    % latex 2.9
\documentclass[12pt]{article}        % latex 2e / latex 3


\usepackage{graphicx}  % For postscript graphics

\usepackage{psfrag}    % for annotating figures using latex

\usepackage{fullpage}  % sets 1 inch margins all around

\usepackage{times}     % Use postscript fonts instead of bitmapped ones

% You can also set margins yourself, e.g.:
% 
% \setlength{\textwidth}{6.3in}
% \setlength{\textheight}{8.5in}
% \setlength{\topmargin}{-0.5in}
% \setlength{\oddsidemargin}{0in}
% \setlength{\evensidemargin}{0in}



% You can defined commands for yourself.  Here are some examples:

\newcommand{\bfun}{\left\{\begin{array}{cl}} % begin function
\newcommand{\efun}{\end{array}\right.}       % end function
\newcommand{\bmat}{\left(\begin{array}}      % begin matrix
\newcommand{\emat}{\end{array}\right)}       % end matrix
\newcommand{\ul}{\underline}                 % underline
\newcommand{\cs}{, \;\;}                     % comma, space
\newcommand{\half}{\frac{1}{2}}              % 1/2
\newcommand{\mbf}[1]{\mathbf{#1}}            % math bold face
\newcommand{\bg}[1]{\mbox{\boldmath $#1$}}   % bold greek

%\input colordvi
%\def\Red#1{\Color{0 0.70 0.70 0.2}{#1}}
%\def\Green#1{\Color{0.70 0 0.5 0.2}{#1}}
%\def\Blue#1{\Color{0.70 0 0 0.2}{#1}}

\begin{document}

% For a different paragraph style:
%

\parindent=0pt

\parskip=1em

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{What we did today}
\label{sec:intro}

In this class we looked at the data set ARMath and extracted the
numerical columns corresponding to initial ratings of math teachers'
instructional quality.

In this document there are two sections.  In Section \ref{sec:intro}
we do most of the work.  In Section \ref{sec:end} we say goodbye.
In this document there are two sections.  In Section \ref{sec:intro}
we do most of the work.  In Section \ref{sec:end} we say goodbye.
In this document there are two sections.  In Section \ref{sec:intro}
we do most of the work.  In Section \ref{sec:end} we say goodbye.
In this document there are two sections.  In Section \ref{sec:intro}
we do most of the work.  In Section \ref{sec:end} we say goodbye.
In this document there are two sections.  In Section \ref{sec:intro}
we do most of the work.  In Section \ref{sec:end} we say goodbye.

We used the following commands to extract the data:
In this document there are two sections.  In Section \ref{sec:intro}
we do most of the work.  In Section \ref{sec:end} we say goodbye.
In this document there are two sections.  In Section \ref{sec:intro}
we do most of the work.  In Section \ref{sec:end} we say goodbye.
In this document there are two sections.  In Section \ref{sec:intro}
we do most of the work.  In Section \ref{sec:end} we say goodbye.


{\small
\begin{verbatim}
> source("ARMath.S")

> grep("\\.I",names(ARMath))
 [1]  1  3  6  8  9 10 11 12 13 14 15 16 18 20
> ARInit _ ARMath[,grep("\\.I",names(ARMath))]

> unlist(lapply(ARInit,mode))
     AR.I1    AR.I2C     AR.I3      AR.I3A      AR.I3B      AR.I3C      AR.I3D
 "numeric" "numeric" "numeric" "character" "character" "character" "character"

      AR.I3E     AR.I3ET     AR.I4       AR.I5     AR.I6     AR.I7     AR.I8
 "character" "character" "numeric" "character" "numeric" "numeric"
 "numeric"

> unlist(lapply(ARInit,mode))=="numeric"
 AR.I1 AR.I2C AR.I3 AR.I3A AR.I3B AR.I3C AR.I3D AR.I3E AR.I3ET AR.I4 AR.I5
     T      T     T      F      F      F      F      F       F     T     F

 AR.I6 AR.I7 AR.I8
     T     T     T

> ARInit _ ARInit[,unlist(lapply(ARInit,mode))=="numeric"]
\end{verbatim}
}

The data set has missing values, denoted by numbers in the 90's:
\begin{verbatim}
> ARInit
   AR.I1 AR.I2C AR.I3 AR.I4 AR.I6 AR.I7 AR.I8 
 1     4      4     3     3     3     4     4
 2     3      4     3     4     3     4     4
 3     2      2     3     2     3     3     3
 4     2      2     3     2     3    92    92
 5     4      3     3     3     4     4     2
 6     4      3     4     3     4     4     4
 7     1      1     3     3     2     2     2
 8     1      1     3     3     3     2     2
 9     4     92     2     3     1    92     4
10     4     91     3     3     3    92    92
\end{verbatim}

We can make a table of this data, see Table \ref{tab:data-table}:

\begin{table}

\begin{center}

\begin{tabular}{c|rrrrrrrr}
   & AR.I1 & AR.I2C&  AR.I3 & AR.I4&  AR.I6&  AR.I7&  AR.I8\\
\hline 
 1 &   4 &   4 &   3 &   3 &   3 &   4 &   4\\
 2 &   3 &   4 &   3 &   4 &   3 &   4 &   4\\
 3 &   2 &   2 &   3 &   2 &   3 &   3 &   3\\
 4 &   2 &   2 &   3 &   2 &   3 &  92 &  92\\
 5 &   4 &   3 &   3 &   3 &   4 &   4 &   2\\
 6 &   4 &   3 &   4 &   3 &   4 &   4 &   4\\
 7 &   1 &   1 &   3 &   3 &   2 &   2 &   2\\
 8 &   1 &   1 &   3 &   3 &   3 &   2 &   2\\
 9 &   4 &   92 &   2 &   3 &   1 &  92 &   4\\
10 &   4 &   91 &   3 &   3 &   3 &  92 &  92
\end{tabular}

\end{center}

\caption{Here is a table of data.}
\label{tab:data-table}

\end{table}

We converted the 90's to NA's, which Splus will ignore when making
histograms, like this:
\begin{verbatim}
> ARInit[ARInit>10] _ NA
> ARInit
   AR.I1 AR.I2C AR.I3 AR.I4 AR.I6 AR.I7 AR.I8 
 1     4      4     3     3     3     4     4
 2     3      4     3     4     3     4     4
 3     2      2     3     2     3     3     3
 4     2      2     3     2     3    NA    NA
 5     4      3     3     3     4     4     2
 6     4      3     4     3     4     4     4
 7     1      1     3     3     2     2     2
 8     1      1     3     3     3     2     2
 9     4     NA     2     3     1    NA     4
10     4     NA     3     3     3    NA    NA
\end{verbatim}

And then we graphed the resulting variables like this:
\begin{verbatim}
> par(mfrow=c(3,3))

> dim(ARInit)
[1] 10  7

> for (i in 1:7) hist(ARInit[,i])

> dev.print(postscript,command="cat > bj.eps",onefile=F)
\end{verbatim}

The graph looked like what is in Figure \ref{fig:histograms}.

\begin{figure}[ht]
\centerline{\resizebox{5.5in}{4in}{\includegraphics[origin=c,angle=-90]{bj.eps}}}
\caption{Here are a bunch of histograms.}
\label{fig:histograms}
\end{figure}

\underline{\bf Note:} Above we used the command
\begin{verbatim}
> ARInit[ARInit>10] _ NA
\end{verbatim}
A slower way to do this would be
\begin{verbatim}
N _ dim(ARInit)[1]
J _ dim(ARInit)[2]

for (i in 1:N) {
  for (j in 1:J) {
      if (ARInit[i,j]>10) {
        ARInit[i,j] <- NA
     }
  }
}
\end{verbatim}


\section{The end}
\label{sec:end}

Hope you liked it!


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% for statletter
%\def\myname{Brian W. Junker}
%\def\mytitle{Professor}
%\def\ext{8874}
%\def\net{brian@stat.cmu.edu}


% for embedding postscript files
%\begin{figure}[ht]
%  \begin{center}
%  %\psfrag{gamma}{$\gamma_0$}
%  \resizebox{6.5in}{5in}{\includegraphics[origin=c,angle=-90]{fff.ps}}
%  \end{center}
%  \caption{The caption}
%  \label{fig:xxx} 
%\end{figure}

% alternate form for embedding postscript files
%\centerline{\resizebox{6.5in}{5in}{\includegraphics[origin=c,angle=-90]{fff.ps}}}


\end{document}



