\documentclass[color]{beamer}
\usetheme{default}
\usepackage{pgf,xcolor}
\usecolortheme{seahorse}
\setbeamersize{textmarginleft=0.5cm}
\setbeamersize{textmarginlright=0.5cm}
\setbeamercolor{verbcolor}{fg=blue,bg=lightgray}
% \usepackage{graphicx}
\usepackage{url}
\usepackage{natbib}
\usepackage{float}
\newcommand{\txtt}[1]{{\color{blue}\texttt{#1}}}
% \usepackage{beamerthemesplit}
\setbeamersize{text margin left=0.5cm}
\title{Statistical Perspectives on Data Mining -- Summary of Modules}
\author{John Maindonald}

\begin{document}
\section{Overview of R}
\subsection{General}
\frame{
\frametitle{The R System:}
\begin{itemize}
\item<1-> R is currently the environment of choice for 
\begin{itemize}
  \item<1-> specialists who are implementing new methodology
  \item<1-> highly trained professional data analysts.
\end{itemize}
\item<1-> It is designed for interactive data analysis: the next step
may depend on the previous result
\item<1-> New releases every few months bring improvements \& new features.
\item<2-> It can be remarkably efficient, even though:
\begin{itemize}
  \item<2-> data resides (mostly) in memory
  \item<2-> it is an interpreted language (but one command may start a
lengthy computation)
\end{itemize}
\end{itemize}
\vspace*{9pt}

Check out \url{http://cran.ms.unimelb.edu.au}\\
or (outside of Australia) \url{http://cran.r-project.org}
}

\subsection{Simple R}

\begin{frame}[fragile]
\frametitle{First Steps with R}
\begin{block}{Command line calculations}
Type following \verb!>!, which is the command prompt.
\begin{beamercolorbox}{verbcolor}

\begin{verbatim}
> 2+2
[1] 4
>
\end{verbatim}
\end{beamercolorbox}
The \txtt{[1]} says, perhaps a little strangely,\newline 
``first requested element will follow''
\end{block}

\begin{block}{Demonstrations}
\begin{beamercolorbox}{verbcolor}
\begin{verbatim}
demo(graphics)   # Gives graphics demonstrations
demo()           # List all available demonstrations
\end{verbatim}
\end{beamercolorbox}
\end{block}
\begin{block}{Examples}
\begin{beamercolorbox}{verbcolor}
\begin{verbatim}
example(plot)    # Examples from help page for plot()
\end{verbatim}
\end{beamercolorbox}
\end{block}
\end{frame}

%% An Overview of R
\noindent
\frame{
\frametitle{Getting Started}
\parbox{12.5cm}{
\vspace*{-6pt}
\hspace*{-0.5cm}
\begin{tabbing}
Demonstrations zz\= \txtt{example(plot)} x\= \kill
 Command \> Enter commands following the prompt, e.g.\\
 prompt (\txtt{>})  \> \txtt{> 2 + 2} \> \txtt{\# Calculate 2 + 2}\\[6pt]
 Quitting \> To quit from R type\\
 \> \txtt{q()} \> \txtt{\# NB q(), not q}\\[6pt]
 Case matters \> \txtt{volume} is different from \txtt{Volume}\\[6pt]
 Help \> Use it often. For example\\
  \> \txtt{help()} \> \txtt{\# Describe the use of help()}\\
  \> \txtt{help(plot)} \> \txtt{\# help on the plot function}\\[6pt]
% Examples \> To run examples from a help page, type, e.g.\\
%  \> \txtt{example(plot)} \> \txtt{\# Example from help(plot)}\\[6pt]
 Assignment \> The assignment symbol is \txtt{<-}, e.g.\\
  \> \txtt{volume <- c(351, 955, 662, 1203, 557)}\\
  \> \txtt{  \# Store the column of numbers in volume}\\
  \> \txtt{  \# c = concatenate}\\[6pt]
Other topics \> Simple arithmetic operations; simple plots.
\end{tabbing}
\vspace*{-6pt}
}}
\subsection{The Working Environment of an R Session}
\noindent
\frame{
\frametitle{The Working Environment}
\parbox{12.5cm}{
\begin{tabular}{ll}
  Working & R will by default read files from this directory,\\
 directory & or write files to it\\[6pt]
  Object & A data structure or function that R recognizes \\
 & Functions, as well as data, exist as ``objects''\\
& Note also, e.g., formula objects, expression objects, \ldots\\[6pt]
Workspace & This is the user's ``database''. It holds objects that the\\ 
& user can modify or delete, or to which the user can add.\\
 &  Use \txtt{ls()} to list contents of current workspace.\\[6pt]
  \txtt{read.table()} 
    & Use to read data, from a file, into the workspace\\[6pt]
  Image files & Use to store R objects, e.g., workspace
contents.\\
  & (The expected file extension is \textbf{.RData} or \textbf{.rda})\\[6pt]
\txtt{save.image()} & Use to store all or some
workspace contents.\\
  & For safety, use from time to time in a session\\
& Alternatively, use the relevant menu item.
\end{tabular}
\vspace*{-6pt}
}}

\subsection{Packages, and the Search List}
\noindent
\frame{
\frametitle{Packages, and the Search List}
\parbox{12.5cm}{
\begin{tabular}{ll}
  Packages & Packages are collections of R functions and/or data. \\[6pt]
  \txtt{library()} & Use to attach a package, e.g. 
  \txtt{library(DAAG)} \\
  & (Binary R distributions include recommended packages.\\ 
  & Install other packages, as required, prior to their use.)\\[6pt]
Search List & The search list specifies the working directory,\\
 & followed by other ``databases'' that should be searched\\
 & if the object sought is not in the working directory.\\[6pt]
Databases & Other ``databases'' that can be added to the search\\
& list include image (\textbf{.RData}) files, and data frames.
\end{tabular}
}}

\subsection{Different Types of Data Objects}
\noindent
\frame{
\frametitle{Different types of data objects:}
\parbox{12.5cm}{
\begin{tabular}{ll}
Vectors & These collect together elements that are all of one mode.\\
& (Possible modes are "logical", "integer", "numeric",\\
& "complex", "character") and "raw")\\[6pt]
Factors & These identify categories (levels) in categorical data.\\
        & They make it easy to write down model formulae that\\
        & account for categorical effects\\ 
& (Factors are very like vectors, but do not quite manage\\
& to be vectors! Why?)\\[6pt]
Data & A list of columns -- same length; may have different modes. \\
frame & Data frames are an effective way to organise data for use\\
 & with modeling functions.\\[6pt]
Lists & Lists group together an arbitrary collection of objects \\
& (These are recursive structures; elements of lists are lists.)\\[6pt]
\txtt{NA}s & The handling of \txtt{NA}s (missing values) can be tricky.
\end{tabular}
}}
\noindent
\frame{
\frametitle{Different Kinds of Functions}
\parbox{12.5cm}{
\begin{tabular}{ll}
Generic & They examine the object given as argument, before\\
 functions & deciding what action is needed. Examples include\\
& \txtt{print()}, \txtt{plot()} \& \txtt{summary()}\\[6pt]
Modeling  & Use to fit statistical models. Thus note \txtt{lm()} for
\textit{linear}\\ 
functions & modeling. Output may be stored in a model object.\\[6pt] 
Extractor & Use extractor functions to obtain specific types of\\
functions & information (summary, coefficients, residuals, etc.)\\
 & from model objects.  Examples are \txtt{summary()},\\
 & \txtt{residuals()},
etc\\[6pt]
User & Create functions that automate \& document computations\\[6pt]
Anonymous & Functions that are defined in place do not need a name
\end{tabular}
}}

\section{Graphics}
%% {Base Graphics}
\frame{
\frametitle{Base Graphics}
\parbox{15.25cm}{
\begin{tabular}{ll}
\multicolumn{2}{l}{Base graphics implements a relatively ``traditional'' style
of graphics}\\[0.15cm]
Functions & \txtt{plot()}, \txtt{points()}, \txtt{lines()}, 
  \txtt{text()}, \txtt{mtext()}, \txtt{axis()},\\ 
& \txtt{identify()} etc. form a suite (plot points, lines, text, etc.)\\[6pt]
Plot \txtt{y} vs \txtt{x} & \txtt{with(women, plot(height, weight))}\\  
& (older syntax)\\
 & Or: \txtt{plot(weight \ensuremath{\sim} height, data=women)}\\ 
 & (uses graphics formula)\\[6pt]
Caveat & Some base graphics functions do not take a \txtt{data} 
parameter\\[0.25cm]
\multicolumn{2}{l}{In addition to base graphics there is}\\
\multicolumn{2}{l}{(i) lattice (trellis) graphics, using the 
\textit{lattice} package,}\\
\multicolumn{2}{l}{and (ii) the low-level \textit{grid} package on which 
\textit{lattice} is built.}
\end{tabular}
}}

%% {Lattice Graphics}
\frame{

\parbox{12.5cm}{
\frametitle{Lattice Graphics}
\begin{tabular}{ll}
\textbf{Lattice} & Lattice is a flavour of trellis graphics\\
 & (the S-PLUS flavour was the original implementation)\\[6pt]
\textbf{Grid} & \textit{grid} is a low-level graphics system. It was used
to build \textit{lattice}.\\
 & For \textit{grid}, see Part II of Paul Murrell's \textit{R Graphics}\\[6pt]
Lattice & Lattice is more structured, automated and stylized.\\
vs base & Much is done automatically, without user intervention.\\
 & Changes to the default style are harder than for base.\\[6pt]
Lattice  & Lattice syntax is consistent and tightly regulated\\
syntax & For use of lattice, graphics formulae are mandatory.
\end{tabular}
\vspace*{9pt}

 \txtt{xyplot(csoa \ensuremath{\sim} it | sex, groups = target, data = tinting)}\\
 \hspace*{1.0cm} \txtt{csoa \ensuremath{\sim} it}: Plot \txtt{csoa} vs \txtt{it}\\
\hspace*{1.0cm} \txtt{| sex}: Condition on \txtt{sex}
(one panel for each level of \txtt{sex}\\
\hspace*{1.0cm} \txtt{groups}: In each panel, group by levels (\txtt{locon},
\txtt{hicon}) of \txtt{target}\\[6pt]
Use \txtt{auto.key} for a basic key to the group 
labeling (\txtt{groups} parameter).
}}

\section{Models in R}
\subsection{Linear models with iid errors}
%% Fitting Statistical Models
\frame{
\frametitle{Linear Models, in the style of \txtt{lm()}}
\parbox{12.5cm}{
\begin{tabular}{ll}
Linear model & Any model that \txtt{lm()} will fit
is a ``linear'' model.\\
& \txtt{lm()} can fit highly non-linear forms of response!\\[6pt]
Diagnostic  & Use \txtt{plot()} with the model object as argument,\\
plots & to get a basic set of diagnostic plots.\\[6pt]
\txtt{termplot()} & If there are no interaction terms, 
use \txtt{termplot()} to\\
& visualize the contributions of the different terms.\\
& (Why are interactions a problem for \txtt{lm()}?\\[6pt]
Factors & In model terms, use factors to model qualitative effects.\\[6pt]
Model & How should coefficients be interpreted? Examine the\\
 matrices & model matrix. (This is an especial issue for factors.)\\[6pt]
GLMs & Generalized Linear Models are an extension of linear\\
& models, commonly used for analyzing counts.
\end{tabular}
\vspace*{9pt}

[NB: \texttt{lm()} assumes independently \& identically distributed
(iid) errors,\\ 
perhaps after applying a weighting function.]\\
}}

\frame{
\frametitle{Models with Non-iid Errors}
\parbox{12.5cm}{
\begin{tabular}{ll}
Error Term & Errors do not have to be (and often are not) iid\\[6pt]
Multi-level & Multi-level models are a (relatively) simple type of non-iid\\
models & model, implemented using \txtt{lme()} (\textit{nlme}) 
or \txtt{lmer()}\\
& (\textit{lme4} package).\\
& Such models allow different errors of prediction, depending\\
& on the intended prediction. (The error term does matter!)\\[6pt]
Time & Points that are close together in time are likely to show a\\
series & (usually, positive) correlation. R's \txtt{acf()} and \txtt{arima()}\\
& functions are powerful tools for working with time series. 
\end{tabular}
}}

\frame{
\frametitle{Other Models and Methods}
\begin{tabular}{ll}
anova & Models for designed experiments etc\\
& [Brief mention in Ch 3 of ``Statistical Models document'']\\
& More flexibly (less insight?), use multi-level approach.\\[6pt]
Multivariate & Principal components, multi-dimensional scaling [Ch 8]\\[6pt]
Discriminant & Discriminant analysis [Ch 8] \& tree-based methods for\\
methods & classification [Ch 7]\\
\end{tabular}
}

\section{Additional Notes on R}
\noindent
%% {Common Uses for Key Language Ideas}
\frame{\parbox{12.5cm}{
\frametitle{Key Language Ideas}
%
\begin{tabular}{ll}
Classes & Classes make generic functions (methods) possible.\\[6pt]
Methods & Examples are \txtt{print()}, \txtt{plot()}, \txtt{summary()}, 
etc.\\[6pt]
S4 vs S3 & S3 is the original implementation of classes \& methods\\
& S4, which uses the \textit{methods} package, is more recent.\\[6pt]
Formulae & As of now, there are model, graphics and table formulae.\\
& Formulae can be manipulated, just as with other objects.\\[6pt]
Expressions & They can be evaluated (of course!). They can also\\
& be printed (on a graph)\\[6pt]
Argument & Argument lists can be constucted in advance, as a\\
lists & list of named values, with \txtt{do.call()} then used\\ 
& to pass the argument list to the function\\[6pt]
Environments & Environments hold various subtleties. There are basic\\
&  matters that it helps to know.
\end{tabular}
}}
%% {Additional Notes on R}

\frame{
\frametitle{Additional Notes}
\parbox{15.25cm}{
%
\begin{tabular}{ll}
Errors in & My attempt to input data has generated an error.\\
data input & How can I locate it?\\[6pt]
\txtt{scan()}  & \txtt{scan()} is a more flexible alternative to \txtt{read.table()}\\[6pt]
\txtt{sapply()} & \txtt{sapply()}, \txtt{lapply()} and \txtt{apply()}
apply functions\\
\& friends & in parallel across all columns of a data frame\\
& or (\txtt{(apply()}) across all rows or columns of a matrix.\\
& Apply any function that will not generate an error.\\
& [e.g., \txtt{log("Hobart")} is not allowed.]\\[6pt]
\txtt{Inf} \& friends & The logarithm of zero returns
\txtt{-Inf}. Take care!\\[6pt]
Large datasets & A little knowhow can save a load of time.\\[6pt]
Workspaces & Manage them carefully!\\
  \end{tabular}
}}

\frame{
\frametitle{THE END}
\begin{quote}
You may think that this is the end,\\
  Well it is, but to prove we're all liars,\\
We're going to sing it again,\\
Only this time we'll sing a little higher.
\end{quote}
Actually, this is not the end, for there are many other analysis methods\\
and R packages to explore, even if not in this workshop!
}
\end{document}