#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh 'SplusDS/S.sty' <<'END_OF_FILE'
X\def\s.{{\sf S}}
X\def\splus.{{\sf S-PLUS}}
X
X\def\^{{\tt\char'136}}
X\def\~{{\tt\char'176}}
X\def\lbrac{{\tt\char'173}}
X\def\rbrac{{\tt\char'175}}
X
X\def\ctrl#1{{\tt \char'136#1}}
X\def\esc#1{{\tt Esc #1}}
X\def\strutt{\vrule height 2.5ex depth 0.5ex width 0ex}
X
X%\def\Sprompt#1\par{\leavevmode\quad{\tt> #1}\par\noindent}
X\def\Sprompt#1\par{{\hangindent=1cm\hangafter=1\tt> #1\par}\noindent}
X%\def\Shell#1\par{\leavevmode\quad{\tt\$ #1}\par\noindent}
X\def\Shell#1\par{{\tt\$ #1}\par\noindent}
X%\def\Contd #1\par{\leavevmode\quad{\tt+\hskip 0.75 truecm #1}\par\noindent}
X\def\Contd #1\par{{\tt\hskip 1cm #1}\par\noindent}
X\vfuzz 3pt
X
X\marginparwidth 0pt
X% \oddsidemargin 0pt
X\oddsidemargin 1 in
X\evensidemargin 0pt
X% \evensidemargin -0.25 in
X% \marginparsep 0pt
X
X\topmargin 0pt
X
X\textwidth 5.3 in
X% \textheight 8.53 in
X\textheight 9.25 in
X
X\def\fps@figure{hbtp}
X\def\fps@table{hbtp}
X\renewcommand{\floatpagefraction}{0.8}
X\renewcommand{\topfraction}{0.9}
X\renewcommand{\bottomfraction}{0.9}
X\renewcommand{\textfraction}{0.1}
X
X\endinput
END_OF_FILE
if test 1039 -ne `wc -c <'SplusDS/S.sty'`; then
echo shar: \"'SplusDS/S.sty'\" unpacked with wrong size!
fi
# end of 'SplusDS/S.sty'
fi
if test -f 'SplusDS/Splus.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/Splus.aux'\"
else
echo shar: Extracting \"'SplusDS/Splus.aux'\" \(697 characters\)
sed "s/^X//" >'SplusDS/Splus.aux' <<'END_OF_FILE'
X\relax
X\@input{preface.aux}
X\@input{intro.aux}
X\@input{simple.aux}
X\@input{objects.aux}
X\@input{categories.aux}
X\@input{arrays.aux}
X\@input{lists.aux}
X\@input{reading.aux}
X\@input{loops.aux}
X\@input{functions.aux}
X\@input{models.aux}
X\@input{graphics.aux}
X\@input{parfig2.aux}
X\@input{multifig.aux}
X\@writefile{lof}{\string\contentsline\space {figure}{\string\numberline\space {10}{\ignorespaces Anatomy of an S figure}}{57}}
X\newlabel{fig:figure}{{10}{57}}
X\@writefile{lof}{\string\contentsline\space {figure}{\string\numberline\space {11}{\ignorespaces Page layout in multiple figure mode}}{58}}
X\newlabel{fig:multifig}{{11}{58}}
X\@input{session.aux}
X\@input{editor.aux}
X\@input{exercises.aux}
END_OF_FILE
if test 697 -ne `wc -c <'SplusDS/Splus.aux'`; then
echo shar: \"'SplusDS/Splus.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/Splus.aux'
fi
if test -f 'SplusDS/Splus.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/Splus.tex'\"
else
echo shar: Extracting \"'SplusDS/Splus.tex'\" \(1405 characters\)
sed "s/^X//" >'SplusDS/Splus.tex' <<'END_OF_FILE'
X% -*-latex-*-
X% Document name: Splus.tex
X%
X% Version 2.0, March, 1992
X%
X% LaTeX version: Lucien W. Van Elsen [lwvanels@FIONAVAR.mit.edu]
X% and W. Venables [wvenable@stats.adelaide.edu.au]
X% Creation Date: 16 Dec., 1990.
X% Version 2.0 (S-PLUS and X-windows) March, 1992
X\documentstyle[S,parskip,titlepage,twoside,fancyheadings,bmit]{article}
X
X%\includeonly{exercises}
X\pagestyle{fancy}
X\setlength\headrulewidth{0pt}
X\renewcommand{\sectionmark}[1]{\markboth{#1}{#1}}
X\cfoot{\small\sf\thepage}
X
X\pagenumbering{roman}
X
X\title{\Huge Notes on {\bf S-PLUS}:\\[0.5cm]
XA Programming Environment for\\[0.5cm]
XData Analysis and Graphics}
X
X\author{
X{\Large Bill Venables and Dave Smith}\\[0.25cm]
X{\Large Department of Statistics}\\[0.25cm]
X{\Large The University of Adelaide}\\[0.5cm]
X{\large Email: {\tt venables@stats.adelaide.edu.au}}\\[1cm]
X\copyright\ W. Venables, 1990, 1992.}
X\date{Version 2.1, July, 1992}
X
X\begin{document}
X\include{preface}
X
X\newpage
X
X\lhead[\fancyplain{}{\small\sf\thepage}]{\fancyplain{}{\small\sf\rightmark}}
X\rhead[\fancyplain{}{\small\sf\leftmark}]{\fancyplain{}{\small\sf\thepage}}
X\cfoot{}
X
X\include{intro}
X\include{simple}
X\include{objects}
X\include{categories}
X\include{arrays}
X\include{lists}
X\include{reading}
X\include{loops}
X\include{functions}
X\include{models}
X\include{graphics}
X\appendix
X\include{session}
X\include{editor}
X\include{exercises}
X\end{document}
END_OF_FILE
if test 1405 -ne `wc -c <'SplusDS/Splus.tex'`; then
echo shar: \"'SplusDS/Splus.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/Splus.tex'
fi
if test -f 'SplusDS/Splus.toc' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/Splus.toc'\"
else
echo shar: Extracting \"'SplusDS/Splus.toc'\" \(10070 characters\)
sed "s/^X//" >'SplusDS/Splus.toc' <<'END_OF_FILE'
X\contentsline {section}{Preface}{i}
X\contentsline {section}{\numberline {1}Introduction and Preliminaries}{1}
X\contentsline {subsection}{\numberline {1.1}Reference manuals}{1}
X\contentsline {subsection}{\numberline {1.2}{\psf S-PLUS} and {\psf X--}windows}{1}
X\contentsline {subsection}{\numberline {1.3}Using {\psf S-PLUS} interactively}{2}
X\contentsline {subsection}{\numberline {1.4}An introductory session}{2}
X\contentsline {subsection}{\numberline {1.5}{\psf S-PLUS} and {\psf UNIX}}{3}
X\contentsline {subsection}{\numberline {1.6}Getting help with functions and features}{3}
X\contentsline {subsection}{\numberline {1.7}{\psf S-PLUS} commands. Case sensitivity.}{3}
X\contentsline {subsection}{\numberline {1.8}Recall and correction of previous commands}{4}
X\contentsline {subsubsection}{\numberline {1.8.1}{\psf S-PLUS}}{4}
X\contentsline {subsubsection}{\numberline {1.8.2}Vanilla {\psf S}}{4}
X\contentsline {subsection}{\numberline {1.9}Executing commands from, or diverting output to, a file}{4}
X\contentsline {subsection}{\numberline {1.10}Data directories. Permanency. Removing objects.}{5}
X\contentsline {section}{\numberline {2}Simple manipulations; numbers and vectors}{6}
X\contentsline {subsection}{\numberline {2.1}Vectors}{6}
X\contentsline {subsection}{\numberline {2.2}Vector arithmetic}{6}
X\contentsline {subsection}{\numberline {2.3}Generating regular sequences}{7}
X\contentsline {subsection}{\numberline {2.4}Logical vectors}{8}
X\contentsline {subsection}{\numberline {2.5}Missing values}{8}
X\contentsline {subsection}{\numberline {2.6}Character vectors}{8}
X\contentsline {subsection}{\numberline {2.7}Index vectors. Selecting and modifying subsets of a data set}{9}
X\contentsline {section}{\numberline {3}Objects, their modes and attributes}{11}
X\contentsline {subsection}{\numberline {3.1}Intrinsic attributes: {\psl mode\/} and {\psl length}}{11}
X\contentsline {subsection}{\numberline {3.2}Changing the length of an object}{12}
X\contentsline {subsection}{\numberline {3.3}{\ptt attributes()} and {\ptt attr()}}{12}
X\contentsline {subsection}{\numberline {3.4}The {\psl class} of an object}{12}
X\contentsline {section}{\numberline {4}Categories and factors}{13}
X\contentsline {subsection}{\numberline {4.1}A specific example}{13}
X\contentsline {subsection}{\numberline {4.2}The function {\ptt tapply()} and ragged arrays}{14}
X\contentsline {section}{\numberline {5}Arrays and matrices}{16}
X\contentsline {subsection}{\numberline {5.1}Arrays}{16}
X\contentsline {subsection}{\numberline {5.2}Array indexing. Subsections of an array}{16}
X\contentsline {subsection}{\numberline {5.3}Index arrays}{16}
X\contentsline {subsection}{\numberline {5.4}The {\ptt array()} function}{18}
X\contentsline {subsubsection}{\numberline {5.4.1}Mixed vector and array arithmetic. The recycling rule}{18}
X\contentsline {subsection}{\numberline {5.5}The outer product of two arrays}{19}
X\contentsline {subsubsection}{\numberline {5.5.1}An example: Determinants of $2\times 2$ digit matrices}{19}
X\contentsline {subsection}{\numberline {5.6}Generalized transpose of an array}{19}
X\contentsline {subsection}{\numberline {5.7}Matrix facilities. Multiplication, inversion and solving linear equations.}{20}
X\contentsline {subsection}{\numberline {5.8}Forming partitioned matrices. {\ptt cbind()} and {\ptt rbind()}.}{21}
X\contentsline {subsection}{\numberline {5.9}The concatenation function, {\ptt c()}, with arrays.}{21}
X\contentsline {subsection}{\numberline {5.10}Frequency tables from factors. The {\ptt table()} function}{21}
X\contentsline {section}{\numberline {6}Lists, data frames, and their uses}{23}
X\contentsline {subsection}{\numberline {6.1}Lists}{23}
X\contentsline {subsection}{\numberline {6.2}Constructing and modifying lists}{23}
X\contentsline {subsubsection}{\numberline {6.2.1}Concatenating lists}{24}
X\contentsline {subsection}{\numberline {6.3}Some functions returning a list result}{24}
X\contentsline {subsubsection}{\numberline {6.3.1}Eigenvalues and eigenvectors}{24}
X\contentsline {subsubsection}{\numberline {6.3.2}Singular value decomposition and determinants}{24}
X\contentsline {subsubsection}{\numberline {6.3.3}Least squares fitting and the $QR$ decomposition}{25}
X\contentsline {subsection}{\numberline {6.4}Data frames}{25}
X\contentsline {subsubsection}{\numberline {6.4.1}Making data frames}{26}
X\contentsline {subsubsection}{\numberline {6.4.2}{\ptt attach()} and {\ptt detach()}}{26}
X\contentsline {subsubsection}{\numberline {6.4.3}Working with data frames}{26}
X\contentsline {subsubsection}{\numberline {6.4.4}Attaching arbitrary lists}{27}
X\contentsline {section}{\numberline {7}Reading data from files}{28}
X\contentsline {subsection}{\numberline {7.1}The {\ptt scan()} function}{28}
X\contentsline {subsection}{\numberline {7.2}The {\ptt read.table()} function}{28}
X\contentsline {subsection}{\numberline {7.3}Other facilities; editing data}{29}
X\contentsline {section}{\numberline {8}More language features. Loops and conditional execution}{30}
X\contentsline {subsection}{\numberline {8.1}Grouped expressions}{30}
X\contentsline {subsection}{\numberline {8.2}Control statements}{30}
X\contentsline {section}{\numberline {9}Writing your own functions}{31}
X\contentsline {subsection}{\numberline {9.1}Defining new binary operators.}{31}
X\contentsline {subsection}{\numberline {9.2}Named arguments and defaults. ``\pldots ''}{32}
X\contentsline {subsection}{\numberline {9.3}Assignments within functions are local. Frames.}{32}
X\contentsline {subsection}{\numberline {9.4}More advanced examples}{33}
X\contentsline {subsection}{\numberline {9.5}Customizing the environment. {\ptt .First} and {\ptt .Last}}{35}
X\contentsline {subsection}{\numberline {9.6}Classes, generic functions and object orientation}{36}
X\contentsline {section}{\numberline {10}Statistical models in {\psf S-PLUS}}{37}
X\contentsline {subsection}{\numberline {10.1}Defining statistical models; formul\ae }{37}
X\contentsline {subsection}{\numberline {10.2}Regression models; fitted model objects}{38}
X\contentsline {subsection}{\numberline {10.3}Generic functions for extracting information}{39}
X\contentsline {subsection}{\numberline {10.4}Analysis of variance; comparing models}{39}
X\contentsline {subsubsection}{\numberline {10.4.1}ANOVA tables}{40}
X\contentsline {subsection}{\numberline {10.5}Updating fitted models. The ditto name ``{\ptt .}''}{41}
X\contentsline {subsection}{\numberline {10.6}Generalized linear models; families}{41}
X\contentsline {subsubsection}{\numberline {10.6.1}Families}{42}
X\contentsline {subsubsection}{\numberline {10.6.2}The {\ptt glm()} function}{42}
X\contentsline {subsection}{\numberline {10.7}Nonlinear regression models; parametrized data frames}{45}
X\contentsline {subsubsection}{\numberline {10.7.1}Changes to the form of the model formula}{45}
X\contentsline {subsubsection}{\numberline {10.7.2}Specifying the parameters}{46}
X\contentsline {subsection}{\numberline {10.8}Some non-standard models}{47}
X\contentsline {section}{\numberline {11}Graphical procedures}{48}
X\contentsline {subsection}{\numberline {11.1}High-level plotting commands}{48}
X\contentsline {subsubsection}{\numberline {11.1.1}The {\ptt plot()} function}{48}
X\contentsline {subsubsection}{\numberline {11.1.2}Displaying multivariate data}{49}
X\contentsline {subsubsection}{\numberline {11.1.3}Display graphics}{49}
X\contentsline {subsubsection}{\numberline {11.1.4}Arguments to high-level plotting functions}{50}
X\contentsline {subsection}{\numberline {11.2}Low-level plotting commands}{51}
X\contentsline {subsection}{\numberline {11.3}Interactive graphics functions}{52}
X\contentsline {subsection}{\numberline {11.4}Using graphics parameters}{53}
X\contentsline {subsubsection}{\numberline {11.4.1}Permanent changes: the {\ptt par()} function}{53}
X\contentsline {subsubsection}{\numberline {11.4.2}Temporary changes: arguments to graphics functions}{54}
X\contentsline {subsection}{\numberline {11.5}Graphics parameters list}{54}
X\contentsline {subsubsection}{\numberline {11.5.1}Graphical elements}{54}
X\contentsline {subsubsection}{\numberline {11.5.2}Axes and Tick marks}{55}
X\contentsline {section}{\numberline {A}{\psf S-PLUS}: An Introductory Session}{61}
X\contentsline {section}{\numberline {B}The Inbuilt Command Line Editor in {\psf S-PLUS}}{64}
X\contentsline {subsection}{\numberline {B.1}Preliminaries}{64}
X\contentsline {subsection}{\numberline {B.2}Editing Actions}{64}
X\contentsline {subsection}{\numberline {B.3}Command Line Editor Summary}{65}
X\contentsline {section}{\numberline {C}Exercises}{66}
X\contentsline {subsection}{\numberline {C.1}The Cloud Point Data}{66}
X\contentsline {subsection}{\numberline {C.2}The Janka Hardness Data}{66}
X\contentsline {subsection}{\numberline {C.3}The Tuggeranong House Price Data}{67}
X\contentsline {subsection}{\numberline {C.4}Yorke Penninsula Wheat Data}{67}
X\contentsline {subsection}{\numberline {C.5}The Iowa Wheat Yield Data}{67}
X\contentsline {subsection}{\numberline {C.6}The Gasoline Yield Data}{68}
X\contentsline {subsection}{\numberline {C.7}The Michaelson-Morley Speed of Light Data}{69}
X\contentsline {subsection}{\numberline {C.8}The Rat Genotype Data}{71}
X\contentsline {subsection}{\numberline {C.9}Fisher's Sugar Beet Data}{71}
X\contentsline {subsection}{\numberline {C.10}A Barley Split Plot Field Trial.}{72}
X\contentsline {subsection}{\numberline {C.11}The Snail Mortality Data}{73}
X\contentsline {subsection}{\numberline {C.12}The Kalythos Blindness Data}{74}
X\contentsline {subsection}{\numberline {C.13}The Stormer Viscometer Data}{76}
X\contentsline {subsection}{\numberline {C.14}The Chlorine availability data}{76}
X\contentsline {subsection}{\numberline {C.15}The Saturated Steam Pressure Data}{77}
X\contentsline {subsection}{\numberline {C.16}Count Rumford's Friction Data}{78}
X\contentsline {subsection}{\numberline {C.17}The Jellyfish Data.}{79}
X\contentsline {subsection}{\numberline {C.18}Archaelogical Pottery Data}{79}
X\contentsline {subsection}{\numberline {C.19}The Beaujolais Quality Data}{80}
X\contentsline {subsection}{\numberline {C.20}The Painter's Data of de Piles}{80}
END_OF_FILE
if test 10070 -ne `wc -c <'SplusDS/Splus.toc'`; then
echo shar: \"'SplusDS/Splus.toc'\" unpacked with wrong size!
fi
# end of 'SplusDS/Splus.toc'
fi
if test -f 'SplusDS/TAGS' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/TAGS'\"
else
echo shar: Extracting \"'SplusDS/TAGS'\" \(10284 characters\)
sed "s/^X//" >'SplusDS/TAGS' <<'END_OF_FILE'
X
XS.sty,0
X
XSplus.tex,57
X\renewcommand{\sectionmark}[1]{\markboth{#1}{#1}}16,467
X
Xarrays.tex,643
X\label{indexarrays}101,3736
X\caption{\label{matrixindex} Using an Index Array}145,5327
Xin Figure~\ref{matrixindex}118,4604
X\section{Arrays and matrices}7,74
X\subsection{Arrays}9,105
X\subsection{Forming partitioned matrices. {\tt cbind()} and {\tt279,10856
X\subsection{Frequency tables from factors. The {\tt table()} function}336,13131
X\subsection{Generalized transpose of an array}200,7263
X\subsection{Index arrays}100,3710
X\subsection{Matrix facilities. Multiplication, inversion and solving217,8051
X\subsection{The concatenation function, {\tt c()}, with arrays.}316,12378
X\subsection{The outer product of two arrays}168,6088
X
Xcategories.tex,281
X(Writing functions will be considered later in \S\ref{functions}.) After116,4463
X\section{Categories and factors}7,74
X\subsection{A specific example}16,484
X% \subsection{Factors in statistical models}150,5917
X\subsection{The function {\tt tapply()} and ragged arrays}83,3167
X
Xeditor.tex,200
X\label{cleditor}8,127
X\section{The Inbuilt Command Line Editor in \splus.}7,74
X\subsection{Command Line Editor Summary}60,2210
X\subsection{Editing Actions}39,1315
X\subsection{Preliminaries}9,144
X
Xexercises.tex,2676
X\caption{\label{ } }647,24112
X\caption{\label{kalythos}The Kalythos Blindness Data}603,23099
X\caption{\label{morley}The Michaelson-Morley Speed of Light Data}160,5821
X\caption{\label{oildata}The Oil Recovery Data}322,12248
X\caption{\label{snails} The Snail Mortality Data}556,21654
X\caption{\label{stormer}The Stormer Viscometer Calibration Data}483,18641
X\caption{\label{sugar}Fisher's Sugar Beet Data}405,16203
X\caption{\label{tugg}The Tuggeranong House Price Data}229,8342
XThe data is given in Table~\ref{ } and may be read as a data frame from649,24166
XThe data is given in Table~\ref{kalythos} and may be read as a data frame from605,23183
XThe data is given in Table~\ref{morley} and may be read as a data frame134,4518
XThe data is shown in Table~\ref{oildata}, and is available as the file290,10661
XThe data is given in Table~\ref{snails} and may be read as a data frame from558,21734
XThe data is given in Table~\ref{stormer} and may be read as a data frame from485,18736
XThe data is given in Table~\ref{sugar} and may be read from the file {\tt364,13750
XThe data is given in Table \ref{tugg}196,7061
X\section{Exercises}7,74
X\subsection{ }626,23848
X\subsection{Fisher's Sugar Beet Data}347,13047
X\subsection{The Cloud Point Data}9,95
X\subsection{The Gasoline Yield Data}262,9769
X\subsection{The Janka Hardness Data}59,1747
X\subsection{The Kalythos Blindness Data}575,22318
X\subsection{The Michaelson-Morley Speed of Light Data}117,3749
X\subsection{The Snail Mortality Data}506,19489
X\subsection{The Stormer Viscometer Data}431,17093
X\subsection{The Tuggeranong House Price Data}179,6377
X\subsubsection*{Data}26,722
X\subsubsection*{Data}75,2322
X\subsubsection*{Data}133,4469
X\subsubsection*{Data}195,7012
X\subsubsection*{Data}289,10612
X\subsubsection*{Data}363,13701
X\subsubsection*{Data}452,17984
X\subsubsection*{Data}527,20424
X\subsubsection*{Data}589,22819
X\subsubsection*{Data}635,23987
X\subsubsection*{Description}16,320
X\subsubsection*{Description}66,1975
X\subsubsection*{Description}124,3946
X\subsubsection*{Description}186,6586
X\subsubsection*{Description}271,10094
X\subsubsection*{Description}354,13259
X\subsubsection*{Description}438,17325
X\subsubsection*{Description}513,19699
X\subsubsection*{Description}582,22540
X\subsubsection*{Description}633,23957
X\subsubsection*{Problems}45,1321
X\subsubsection*{Problems}100,3137
X\subsubsection*{Problems}163,5891
X\subsubsection*{Problems}233,8402
X\subsubsection*{Problems}325,12299
X\subsubsection*{Problems}408,16255
X\subsubsection*{Problems}488,18813
X\subsubsection*{Problems}561,21809
X\subsubsection*{Problems}608,23262
X\subsubsection*{Problems}652,24228
X
Xfunctions.tex,662
X\caption{\label{effic} A function for Block Design Efficiencies}120,4711
X\label{functions}7,110
X\label{oops}210,7723
XFigure~\ref{effic}.102,4159
Xbeen discussed in \S\ref{indexarrays}.)91,3671
X\section{Writing your own functions}6,73
X\subsection{Assignments within functions are local. Frames.}53,1974
X\subsection{Classes, generic functions and object orientation}209,7660
X\subsection{Customizing the environment. {\tt .First} and {\tt .Last}}168,6373
X\subsection{Defining binary operators.}69,2753
X\subsection{Examples}87,3431
X\subsubsection{Dropping all names in a printed array}129,5138
X\subsubsection{Efficiency factors in block designs}88,3453
X
Xgraphics.tex,297
X\section{Graphical procedures}6,73
X\subsection{Graphical devices. Hardcopy output on {\sf postscript} printers}320,11723
X\subsection{Graphical parameters}43,1635
X\subsection{Some important plotting functions}157,5304
X\subsubsection{{\sf PostScript} diagrams for typeset documents.}345,12676
X
Xintro.tex,916
Xgiven in Appendix~\ref{cleditor} of these notes, or they may be found in 224,8893
Xfurther in \S\ref{dataframes}. 285,11426
Xintroductory sessing given in Appendix~\ref{intro}, starting on page~\pageref{intro}.137,5411
X\section{Introduction and Preliminaries}7,74
X\subsection{An introductory session}133,5196
X\subsection{Data directories. Permanency. Removing objects.}266,10396
X\subsection{Executing commands from, or diverting output to, a file}247,9916
X\subsection{Getting help with functions and features}161,6441
X\subsection{Recall and correction of previous commands}211,8270
X\subsection{Reference manuals}48,2122
X\subsection{Using \splus. interactively}80,3711
X\subsection{\splus. and {\sf UNIX}}140,5460
X\subsection{\splus. and {\sf X--}windows}65,2973
X\subsection{\splus. commands. Case sensitivity.}189,7389
X\subsubsection{Vanilla \s. style}227,9001
X\subsubsection{\splus. style}213,8327
X
Xlists.tex,907
X\label{atlist}294,12097
X\label{cwithlists}104,4462
X\label{dataframes}228,9451
Xdiscussed in \S\ref{models}.224,9374
Xfile. This is discussed further in \S\ref{reading}.129,5529
X\section{Lists, data frames, and their uses}6,73
X\subsection{Constructing and modifying lists, including data frames}84,3590
X\subsection{Data frames, {\tt attach()} and {\tt detach()}} 227,9390
X\subsection{Lists and data frames}8,119
X\subsection{Some functions returning a list result}131,5545
X\subsubsection{Attaching arbitrary lists}293,12055
X\subsubsection{Concatenating lists}103,4426
X\subsubsection{Data frames}61,2679
X\subsubsection{Eigenvalues and eigenvectors}136,5791
X\subsubsection{Least squares fitting and the $QR$ decomposition}189,7964
X\subsubsection{Making data frames}117,4945
X\subsubsection{Singular value decomposition and determinants}159,6583
X\subsubsection{Working with data frames}269,11082
X
Xloops.tex,150
X\section{More language features. Loops and conditional execution}7,74
X\subsection{Control statements}23,840
X\subsection{Grouped expressions}9,142
X
Xmodels.tex,1870
X\caption{\label{blind}The Kalythos Blindness Data}543,20934
X\caption{\label{generic} Commonly Used Generic Functions on Class {\tt lm}294,10419
X\caption{\label{links} Families and the Link Functions Available to them}474,18290
X\label{models}10,168
X\caption{\label{operators} Summary of Model Operator Semantics}199,6576
Xy = \frac{\theta_1z_1}{z_2 - \theta_2} + e \label{storm}640,24633
XTable~\ref{blind}. 530,20661
XTable~\ref{generic}. 248,8549
XTable~\ref{generic} apply.305,10785
Xin Table~\ref{links}.451,17349
X``Family Name'' in Table~\ref{links}. Where there is a choice of links,501,19534
Xand summarised as in the Table~\ref{operators} (based on Chambers \&175,5712
Xnonlinear regression such as \ref{storm} above, we would use676,26242
XConsider again a nonlinear regression of the form~\ref{storm}. An easy716,27909
X\section{Statistical models in \splus.}9,128
X\subsection{Analysis of variance; comparing models}300,10524
X\subsection{Defining statistical models; formul\ae}25,966
X\subsection{Generalized linear models; families}389,14539
X\subsection{Generic functions for extracting information}232,7876
X\subsection{Nonlinear regression models; parametrized data frames}657,25140
X\subsection{Regression models; fitted model objects}213,7142
X\subsection{Some non-standard models}752,29243
X\subsection{Updating fitted models. The ditto name ``{\tt .}''}351,12881
X\subsubsection*{Example}714,27833
X\subsubsection*{Poisson models}609,22984
X\subsubsection*{Quasi-likelihood models}624,23755
X\subsubsection*{The {\tt binomial} family}523,20304
X\subsubsection*{The {\tt gaussian} family}509,19823
X\subsubsection{ANOVA tables}329,11758
X\subsubsection{Changes to the form of the model formula}668,25721
X\subsubsection{Families}439,16696
X\subsubsection{Specifying the parameters}690,26773
X\subsubsection{The {\tt glm()} function}481,18584
X
Xobjects.tex,338
XGeneric functions and classes will be discussed further in \S\ref{oops}.123,5415
X\section{Objects, their modes and attributes}6,73
X\subsection{The {\em class} of an object}98,4372
X\subsection{{\tt attributes()} and {\tt attr()}}85,3813
X\subsection{{\tt dim} and {\tt dimnames}}74,3304
X\subsection{{\tt mode} and {\tt length}}8,120
X
Xpreface.tex,0
X
Xreading.tex,488
X\caption{\label{norowlab} Input file form without row labels}102,3820
X\label{reading}7,107
X\caption{\label{rowlab} Input file form with names and row labels}78,2882
X\S\ref{atlist}).43,1587
XFigure~\ref{norowlab} 91,3431
Xto be read as a data frame might look as in Figure~\ref{rowlab}.67,2483
X\section{Reading data from files}6,73
X\subsection{Other facilities; editing data}112,4162
X\subsection{The {\tt read.table()} function}54,1910
X\subsection{The {\tt scan()} function}15,421
X
Xsession.tex,71
X\label{intro}27,687
X\section{\splus.: An Introductory Session}26,644
X
Xsimple.tex,436
Xsight rather different. See \S\ref{cwithlists}.}23,899
X\section{Simple data manipulation. Constants and vectors}6,73
X\subsection{Character vectors}195,8507
X\subsection{Generating regular sequences}96,4146
X\subsection{Index vectors. Selecting and modifying subsets of a data set}222,9720
X\subsection{Logical vectors}147,6315
X\subsection{Missing values}174,7468
X\subsection{Vector arithmetic}53,1922
X\subsection{Vectors}8,133
END_OF_FILE
echo shar: 195 control characters may be missing from \"'SplusDS/TAGS'\"
if test 10284 -ne `wc -c <'SplusDS/TAGS'`; then
echo shar: \"'SplusDS/TAGS'\" unpacked with wrong size!
fi
# end of 'SplusDS/TAGS'
fi
if test -f 'SplusDS/arrays.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/arrays.aux'\"
else
echo shar: Extracting \"'SplusDS/arrays.aux'\" \(2503 characters\)
sed "s/^X//" >'SplusDS/arrays.aux' <<'END_OF_FILE'
X\relax
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {5}Arrays and matrices}{16}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.1}Arrays}{16}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.2}Array indexing. Subsections of an array}{16}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.3}Index arrays}{16}}
X\newlabel{indexarrays}{{5.3}{16}}
X\@writefile{lof}{\string\contentsline\space {figure}{\string\numberline\space {1}{\ignorespaces Using an index array}}{17}}
X\newlabel{matrixindex}{{1}{17}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.4}The {\string\ptt\space array()} function}{18}}
X\newlabel{arrayfn}{{5.4}{18}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {5.4.1}Mixed vector and array arithmetic. The recycling rule}{18}}
X\newlabel{cyclerule}{{5.4.1}{18}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.5}The outer product of two arrays}{19}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {5.5.1}An example: Determinants of $2\times 2$ digit matrices}{19}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.6}Generalized transpose of an array}{19}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.7}Matrix facilities. Multiplication, inversion and solving linear equations.}{20}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.8}Forming partitioned matrices. {\string\ptt\space cbind()} and {\string\ptt\space rbind()}.}{21}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.9}The concatenation function, {\string\ptt\space c()}, with arrays.}{21}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.10}Frequency tables from factors. The {\string\ptt\space table()} function}{21}}
X\global\@namedef{cp@arrays}{
X\setcounter{page}{23}
X\setcounter{equation}{0}
X\setcounter{enumi}{6}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{6}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{5}
X\setcounter{subsection}{10}
X\setcounter{subsubsection}{0}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{1}
X\setcounter{table}{0}
X}
END_OF_FILE
if test 2503 -ne `wc -c <'SplusDS/arrays.aux'`; then
echo shar: \"'SplusDS/arrays.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/arrays.aux'
fi
if test -f 'SplusDS/arrays.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/arrays.tex'\"
else
echo shar: Extracting \"'SplusDS/arrays.tex'\" \(17833 characters\)
sed "s/^X//" >'SplusDS/arrays.tex' <<'END_OF_FILE'
X% -*-latex-*-
X% Document name: Splus.tex
X%
X% Version 2.0, March, 1992
X%
X
X\section{Arrays and matrices}
X
X\subsection{Arrays}
X
XAn array can be considered as a multiply subscripted collection of data
Xentries, for example numeric. \splus. allows simple facilities for creating
Xand handling arrays, and in particular the special case of matrices.
X
XA dimension vector is a vector of positive integers. If its length is {\tt
Xk} then the array is {\tt k}--dimensional. The values in the dimension
Xvector give the upper limits for each of the {\tt k} subscripts. The lower
Xlimits are always 1.
X
XA vector can be used by \splus. as an array only if it has a dimension vector
Xas its {\sl dim\/} attribute. Suppose, for example, {\tt z} is a vector of
X$1500$ elements. The assignment
X
X\Sprompt dim(z) <- c(3,5,100)
X
Xgives it the {\sl dim\/} attribute that allows it to be treated as a
X$3\times5\times100$ array.
X
XOther functions such as {\tt matrix()} and {\tt array()} are available for
Xsimpler and more natural looking assignments, as we shall see in \S\ref{arrayfn}.
X
XThe values in the data vector give the values in the array in the same
Xorder as they would occur in {\sf Fortran}, that is `column major order',
Xwith the first subscript moving fastest and the last subscript slowest.
X
XFor example if the dimension vector for an array, say {\tt a} is {\tt
Xc(3,4,2)} then there are $3\times4\times2=24$ entries in {\tt a} and the
Xdata vector holds them in the order {\tt a[1,1,1], a[2,1,1], \ldots,
Xa[2,4,2], a[3,4,2]}.
X
X\subsection{Array indexing. Subsections of an array}
X
XIndividual elements of an array may be referenced, as above, by giving the
Xname of the array followed by the subscripts in square brackets, separated
Xby commas.
X
XMore generally, subsections of an array may be specified by giving a
Xsequence of {\sl index vectors\/} in place of subscripts; however {\em if
Xany index position is given an empty index vector, then the full range of
Xthat subscript is taken}.
X
XContinuing the previous example, {\tt a[2,,]} is a $4\times2$ array with
Xdimension vector {\tt c(4,2)} and data vector
X
X\begin{centering}
X
X{{\tt a[2,1,1]}, {\tt a[2,2,1]}, {\tt a[2,3,1]}, {\tt a[2,4,1]},
X {\tt a[2,1,2]}, {\tt a[2,2,2]}, {\tt a[2,3,2]}, {\tt a[2,4,2]},}
X
X\end{centering}
X
Xin that order. {\tt a[,,]} stands for the entire array, which
Xis the same as omitting the subscripts entirely and using {\tt a} alone.
X
XFor any array, say {\tt Z}, the dimension vector may be referenced
Xexplicitly as {\tt dim(Z)} (on either side of an assignment).
X
XAlso, if an array name is given with just {\sl one subscript or index
Xvector\/}, then the corresponding values of the data vector only are used;
Xin this case the dimension vector is ignored. This is not the case,
Xhowever, if the single index is not a vector but itself an array, as we
Xnext discuss.
X
X\subsection{Index arrays}
X\label{indexarrays}
XAs well as an index vector in any subscript position, an array may be used
Xwith a single {\sl index array\/} in order either to assign a vector of
Xquantities to an irregular collection of elements in the array, or to
Xextract an irregular collection as a vector.
X
XA matrix example makes the process clear. In the case of a doubly indexed
Xarray, an index matrix may be given consisting of two columns and as many
Xrows as desired. The entries in the index matrix are the row and column
Xindices for the doubly indexed array. Suppose for example we have a
X$4\times5$ array {\tt X} and we wish to do the following:
X\begin{itemize}
X\item Extract elements {\tt X[1,3]}, {\tt X[2,2]} and {\tt X[3,1]} as a
Xvector structure, and
X\item Replace these entries in the array {\tt X} by 0s.
X\end{itemize}
XIn this case we need a $3\times2$ subscript array, as in the example given
Xin Figure~\ref{matrixindex}
X\begin{figure}[ht]
X\hrule\medskip
X\begin{verbatim}
X> x <- array(1:20,dim=c(4,5)) # Generate a 4 x 5 array.
X> x
X [,1] [,2] [,3] [,4] [,5]
X[1,] 1 5 9 13 17
X[2,] 2 6 10 14 18
X[3,] 3 7 11 15 19
X[4,] 4 8 12 16 20
X> i <- array(c(1:3,3:1),dim=c(3,2))
X> i # i is a 3 x 2 index array.
X [,1] [,2]
X[1,] 1 3
X[2,] 2 2
X[3,] 3 1
X> x[i] # Extract those elements
X[1] 9 6 3
X> x[i] <- 0 # Replace those elements by zeros.
X> x
X [,1] [,2] [,3] [,4] [,5]
X[1,] 1 5 0 13 17
X[2,] 2 0 10 14 18
X[3,] 0 7 11 15 19
X[4,] 4 8 12 16 20
X>
X\end{verbatim}
X\caption{\label{matrixindex} Using an index array}
X\medskip\hrule
X\end{figure}
X
XAs a less trivial example, suppose we wish to generate an (unreduced)
Xdesign matrix for a block design defined by factors {\tt blocks} ({\tt b}
Xlevels) and {\tt varieties}, ({\tt v} levels). Further suppose there are
X{\tt n} plots in the experiment. We could proceed as follows:
X\begin{verbatim}
X> Xb <- matrix(0, n, b)
X> Xv <- matrix(0, n, v)
X> ib <- cbind(1:n, blocks)
X> iv <- cbind(1:n, varieties)
X> Xb[ib] <- 1
X> Xv[iv] <- 1
X> X <- cbind(Xb, Xv)
X\end{verbatim}
XFurther, to construct the incidence matrix, {\tt N} say, we could use
X
X\Sprompt N <- crossprod(Xb, Xv)
X
XHowever a simpler direct way of producing this matrix is to use {\tt
Xtable()}:
X
X\Sprompt N <- table(blocks, varieties)
X
X\subsection{The {\tt array()} function}
X\label{arrayfn}
XAs well as giving a vector structure a {\tt dim} attribute, arrays can be
Xconstructed from vectors by the {\tt array} function, which has the form
X
X\Sprompt Z <- array({\sl data\_vector\/},{\sl dim\_vector\/})
X
XFor example, if the vector {\tt h} contains 24, or fewer, numbers then
Xthe command
X
X\Sprompt Z <- array(h, dim=c(3,4,2))
X
Xwould use {\tt h} to set up $3\times4\times2$ array in {\tt Z}. If the
Xsize of {\tt h} is exactly 24 the result is the same as
X
X\Sprompt dim(Z) <- c(3,4,2)
X
XHowever if {\tt h} is shorter than 24, its values recycled from the
Xbeginning again to make it up to size 24. See \S\ref{cyclerule} below. As
Xan extreme but common example
X
X\Sprompt Z <- array(0, c(3,4,2)
X
Xmakes Z an array of all zeros.
X
XAt this point {\tt dim(Z)} stands for the dimension vector {\tt c(3,4,2)},
Xand {\tt Z[1:24]} stands for the data vector as it was in {\tt h}, and {\tt
XZ[]} with an empty subscript or {\tt Z} with no subscript stands for the
Xentire array as an array.
X
XArrays may be used in arithmetic expressions and the result is an array
Xformed by element by element operations on the data vector. The {\tt dim}
Xattributes of operands generally need to be the same, and this becomes the
Xdimension vector of the result. So if {\tt A}, {\tt B} and {\tt C} are all
Xsimilar arrays, then
X
X\Sprompt D <- 2*A*B + C + 1
X
Xmakes {\tt D} a similar array with data vector the result of the evident
Xelement by element operations. However the precise rule concerning mixed
Xarray and vector calculations has to be considered a little more carefully.
X
X\subsubsection{Mixed vector and array arithmetic. The recycling rule}
X\label{cyclerule}
XThe precise rule affecting element by element mixed calculations with
Xvectors and arrays is somewhat quirky and hard to find in the references.
XFrom experience I have found the following to be a reliable guide.
X
X\begin{itemize}
X\item The expression is scanned from left to right.
X
X\item Any short vector operands are extended by recycling their values
Xuntil they match the size of any previous (or subsequent) operands.
X
X\item As long as short vectors and arrays, only, are encountered, the
Xarrays must all have the same {\tt dim} attribute or an error results.
X
X\item Any vector operand longer than some previous array immediately
Xconverts the calculation to one in which all operands are coerced to
Xvectors. A diagnostic message is issued if the size of the long vector is
Xnot a multiple of the (common) size of all previous arrays.
X
X\item If array structures are present and no error or coercion to vector
Xhas been precipitated, the result is an array structure with the common
X{\tt dim} attribute of its array operands,
X\end{itemize}
X
X\subsection{The outer product of two arrays}
X
XAn important operation on arrays is the {\sl outer product}. If {\tt a}
Xand {\tt b} are two numeric arrays, their outer product is an array whose
Xdimension vector is got by concatenating their two dimension vectors,
X(order is important), and whose data vector is got by forming all possible
Xproducts of elements of the data vector of {\tt a} with those of {\tt b}.
XThe outer product is formed by the special operator {\tt\%o\%}:
X
X\Sprompt ab <- a \%o\% b
X
XAn alternative is
X
X\Sprompt ab <- outer(a, b, '*')
X
XThe multiplication function can be replaced by an arbitrary function of two
Xvariables. For example if we wished to evaluate the function
X\[
Xf(x,y)= \frac{\cos(y)}{1 + x^2}
X\]
Xover a regular grid of values with $x-$ and $y-$coordinates defined by the
X\splus. vectors {\tt x} and {\tt y} respectively, we could proceed as
Xfollows:
X\begin{verbatim}
X> f <- function(x,y) cos(y)/(1 + x^2)
X> z <- outer(x, y, f)
X\end{verbatim}
X
XIn particular the outer product of two ordinary vectors is a doubly
Xsubscripted array (i.e. a matrix, of rank at most 1). Notice that the
Xouter product operator is of course non-commutative.
X
X\subsubsection{An example: Determinants of $2\times2$ digit matrices}
XAs an artificial but cute example, consider the determinants of $2\times2$
Xmatrices $\left[\matrix{a & b\cr c & d\cr}\right]$ where each entry is a
Xnon-negative integer in the range $0,1,\ldots,9$, that is a digit.
X
XThe problem is to find the determinants, $ad - bc$, of all possible
Xmatrices of this form and represent the frequency with which each value
Xoccurs as a {\sl high density\/} plot. This amounts to finding the
Xprobability distribution of the determinant if each digit is chosen
Xindependently and uniformly at random.
X
XA neat way of doing this uses the {\tt outer()} function twice:
X\begin{verbatim}
X> d <- outer(0:9, 0:9)
X> fr <- table(outer(d, d, "-"))
X> plot(as.numeric(names(fr)), fr, type="h",
X xlab="Determinant", ylab="Frequency")
X\end{verbatim}
XNotice the coercion of the {\tt names} attribute of the frequency table to
Xnumeric in order to recover the range of the determinant values. The
X``obvious'' way of doing this problem with {\tt for}--loops, to be
Xdiscussed in \S\ref{loops}, is so inefficient as to be impractical.
X
XIt is also perhaps surprising that about 1 in 20 such matrices is singular.
X
X\subsection{Generalized transpose of an array}
X
XThe function {\tt aperm(a, perm)} may be used to permute an array, {\tt a}.
XThe argument {\tt perm} must be a permutation of the integers $\lbrac${\tt 1,
X2, \ldots, k}$\rbrac$, where {\tt k} is the number of subscripts in {\tt a}.
XThe result of the function is an array of the same size as {\tt a} but with
Xold dimension given by {\tt perm[j]} becoming the new {\tt j}th dimension.
XThe easiest way to think of this operation is as a generalization of
Xtransposition for matrices. Indeed if {\tt A} is a matrix, (i.e. a doubly
Xsubscripted array) then {\tt B} given by
X
X\Sprompt B <- aperm(A, c(2,1))
X
Xis just the transpose of {\tt A}. For this special case a
Xsimpler function {\tt t()} is available, so we could have used {\tt B
X<- t(A)}.
X
X\subsection{Matrix facilities. Multiplication, inversion and solving
Xlinear equations.}
X
XAs noted above, a matrix is just an array with two subscripts. However it
Xis such an important special case it needs a separate discussion. \splus.
Xcontains many operators and functions that are available only for matrices.
XFor example {\tt t(X)} is the matrix transpose function, as noted above.
XThe functions {\tt nrow(A)} and {\tt ncol(A)} give the number of rows and
Xcolumns in the matrix {\tt A} respectively.
X
XThe operator {\tt \%*\%} is used for matrix multiplication. An $n\times1$
Xor $1\times n$ matrix may of course be used as an $n-$vector if in the
Xcontext such is appropriate. Conversely vectors which occur in matrix
Xmultiplication expressions are automatically promoted either to row or
Xcolumn vectors, whichever is multiplicatively coherent, if possible,
X(although this is not always unambiguously possible, as we see later).
X
XIf, for example, {\tt A} and {\tt B} are square matrices of the same size,
Xthen
X
X\Sprompt A * B
X
Xis the matrix of element by element products and
X
X\Sprompt A \%*\% B
X
Xis the matrix product. If {\tt x} is a vector, then
X
X\Sprompt x \%*\% A \%*\% x
X
Xis a quadratic form.\footnote{Note that {\tt x \%*\% x} is ambiguous, as it
Xcould mean either ${\bf x'x}$ or ${\bf xx'}$, where ${\bf x}$ is the column
Xform. In such cases the smaller matrix seems implicitly to be the
Xinterpretation adopted, so the scalar ${\bf x'x}$ is in this case the
Xresult. The matrix ${\bf xx'}$ may be calculated either by {\tt cbind(x)
X\%*\% x} or {\tt x \%*\% rbind(x)} since the result of {\tt rbind()}
Xor {\tt cbind()} is always a matrix.}
X
XThe function {\tt crossprod()} forms ``crossproducts'', meaning that
X
X\Sprompt crossprod(X, y) {\rm is the same as} t(X) \%*\% y
X
Xbut the operation is more efficient. If the second argument to {\tt
Xcrossprod()} is omitted it is taken to be the same as the first.
X
XOther important matrix functions include {\tt solve(A, b)} for solving
Xequations, {\tt solve(A)} for the matrix inverse, {\tt svd()} for the
Xsingular value decomposition, {\tt qr()} for QR~decomposition and {\tt
Xeigen()} for eigenvalues and eigenvectors of symmetric matrices.
X
XThe meaning of {\tt diag()} depends on its argument. {\tt
Xdiag(vector)} gives a diagonal matrix with elements of the vector as the
Xdiagonal entries. On the other hand {\tt diag(matrix)} gives the vector of
Xmain diagonal entries of {\tt matrix}. This is the same convention as that
Xused for {\tt diag()} in {\tt MATLAB}. Also, somewhat confusingly, if
X{\tt k} is a single numeric value then {\tt diag(k)} is the $k\times k$
Xidentity matrix!
X
XA surprising omission from the suite of matrix facilities is a function for
Xthe determinant of a square matrix, however the absolute value of the
Xdeterminant is easy to calculate for example as the product of the singular
Xvalues. (See later.)
X
X\subsection{Forming partitioned matrices. {\tt cbind()} and {\tt
Xrbind()}.}
X
XMatrices can be built up from given vectors and matrices by the functions
X{\tt cbind()} and {\tt rbind()}. Roughly {\tt cbind()}
Xforms matrices by binding together matrices horizontally, or column-wise,
Xand {\tt rbind()} vertically, or row-wise.
X
XIn the assignment
X
X\Sprompt X <- cbind(arg$_1$, arg$_2$, arg$_3$, \ldots)
X
Xthe arguments to {\tt cbind()} must be either vectors of any length,
Xor matrices with the same column size, that is the same number of rows.
XThe result is a matrix with the concatenated arguments {\tt arg$_1$}, {\tt
Xarg$_2$}, \ldots forming the columns.
X
XIf some of the arguments to {\tt cbind()} are vectors they may be
Xshorter than the column size of any matrices present, in which case they
Xare cyclically extended to match the matrix column size (or the length of
Xthe longest vector if no matrices are given).
X
XThe function {\tt rbind()} does the corresponding operation for rows.
XIn this case any vector argument, possibly cyclically extended, are of
Xcourse taken as row vectors.
X
XSuppose {\tt X1} and {\tt X2} have the same number of rows. To combine
Xthese by columns into a matrix {\tt X}, together with an initial column of
X{\tt1}s we can use
X
X\Sprompt X <- cbind(1, X1, X2)
X
XThe result of {\tt rbind()} or {\tt cbind()} always has matrix
Xstatus. Hence {\tt cbind(x)} and {\tt rbind(x)} are possibly the simplest
Xways explicitly to allow the vector {\tt x} to be treated as a column or row
Xmatrix respectively.
X
X\subsection{The concatenation function, {\tt c()}, with arrays.}
X
XIt should be noted that whereas {\tt cbind()} and {\tt rbind()} are
Xconcatenation functions that respect {\tt dim} attributes, the basic {\tt
Xc()} function does not, but rather clears numeric objects of all {\tt dim} and
X{\tt dimnames} attributes. This is occasionally useful in its own right.
X
XThe official way to coerce an array back to a simple vector object is to
Xuse the function {\tt as.vector()}
X
X\Sprompt vec <- as.vector(X)
X
XHowever a similar result can be achieved by using {\tt c()} with just one
Xargument, simply for this side-effect:
X
X\Sprompt vec <- c(X)
X
XThere are slight differences between the two, but ultimately the choice
Xbetween them is largely a matter of style (with the former being preferable).
X
X\subsection{Frequency tables from factors. The {\tt table()} function}
X
XRecall that a factor defines a partition into groups. Similarly a pair of
Xfactors defines a two way cross classification, and so on. The function
X{\tt table()} allows frequency tables to be calculated from equal length
Xfactors. If there are $k$ category arguments, the result is a $k-$way
Xarray of frequencies.
X
XSuppose, for example, that {\tt statef} is a factor giving the state code
Xfor each entry in a data vector. The assignment
X
X\Sprompt statefr <- table(statef)
X
Xgives in {\tt statefr} a table of frequencies of each state in the sample.
XThe frequencies are ordered and labelled by the levels attribute of the
Xcategory. This simple case is equivalent to, but more convenient than,
X
X\Sprompt statefr <- tapply(statef, statef, length)
X
X
XFurther suppose that {\tt incomef} is a category giving a suitably defined
X``income class'' for each entry in the data vector, for example with the
X{\tt cut()} function:
X
X\Sprompt factor(cut(incomes,breaks=35+10*(0:7))) -> incomef
X
XThen to calculate a two-way table of frequencies:
X\begin{verbatim}
X> table(incomef,statef)
X act nsw nt qld sa tas vic wa
X 35+ thru 45 1 1 0 1 0 0 1 0
X 45+ thru 55 1 1 1 1 2 0 1 3
X 55+ thru 65 0 3 1 3 2 2 2 1
X 65+ thru 75 0 1 0 0 0 0 1 0
X\end{verbatim}
X
XExtension to higher way frequency tables is immediate.
X
END_OF_FILE
if test 17833 -ne `wc -c <'SplusDS/arrays.tex'`; then
echo shar: \"'SplusDS/arrays.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/arrays.tex'
fi
if test -f 'SplusDS/auto.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/auto.tex'\"
else
echo shar: Extracting \"'SplusDS/auto.tex'\" \(2473 characters\)
sed "s/^X//" >'SplusDS/auto.tex' <<'END_OF_FILE'
X\subsubsection*{Autoregressive correlation matrices}
XBy an autoregressive correlation matrix we mean a matrix of the form
X\[
X{\bf P} = \left[\matrix{
X1 & x & x^2 & x^3 & \cdots & x^{m-1}\cr
Xx & 1 & x & x^2 & \cdots & x^{m-2}\cr
Xx^2 & x & 1 & x & \cdots & x^{m-3}\cr
Xx^3 & x^2 & x & 1 & \cdots & x^{m-4}\cr
X\vdots & \vdots & \vdots & \vdots & \ddots& \vdots \cr
Xx^{m-1} & x^{m-2} & x^{m-3} & x^{m-4} & \dots & 1 \cr}
X\right]
X\]
XThus ${\bf P} = (p_{ij})$ where $p_{ij} = x^{|i-j|}$.
X
XWe now consider two functions to calculate such highly patterned matrices
Xgiven the size, $n$ and $x$. Both are quite slow, and if these matrices
Xwere needed in large numbers for some application, you may consider doing the
Xjob more efficiently, say by using an external routine written in {\sf C}
Xor {\sf Fortran} and linking it in with the {\tt dyn.load()} facility, or
Xeven generating the inverse matrix, which has a much simpler form, and
Xinverting it.
X
XThe first function shown in Figure~\ref{ar1} uses a single {\tt for}--loop
Xrather than the more obvious double loop and index matrices to access the
Xoff-diagonal elements.
X\begin{figure}[ht]
X\begin{verbatim}
X> armat1 <- function(n, x)
X {
X M <- diag(n)
X d <- x
X for(i in 2:n) {
X M[cbind(1:(n - i + 1), i:n)] <- d
X d <- d * x
X }
X (M + t(M) - diag(n))
X }
X\end{verbatim}
X\caption{\label{ar1} Autoregressive correlation matrix with a {\tt
Xfor}--loop}
X\medskip\hrule
X\end{figure}
X
XThe second method shown in Figure~\ref{ar2} uses recursive functions, and a
Xfunction defined within a function. This is even slower than the previous
Xmethod in this case, but the technique is sometimes needed to take
Xadvantage of complicated symmetries that are only easy to describe
Xrecursively.
X
XNotice that the function defined in the first level frame is not inherited
Xat higher recursive levels, but has to be passed on as a parameter.
X\begin{figure}[ht]
X\begin{verbatim}
X> armat2 <- function(n, x)
X {
X ar1 <- function(n, x, f)
X {
X if(n == 1) {
X return(matrix(1, 1, 1))
X }
X else {
X M <- f(n - 1, x, f)
X return(rbind(cbind(M, x * M[, n - 1]), c(x * M[n - 1,
X ], 1)))
X }
X }
X ar1(n, x, ar1)
X }
X\end{verbatim}
X\caption{\label{ar2} Autoregressive correlation matrices by recursive
Xfunctions}
X\medskip\hrule
X\end{figure}
X
END_OF_FILE
if test 2473 -ne `wc -c <'SplusDS/auto.tex'`; then
echo shar: \"'SplusDS/auto.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/auto.tex'
fi
if test -f 'SplusDS/bmit.sty' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/bmit.sty'\"
else
echo shar: Extracting \"'SplusDS/bmit.sty'\" \(1484 characters\)
sed "s/^X//" >'SplusDS/bmit.sty' <<'END_OF_FILE'
X
X\font\bmitl=cmmib10 at 12 true pt
X\font\bmits=cmmib10 at 10 true pt
X\newfam\bmfam
X\newcommand\bmit{\fam\bmfam\bmitl}
X\textfont\bmfam=\bmitl
X\scriptfont\bmfam=\bmits
X\scriptscriptfont\bmfam=\bmits
X\mathchardef\alpha="710B \mathchardef\beta="710C
X\mathchardef\gamma="710D \mathchardef\delta="710E
X\mathchardef\epsilon="710F \mathchardef\zeta="7110
X\mathchardef\eta="7111 \mathchardef\theta="7112
X\mathchardef\iota="7113 \mathchardef\kappa="7114
X\mathchardef\lambda="7115 \mathchardef\mu="7116
X\mathchardef\nu="7117 \mathchardef\xi="7118
X\mathchardef\pi="7119 \mathchardef\rho="711A
X\mathchardef\sigma="711B \mathchardef\tau="711C
X\mathchardef\upsilon="711D \mathchardef\phi="711E
X\mathchardef\chi="711F \mathchardef\psi="7120
X\mathchardef\omega="7121 \mathchardef\varepsilon="7122
X\mathchardef\vartheta="7123 \mathchardef\varpi="7124
X\mathchardef\varrho="7125 \mathchardef\varsigma="7126
X\mathchardef\varphi="7127 \mathchardef\Gamma="7000
X\mathchardef\Delta="7001 \mathchardef\Theta="7002
X\mathchardef\Lambda="7003 \mathchardef\Xi="7004
X\mathchardef\Pi="7005 \mathchardef\Sigma="7006
X\mathchardef\Upsilon="7007 \mathchardef\Phi="7008
X\mathchardef\Psi="7009 \mathchardef\Omega="700A
END_OF_FILE
if test 1484 -ne `wc -c <'SplusDS/bmit.sty'`; then
echo shar: \"'SplusDS/bmit.sty'\" unpacked with wrong size!
fi
# end of 'SplusDS/bmit.sty'
fi
if test -f 'SplusDS/categories.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/categories.aux'\"
else
echo shar: Extracting \"'SplusDS/categories.aux'\" \(812 characters\)
sed "s/^X//" >'SplusDS/categories.aux' <<'END_OF_FILE'
X\relax
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {4}Categories and factors}{13}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {4.1}A specific example}{13}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {4.2}The function {\string\ptt\space tapply()} and ragged arrays}{14}}
X\global\@namedef{cp@categories}{
X\setcounter{page}{16}
X\setcounter{equation}{0}
X\setcounter{enumi}{6}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{5}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{4}
X\setcounter{subsection}{2}
X\setcounter{subsubsection}{0}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{0}
X\setcounter{table}{0}
X}
END_OF_FILE
if test 812 -ne `wc -c <'SplusDS/categories.aux'`; then
echo shar: \"'SplusDS/categories.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/categories.aux'
fi
if test -f 'SplusDS/categories.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/categories.tex'\"
else
echo shar: Extracting \"'SplusDS/categories.tex'\" \(6547 characters\)
sed "s/^X//" >'SplusDS/categories.tex' <<'END_OF_FILE'
X% -*-latex-*-
X% Document name: Splus.tex
X%
X% Version 2.0, March, 1992
X%
X
X\section{Categories and factors}
X
XA {\sl category\/} is a vector object used to specify a discrete
Xclassification of the components of other vectors of the same length. A
X{\sl factor\/} is similar, but has the {\sl class\/} {\tt factor}, which
Xmeans that it is adapted to the generic function mechanism. Whereas a
Xcategory can also be used as a plain numeric vector, for example, a factor
Xgenerally cannot.
X
X\subsection{A specific example}
XSuppose, for example, we have a sample of 30 tax accountants from the all
Xstates and territories\footnote{Foreign readers should note that there are
Xeight states and territories in Australia, namely the Australian Capital
XTerritory, New South Wales, the Northern Territory, Queensland, South
XAustralia, Tasmania, Victoria and Western Australia.} and their individual
Xstate of origin is specified by a character vector of state mnemonics as
X
X\begin{verbatim}
X> state <- c("tas", "sa", "qld", "nsw", "nsw", "nt", "wa", "wa",
X "qld", "vic", "nsw", "vic", "qld", "qld", "sa", "tas",
X "sa", "nt", "wa", "vic", "qld", "nsw", "nsw", "wa",
X "sa", "act", "nsw", "vic", "vic", "act")
X\end{verbatim}
X
XFor some purposes it is convenient to represent such information by a
Xnumeric vector with the distinct values in the original (in this case the
Xstate labels) represented by a small integer. Such a numeric vector is
Xcalled a {\sl category}. However at the same time it is important to
Xpreserve the correspondence of these new integer labels with the originals.
XThis is done via the {\sl levels\/} attribute of the category.
X
XMore formally, when a category is formed from such a vector the {\sl sorted
Xunique values} in the vector form the {\sl levels\/} attribute of the
Xcategory, and the values in the category are in the set {\tt 1, 2, \ldots,
Xk} where {\tt k} is the number of unique values. The value at position
X{\tt j} in the factor is {\tt i} if the {\tt i}th sorted unique value
Xoccurred at position {\tt j} of the original vector.
X
XHence the assignment
X
X\Sprompt stcode <- category(state)
X
Xcreates a category with values and attributes as follows
X
X\begin{verbatim}
X> stcode
X [1] 6 5 4 2 2 3 8 8 4 7 2 7 4 4 5 6 5 3 8 7 4 2 2 8 5 1 2 7 7 1
X attr(, "levels"):
X [1] "act" "nsw" "nt" "qld" "sa" "tas" "vic" "wa"
X\end{verbatim}
X
XNotice that in the case of a character vector, ``sorted'' means sorted in
Xalphabetical order.
X
XA {\sl factor} is similarly created using the {\tt factor()}
Xfunction:
X
X\Sprompt statef <- factor(state)
X
XThe {\tt print()} function now handles the factor object slightly
Xdifferently:
X\begin{verbatim}
X> statef
X [1] tas sa qld nsw nsw nt wa wa qld vic nsw vic qld qld sa
X[16] tas sa nt wa vic qld nsw nsw wa sa act nsw vic vic act
X\end{verbatim}
X
XIf we remove the factor class, however, using the function {\tt
Xunclass()}, it becomes virtually identical to the category:
X\begin{verbatim}
X> unclass(statef)
X [1] 6 5 4 2 2 3 8 8 4 7 2 7 4 4 5 6 5 3 8 7 4 2 2 8 5 1 2 7 7 1
Xattr(, "levels"):
X[1] "act" "nsw" "nt" "qld" "sa" "tas" "vic" "wa"
X\end{verbatim}
X
X\subsection{The function {\tt tapply()} and ragged arrays}
X
XTo continue the previous example, suppose we have the incomes of the same
Xtax accountants in another vector (in suitably large units of money)
X
X\begin{verbatim}
X> incomes <- c(60, 49, 40, 61, 64, 60, 59, 54, 62, 69, 70, 42, 56,
X 61, 61, 61, 58, 51, 48, 65, 49, 49, 41, 48, 52, 46,
X 59, 46, 58, 43)
X\end{verbatim}
X
XTo calculate the sample mean income for each state we can now use the special
Xfunction {\tt tapply()}:
X
X\Sprompt incmeans <- tapply(incomes, statef, mean)
X
Xgiving a means vector with the components labelled by the levels
X\begin{verbatim}
X> incmeans
X act nsw nt qld sa tas vic wa
X 44.5 57.333 55.5 53.6 55 60.5 56 52.25
X\end{verbatim}
XThe function {\tt tapply()} is used to apply a function, here {\tt mean()}
Xto each group of components of the first argument, here {\tt incomes},
Xdefined by the levels of the second component, here {\tt statref} as if
Xthey were separate vector structures. The result is a structure of the
Xsame length as the levels attribute of the factor containing the results.
XThe reader should consult the help document for more details.
X
XSuppose further we needed to calculate the standard errors of the state
Xincome means. To do this we need to write an \splus. function to calculate the
Xstandard error for any given vector. We discuss functions more fully later
Xin these notes, but since there is an in built function {\tt var()}
Xto calculate the sample variance, such a function is a very simple one
Xliner, specified by the assignment:
X
X\Sprompt stderr <- function(x) sqrt(var(x)/length(x))
X
X(Writing functions will be considered later in \S\ref{functions}.) After
Xthis assignment, the standard errors are calculated by
X
X\Sprompt incster <- tapply(incomes, statef, stderr)
X
Xand the values calculated are then
X
X\begin{verbatim}
X> incster
X act nsw nt qld sa tas vic wa
X 1.5 4.3102 4.5 4.1061 2.7386 0.5 5.244 2.6575
X\end{verbatim}
X
XAs an exercise you may care to find the usual 95\% confidence limits for
Xthe state mean incomes. To do this you could use {\tt tapply()} once
Xmore with the {\tt length()} function to find the sample sizes, and
Xthe {\tt qt()} function to find the percentage points of the
Xappropriate $t-$distributions.
X
XThe function {\tt tapply()} can be used to handle more complicated
Xindexing of a vector by multiple categories. For example, we might wish to
Xsplit the tax accountants by both state and sex. However in this simple
Xinstance what happens can be thought of as follows. The values in the
Xvector are collected into groups corresponding to the distinct entries in
Xthe category. The function is then applied to each of these groups
Xindividually. The value is a vector of function results, labelled by the
Xlevels attribute of the category.
X
XThe combination of a vector and a labelling factor or category is an example
Xof what is called a {\sl ragged array}, since the subclass sizes are
Xpossibly irregular. When the subclass sizes are all the same the indexing
Xmay be done implicitly and much more efficiently, as we see in the next
Xsection.
X%
X% \subsection{Factors in statistical models}
X%
X% The main use for factors in statistical models is to define classifications
X% such as those used in factorial experiments and the analysis of variance.
X
END_OF_FILE
if test 6547 -ne `wc -c <'SplusDS/categories.tex'`; then
echo shar: \"'SplusDS/categories.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/categories.tex'
fi
if test -f 'SplusDS/editor.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/editor.aux'\"
else
echo shar: Extracting \"'SplusDS/editor.aux'\" \(949 characters\)
sed "s/^X//" >'SplusDS/editor.aux' <<'END_OF_FILE'
X\relax
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {B}The Inbuilt Command Line Editor in {\string\psf\space S-PLUS}}{64}}
X\newlabel{cleditor}{{B}{64}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {B.1}Preliminaries}{64}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {B.2}Editing Actions}{64}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {B.3}Command Line Editor Summary}{65}}
X\global\@namedef{cp@editor}{
X\setcounter{page}{66}
X\setcounter{equation}{1}
X\setcounter{enumi}{6}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{8}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{2}
X\setcounter{subsection}{3}
X\setcounter{subsubsection}{0}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{11}
X\setcounter{table}{4}
X}
END_OF_FILE
if test 949 -ne `wc -c <'SplusDS/editor.aux'`; then
echo shar: \"'SplusDS/editor.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/editor.aux'
fi
if test -f 'SplusDS/editor.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/editor.tex'\"
else
echo shar: Extracting \"'SplusDS/editor.tex'\" \(4325 characters\)
sed "s/^X//" >'SplusDS/editor.tex' <<'END_OF_FILE'
X% -*-latex-*-
X% Document name: Splus.tex
X%
X% Version 2.0, March, 1992
X%
X
X\section{The Inbuilt Command Line Editor in \splus.}
X\label{cleditor}
X\subsection{Preliminaries}
XThe August 1991 release of \splus. has inbuilt command line editor that allows
Xrecall, editing and re-submission of prior commands.
X
XTo use it, start the \splus. programme with
X
X\Shell Splus -e
X
XInside the editor either {\sf emacs\/} or {\sf vi\/} conventions are
Xavailable, according to the shell environment variable {\tt S\_CLEDITOR}.
XTo get the {\sf emacs\/} conventions use (in {\tt csh} and variants)
X
X\Shell setenv S\_CLEDITOR emacs
X
Xand for the {\sf vi\/} conventions to apply, put {\sf vi} instead of {\sf
Xemacs}. This statement would normally be included in your {\tt .login\/}
Xfile (or equivalent) and would then be done automatically at login time.
XTo avoid forgetting to include the {\tt -e} a handy alias for your {\tt
X.cshrc\/} file is, say
X\begin{verbatim}
Xalias S+ 'Splus -e'
X\end{verbatim}
Xafter which {\tt S+} is the command to start {\sf Splus} with command line
Xeditor.
X
XThe usual typographical conventions apply: \ctrl M means {\sl Hold the {\tt
XControl} down while you press the {\tt m} key}, but \esc m means {\sl First
Xpress the {\tt Esc} key and then the {\tt m} key}. Note that after \esc{}
Xcase is significant.
X
X\subsection{Editing Actions}
XThe \splus. programme keeps a history of the commands you type,
Xincluding the error lines, and commands in your history may be recalled,
Xchanged if necessary, and re-submitted as new commands. In {\it emacs}
Xstyle command line editing any straight typing you do while in this
Xediting phase causes the characters to be inserted in the command you
Xare editing, displacing any characters to the right of the cursor. In {\it
Xvi} mode character insertion mode is started by \esc i or \esc a,
Xcharacters are typed and insertion mode is finished by typing a further
X\esc{}.
X
XPressing the {\tt Return} command at any time causes the command to be
Xre-submitted.
X
XOther editing actions are summarised in the following table.
X
XUnfortunately it does not seem to be possible to bind the motion keys, for
Xexample, to the arrow keys, which is something of a nuisance.
X
X
X\newpage
X\subsection{Command Line Editor Summary}
X\renewcommand{\baselinestretch}{1.5}\tiny\normalsize
X
X\begin{tabbing}
XGo to the previous command (backwards in the history). \quad \= \esc a
Xtext \esc{} \= \esc a text \esc{}\kill
X{\large\bf 1. Command recall and vertical motion} \> {\sf emacs} style
X\> {\sf vi} style \\
X
XGo to the previous command (backwards in the history) \> \ctrl P \> \esc k \\
X
XGo to the next command (forwards in the history) \> \ctrl N \> \esc j \\
X
XFind the last command with the {\tt text} string in it \> \ctrl {R text} \>
X\esc{? text}\\
X\\
X{\large\bf 2. Horizontal motion of the cursor}\\
X
XGo to the beginning of the command \> \ctrl A \> \esc{\ctrl{}}\\
X
XGo to the end of the line \> \ctrl E \> \esc \$\\
X
XGo back one word \> \esc b \> \esc b\\
X
XGo forward one word \> \esc f \> \esc w\\
X
XGo back one character \> \ctrl B \> \esc h\\
X
XGo forward one character \> \ctrl F \> \esc l\\
X\\
X{\large\bf 3. Editing and re-submission}\\
X
XInsert {\tt text} at the cursor \> text \> \esc i text \esc{}\\
X
XAppend {\tt text} after cursor \> \ctrl Ftext \> \esc a text \esc{}\\
X
XDelete the previous character (left of the cursor) \> {\tt Delete} \> \esc{shift-x}\\
X
XDelete the character under the cursor \> \ctrl D \> \esc x\\
X
XDelete rest of the word under the cursor, and `save' it \> \esc d \> \esc{dw}\\
X
XDelete from cursor to end of command, and `save' it \> \ctrl K \> \esc{shift-d}\\
X
XInsert (yank) the last `saved' text here \> \ctrl Y \> \esc{shift-y}\\
X
XTranspose the character under the cursor with the next \> \ctrl T \> \esc{xp}\\
X
XChange the rest of the word to lower case \> \esc l \> \\
X
XChange the rest of the word to capitals (upper case) \> \esc c \> \\
X
XRe-submit the command to \splus. \> {\tt Return} \> {\tt Return}
X
X\end{tabbing}
X
X\vfill
X\renewcommand{\baselinestretch}{1.0}\tiny\normalsize
X
X{\bf NOTE}: With {\tt vi} style commands the \esc{} need only be issued
Xbefore the first recall command, and to terminate insert and append
Xcommands, as is usual in {\tt vi}.
X
XThe final {\tt Return} terminates the command line editing sequence for
Xcommands of either style.
X\newpage
X
END_OF_FILE
if test 4325 -ne `wc -c <'SplusDS/editor.tex'`; then
echo shar: \"'SplusDS/editor.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/editor.tex'
fi
if test -f 'SplusDS/exercises.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/exercises.aux'\"
else
echo shar: Extracting \"'SplusDS/exercises.aux'\" \(5967 characters\)
sed "s/^X//" >'SplusDS/exercises.aux' <<'END_OF_FILE'
X\relax
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {C}Exercises}{66}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.1}The Cloud Point Data}{66}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.2}The Janka Hardness Data}{66}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.3}The Tuggeranong House Price Data}{67}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.4}Yorke Penninsula Wheat Data}{67}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.5}The Iowa Wheat Yield Data}{67}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {5}{\ignorespaces The Tuggeranong house price data}}{68}}
X\newlabel{tugg}{{5}{68}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.6}The Gasoline Yield Data}{68}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {6}{\ignorespaces Yorke Penninsula Wheat Yield Data}}{69}}
X\newlabel{sawheat}{{6}{69}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.7}The Michaelson-Morley Speed of Light Data}{69}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {7}{\ignorespaces The Iowa Historical Wheat Yield Data}}{70}}
X\newlabel{iowheat}{{7}{70}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {8}{\ignorespaces The gasoline recovery data}}{71}}
X\newlabel{oildata}{{8}{71}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.8}The Rat Genotype Data}{71}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.9}Fisher's Sugar Beet Data}{71}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {9}{\ignorespaces The Michaelson-Morley speed of light data}}{72}}
X\newlabel{morley}{{9}{72}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.10}A Barley Split Plot Field Trial.}{72}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {10}{\ignorespaces The Rat Genotype Data}}{73}}
X\newlabel{genotype}{{10}{73}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.11}The Snail Mortality Data}{73}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {11}{\ignorespaces Fisher's sugar beet data}}{74}}
X\newlabel{sugar}{{11}{74}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.12}The Kalythos Blindness Data}{74}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {12}{\ignorespaces A split plot Barley field trial}}{75}}
X\newlabel{barley}{{12}{75}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {13}{\ignorespaces The snail mortality data}}{75}}
X\newlabel{snails}{{13}{75}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {14}{\ignorespaces The Kalythos blindness data}}{75}}
X\newlabel{kalythos}{{14}{75}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.13}The Stormer Viscometer Data}{76}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {15}{\ignorespaces The Stormer viscometer calibration data}}{76}}
X\newlabel{stormer}{{15}{76}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.14}The Chlorine availability data}{76}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {16}{\ignorespaces The Chlorine availability data.}}{77}}
X\newlabel{chlorine}{{16}{77}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.15}The Saturated Steam Pressure Data}{77}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {17}{\ignorespaces Temperature and Pressure in Saturated Steam}}{78}}
X\newlabel{steam}{{17}{78}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.16}Count Rumford's Friction Data}{78}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {18}{\ignorespaces The Rumford Friction Cooling Data}}{78}}
X\newlabel{rumford}{{18}{78}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.17}The Jellyfish Data.}{79}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {19}{\ignorespaces The Jellyfish data -- Danger Island and Salamander Bay}}{79}}
X\newlabel{jelly}{{19}{79}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.18}Archaelogical Pottery Data}{79}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {20}{\ignorespaces The Pottery Composition Data}}{80}}
X\newlabel{pottery}{{20}{80}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.19}The Beaujolais Quality Data}{80}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {C.20}The Painter's Data of de Piles}{80}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {21}{\ignorespaces Quality Measurements on Young Beaujolais Wine Samples}}{81}}
X\newlabel{wine}{{21}{81}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {22}{\ignorespaces The Subjective Assessment Data of de Piles}}{82}}
X\newlabel{paint}{{22}{82}}
X\global\@namedef{cp@exercises}{
X\setcounter{page}{83}
X\setcounter{equation}{1}
X\setcounter{enumi}{6}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{8}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{3}
X\setcounter{subsection}{20}
X\setcounter{subsubsection}{0}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{11}
X\setcounter{table}{22}
X}
END_OF_FILE
if test 5967 -ne `wc -c <'SplusDS/exercises.aux'`; then
echo shar: \"'SplusDS/exercises.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/exercises.aux'
fi
if test -f 'SplusDS/exercises.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/exercises.tex'\"
else
echo shar: Extracting \"'SplusDS/exercises.tex'\" \(42927 characters\)
sed "s/^X//" >'SplusDS/exercises.tex' <<'END_OF_FILE'
X% -*-latex-*-
X% Document name: Splus.tex
X%
X% Version 2.0, March, 1992
X%
X
X\section{Exercises}
X
X\subsection{The Cloud Point Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> Draper \& Smith, {\it Applied Regression Analysis}, p.\ 162\\
X{\bf Category:} \> Polynomial regression. Simple plots.
X\end{tabbing}
X
X\subsubsection*{Description}
XThe cloud point of a liquid is a measure of the degree of crystalization
Xin a stock that can be measured by the refractive index. It has been
Xsuggested that the percentage of $I_8$ in the base stock is an excellent
Xpredictor of cloud point using the second or third order model:
X\[
XY = \beta_0 + \beta_1x + \beta_2x^2 + \beta_3x^3 + E,\qquad E\sim {\rm
XN}(0,\sigma^2)
X\]
X
X\subsubsection*{Data}
XThe following data was collected on stocks with known percentage of $I_8$:
X\begin{center}
X\def\0{\hphantom{0}}
X\begin{tabular}{@{\protect\strutt}|cc|cc|cc|cc|}
X\hline
X$I_8$\% & Cloud Point & $I_8$\% & Cloud Point & $I_8$\% & Cloud Point &
X$I_8$\% & Cloud Point \\
X\hline
X \00 & 21.9 & \02 & 26.1 & \05 & 28.9 & \08 & 31.4 \\
X \00 & 22.1 & \03 & 26.8 & \06 & 29.8 & \08 & 31.5\\
X \00 & 22.8 & \03 & 27.3 & \06 & 30.0 & \09 & 31.8\\
X \01 & 24.5 & \04 & 28.2 & \06 & 30.3 & 10 & 33.1\\
X \02 & 26.0 & \04 & 28.5 & \07 & 30.4 & &\\
X\hline
X\end{tabular}
X\end{center}
X
XThe data may be read from file {\tt cloud.data} in a form suitable to
Xconstruct a data frame.
X
X\subsection{The Janka Hardness Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> E. J. Williams: {\it Regression Analysis}, Wiley, 1959.\\
X{\bf Category:} \> Polynomial regression. Transformations.
X\end{tabbing}
X
X\subsubsection*{Description}
XThe Janka hardness is an important structural property of Australian
Xtimbers, which is difficult to measure. It is, however, related to the
Xdensity of the timber, which is relatively easy to measure. A low degree
Xpolynomial regression is suggested as appropriate.
X\[
XY = \beta_0+\beta_1x+\beta_2x^2+\cdots+E
X\]
Xwhere $Y$ is the hardness and $x$ the density.
X
X\subsubsection*{Data}
XThe following data comes from samples of 36 Australian Eucalypt hardwoods.
X\begin{center}
X\def\0{\hphantom{0}}
X\begin{tabular}{@{\protect\strutt}|cc|cc|cc|cc|cc|cc|}
X\hline
XD & H & D & H & D & H & D & H & D & H & D & H \\
X\hline
X 24.7 & 484 & 30.3 &\0587 & 39.4 & 1210 & 42.9 & 1270 & 53.4 & 1880 & 59.8 & 1940\\
X 24.8 & 427 & 32.7 &\0704 & 39.9 &\0989 & 45.8 & 1180 & 56.0 & 1980 & 66.0 & 3260\\
X 27.3 & 413 & 35.6 &\0979 & 40.3 & 1160 & 46.9 & 1400 & 56.5 & 1820 & 67.4 & 2700\\
X 28.4 & 517 & 38.5 &\0914 & 40.6 & 1010 & 48.2 & 1760 & 57.3 & 2020 & 68.8 & 2890\\
X 28.4 & 549 & 38.8 & 1070 & 40.7 & 1100 & 51.5 & 1710 & 57.6 & 1980 & 69.1 & 2740\\
X 29.0 & 648 & 39.3 & 1020 & 40.7 & 1130 & 51.5 & 2010 & 59.2 & 2310 & 69.1 & 3140\\
X\hline
X\end{tabular}
X\end{center}
X
XThe data may be read as a data frame from file {\tt janka.data}.
X
X\subsection{The Tuggeranong House Price Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> Dr~Ray Correll, Personal communication\\
X{\bf Category:} \> Multiple regression, coplots.
X\end{tabbing}
X
X\subsubsection*{Description}
XBefore buying a house in Tuggeranong in February, 1987, a cautious
Xpotential householder collected some data on houses on the market. The
Xdata for 20 such houses is shown in the table and is available as the
Xfile {\tt house.dat}. The variables collected are, in order, price,
Xtotal floor area, block area, number of main rooms, age of house and
Xwhether or not the house was centrally heated.
X
X
X\subsubsection*{Data}
XThe data is given in Table \ref{tugg}
Xand is available as the file {\tt house.data}.
X
X\begin{table}[ht]
X\begin{center}
X\def\0{\hphantom{0}}
X\begin{tabular}{@{\protect\strutt}|*{6}{c|}}
X\hline
XPrice (\$000s) & Floor (m$^2$) & Block (m$^2$) & Rooms & Age (years) &
XCent.\ Heat. \\
X\hline
X52.00 & 111.0 & \0830 & 5 & 6.2 & no \\
X54.75 & 128.0 & \0710 & 5 & 7.5 & no \\
X57.50 & 101.0 & 1000 & 5 & 4.2 & no \\
X57.50 & 131.0 & \0690 & 6 & 8.8 & no \\
X59.75 & \093.0 & \0900 & 5 & 1.9 & yes \\
X62.50 & 112.0 & \0640 & 6 & 5.2 & no \\
X64.75 & 137.6 & \0700 & 6 & 6.6 & yes \\
X67.25 & 148.5 & \0740 & 6 & 2.3 & no \\
X67.50 & 113.5 & \0660 & 6 & 6.1 & no \\
X69.75 & 152.0 & \0645 & 7 & 9.2 & no \\
X70.00 & 121.5 & \0730 & 5 & 4.3 & yes \\
X75.50 & 141.0 & \0730 & 7 & 4.3 & no \\
X77.50 & 124.0 & \0670 & 6 & 1.0 & yes \\
X77.50 & 153.5 & \0795 & 7 & 7.0 & yes \\
X81.25 & 149.0 & \0900 & 6 & 3.6 & yes \\
X82.50 & 135.0 & \0810 & 6 & 1.7 & yes \\
X86.25 & 162.0 & \0930 & 6 & 1.2 & yes \\
X87.50 & 145.0 & \0825 & 6 & 0.0 & yes \\
X88.00 & 172.0 & \0950 & 7 & 2.3 & yes \\
X92.00 & 170.5 & \0870 & 7 & 0.7 & yes \\
X\hline
X\end{tabular}
X\end{center}
X
X\caption{\label{tugg}The Tuggeranong house price data}
X\end{table}
X
X
X\subsection{Yorke Penninsula Wheat Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> K. W. Morris (private communication)\\
X{\bf Category:} \> Multiple regression.
X\end{tabbing}
X
X\subsubsection*{Description}
XThe annual yield of wheat in a marginal wheat growing district on the Yorke
XPenninsula, South Australia, together with the rainfall for the three
Xgrowing months, for the years 1931--1955. The year itself is potentially a
Xsurrogate predictor to allow for improvements in varieties and farm
Xpractice. Yield is in bushels per acre, and rainfall is in inches.
X
X\subsubsection*{Data}
X
X\begin{table}[ht]
X\begin{center}
X\begin{tabular}{@{\protect\strutt}|crrrr|crrrr|}
X\hline
XYear & Rain0 & Rain1 & Rain2 & Yield & Year & Rain0 & Rain1 & Rain2 & Yield\\
X\hline
X 1931 & .05 & 1.61 & 3.52 & .31 & 1944 & 3.30 & 4.19 & 2.11 & 4.60\\
X 1932 & 1.15 & .60 & 3.46 & .00 & 1945 & .44 & 3.41 & 1.55 & .35\\
X 1933 & 2.22 & 4.94 & 3.06 & 5.47 & 1946 & .50 & 3.26 & 1.20 & .00\\
X 1934 & 1.19 & 11.26 & 4.91 & 16.73 & 1947 & .18 & 1.52 & 1.80 & .00\\
X 1935 & 1.40 & 10.95 & 4.23 & 10.54 & 1948 & .80 & 3.25 & 3.55 & 2.98\\
X 1936 & 2.96 & 4.96 & .11 & 5.89 & 1949 & 7.08 & 5.93 & .93 & 11.89\\
X 1937 & 2.68 & .67 & 2.17 & .03 & 1950 & 2.54 & 4.71 & 2.51 & 6.56\\
X 1938 & 3.66 & 8.49 & 11.95 & 16.03 & 1951 & 1.08 & 3.37 & 4.02 & 1.30\\
X 1939 & 5.15 & 3.60 & 2.18 & 6.57 & 1952 & .22 & 3.24 & 4.93 & .03\\
X 1940 & 6.44 & 2.69 & 1.37 & 8.43 & 1953 & .55 & 1.78 & 1.97 & .00\\
X 1941 & 2.01 & 6.88 & .92 & 8.68 & 1954 & 1.65 & 3.22 & 1.65 & 3.09\\
X 1942 & .73 & 3.30 & 3.97 & 2.49 & 1955 & .72 & 3.42 & 3.31 & 2.72\\
X 1943 & 2.52 & 1.93 & 1.16 & .98 & & & & &\\
X\hline
X\end{tabular}
X\end{center}
X
X\caption{\label{sawheat} Yorke Penninsula Wheat Yield Data}
X\end{table}
XThe data is given in Table~\ref{sawheat} and may be read as a data frame from
Xfile {\tt sawheat.data}.
X
X\subsection{The Iowa Wheat Yield Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> CAED Report, 1964. Quoted in Draper \& Smith.\\
X{\bf Category:} \> Multiple regression; diagnostics.
X\end{tabbing}
X
X\subsubsection*{Description}
XThe data gives the pre-season and three growing months' precipitation, the
Xmean temperatures for the three growing months and harvest month, the year,
Xand the yield of wheat for the USA state of Iowa, for the years 1930--1962.
X
X\subsubsection*{Data}
X
X\begin{table}[ht]
X\begin{center}
X\small
X\begin{tabular}{@{\protect\strutt}|ccccccccc|c|}
X\hline
X Year & Rain0 & Temp1 & Rain1 &Temp2 & Rain2 &Temp3 & Rain3 &Temp4 &
X Yield\\
X\hline
X 1930 & 17.75 & 60.2 & 5.83 & 69.0 & 1.49 & 77.9 & 2.42 & 74.4 & 34.0\\
X 1931 & 14.76 & 57.5 & 3.83 & 75.0 & 2.72 & 77.2 & 3.30 & 72.6 & 32.9\\
X 1932 & 27.99 & 62.3 & 5.17 & 72.0 & 3.12 & 75.8 & 7.10 & 72.2 & 43.0\\
X 1933 & 16.76 & 60.5 & 1.64 & 77.8 & 3.45 & 76.4 & 3.01 & 70.5 & 40.0\\
X 1934 & 11.36 & 69.5 & 3.49 & 77.2 & 3.85 & 79.7 & 2.84 & 73.4 & 23.0\\
X 1935 & 22.71 & 55.0 & 7.00 & 65.9 & 3.35 & 79.4 & 2.42 & 73.6 & 38.4\\
X 1936 & 17.91 & 66.2 & 2.85 & 70.1 & 0.51 & 83.4 & 3.48 & 79.2 & 20.0\\
X 1937 & 23.31 & 61.8 & 3.80 & 69.0 & 2.63 & 75.9 & 3.99 & 77.8 & 44.6\\
X 1938 & 18.53 & 59.5 & 4.67 & 69.2 & 4.24 & 76.5 & 3.82 & 75.7 & 46.3\\
X 1939 & 18.56 & 66.4 & 5.32 & 71.4 & 3.15 & 76.2 & 4.72 & 70.7 & 52.2\\
X 1940 & 12.45 & 58.4 & 3.56 & 71.3 & 4.57 & 76.7 & 6.44 & 70.7 & 52.3\\
X 1941 & 16.05 & 66.0 & 6.20 & 70.0 & 2.24 & 75.1 & 1.94 & 75.1 & 51.0\\
X 1942 & 27.10 & 59.3 & 5.93 & 69.7 & 4.89 & 74.3 & 3.17 & 72.2 & 59.9\\
X 1943 & 19.05 & 57.5 & 6.16 & 71.6 & 4.56 & 75.4 & 5.07 & 74.0 & 54.7\\
X 1944 & 20.79 & 64.6 & 5.88 & 71.7 & 3.73 & 72.6 & 5.88 & 71.8 & 52.0\\
X 1945 & 21.88 & 55.1 & 4.70 & 64.1 & 2.96 & 72.1 & 3.43 & 72.5 & 43.5\\
X 1946 & 20.02 & 56.5 & 6.41 & 69.8 & 2.45 & 73.8 & 3.56 & 68.9 & 56.7\\
X 1947 & 23.17 & 55.6 & 10.39 & 66.3 & 1.72 & 72.8 & 1.49 & 80.6 & 30.5\\
X 1948 & 19.15 & 59.2 & 3.42 & 68.6 & 4.14 & 75.0 & 2.54 & 73.9 & 60.5\\
X 1949 & 18.28 & 63.5 & 5.51 & 72.4 & 3.47 & 76.2 & 2.34 & 73.0 & 46.1\\
X 1950 & 18.45 & 59.8 & 5.70 & 68.4 & 4.65 & 69.7 & 2.39 & 67.7 & 48.2\\
X 1951 & 22.00 & 62.2 & 6.11 & 65.2 & 4.45 & 72.1 & 6.21 & 70.5 & 43.1\\
X 1952 & 19.05 & 59.6 & 5.40 & 74.2 & 3.84 & 74.7 & 4.78 & 70.0 & 62.2\\
X 1953 & 15.67 & 60.0 & 5.31 & 73.2 & 3.28 & 74.6 & 2.33 & 73.2 & 52.9\\
X 1954 & 15.92 & 55.6 & 6.36 & 72.9 & 1.79 & 77.4 & 7.10 & 72.1 & 53.9\\
X 1955 & 16.75 & 63.6 & 3.07 & 67.2 & 3.29 & 79.8 & 1.79 & 77.2 & 48.4\\
X 1956 & 12.34 & 62.4 & 2.56 & 74.7 & 4.51 & 72.7 & 4.42 & 73.0 & 52.8\\
X 1957 & 15.82 & 59.0 & 4.84 & 68.9 & 3.54 & 77.9 & 3.76 & 72.9 & 62.1\\
X 1958 & 15.24 & 62.5 & 3.80 & 66.4 & 7.55 & 70.5 & 2.55 & 73.0 & 66.0\\
X 1959 & 21.72 & 62.8 & 4.11 & 71.5 & 2.29 & 72.3 & 4.92 & 76.3 & 64.2\\
X 1960 & 25.08 & 59.7 & 4.43 & 67.4 & 2.76 & 72.6 & 5.36 & 73.2 & 63.2\\
X 1961 & 17.79 & 57.4 & 3.36 & 69.4 & 5.51 & 72.6 & 3.04 & 72.4 & 75.4\\
X 1962 & 26.61 & 66.6 & 3.12 & 69.1 & 6.27 & 71.6 & 4.31 & 72.5 & 76.0\\
X\hline
X\end{tabular}
X\end{center}
X\caption{\label{iowheat} The Iowa Historical Wheat Yield Data}
X\end{table}
XThe data is given in Table~\ref{iowheat} and may be read as a data frame from
Xfile {\tt iowheat.data}.
X
X
X\subsection{The Gasoline Yield Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> {\it Estimate gasoline yields from crudes\/}\\
X\> by Nilon H.~Prater, {\sf Petroleum Refiner}, {\bf 35}, \#5.\\
X{\bf Category:} \> Analysis of variance, covariance, and multiple regression.\\
X\> Modern regression.
X\end{tabbing}
X
X\subsubsection*{Description}
XThe data gives the gasoline yield as a percent of crude oil, say $y$, and
Xfour independent variables which may influence yield. These are
X\begin{description}
X
X\item[$x_1$:] The crude oil gravity, in $^0${\sf API},
X
X\item[$x_2$:] The crude oil vapour pressure,
X
X\item[$x_3$:] The crude oil 10\% point, {\sf ASTM},
X
X\item[$x_4$:] The gasoline end point.
X
X\end{description}
X
XThe data comes as 10 separate samples, and within each sample the values
Xfor $x_1$, $x_2$, and $x_3$ are constant.
X
X\subsubsection*{Data}
XThe data is shown in Table~\ref{oildata}, and is available as the file
X{\tt oil.data} in a form suitable for constructing a data frame.
X
X\begin{table}[ht]
X\begin{center}
X\def\0{\hphantom{0}}
X\begin{tabular}{@{\protect\strutt}|crrrrr|crrrrr|}
X\hline
XSample& $x_1$&$x_2$&$x_3$&$x_4$&$y$ &Sample& $x_1$&$x_2$&$x_3$&$x_4$&$y$\\
X\hline
X \01& 31.8& 0.2& 316& 365& 8.5 &\06& 40.0& 6.1& 217& 212& 7.4\\
X \01& 31.8& 0.2& 316& 379& 14.7 &\06& 40.0& 6.1& 217& 272& 18.2\\
X \01& 31.8& 0.2& 316& 428& 18.0 &\06& 40.0& 6.1& 217& 340& 30.4\\
X% & & & & & & & & & & & \\
X \02& 32.2& 2.4& 284& 351& 14.0 &\07& 40.3& 4.8& 231& 307& 14.4\\
X \02& 32.2& 2.4& 284& 424& 23.2 &\07& 40.3& 4.8& 231& 367& 26.8\\
X & & & & & &\07& 40.3& 4.8& 231& 395& 34.9\\
X% & & & & & & & & & & & \\
X \03& 32.2& 5.2& 236& 267& 10.0 &\08& 40.8& 3.5& 210& 218& 8.0\\
X \03& 32.2& 5.2& 236& 360& 24.8 &\08& 40.8& 3.5& 210& 273& 13.1\\
X \03& 32.2& 5.2& 236& 402& 31.7 &\08& 40.8& 3.5& 210& 347& 26.6\\
X% & & & & & & & & & & & \\
X \04& 38.1& 1.2& 274& 285& 5.0 &\09& 41.3& 1.8& 267& 235& 2.8\\
X \04& 38.1& 1.2& 274& 365& 17.6 &\09& 41.3& 1.8& 267& 275& 6.4\\
X \04& 38.1& 1.2& 274& 444& 32.1 &\09& 41.3& 1.8& 267& 358& 16.1\\
X & & & & & &\09& 41.3& 1.8& 267& 416& 27.8\\
X \05& 38.4& 6.1& 220& 235& 6.9 & 10& 50.8& 8.6& 190& 205& 12.2\\
X \05& 38.4& 6.1& 220& 300& 15.2 & 10& 50.8& 8.6& 190& 275& 22.3\\
X \05& 38.4& 6.1& 220& 365& 26.0 & 10& 50.8& 8.6& 190& 345& 34.7\\
X \05& 38.4& 6.1& 220& 410& 33.6 & 10& 50.8& 8.6& 190& 407& 45.7\\
X\hline
X\end{tabular}
X\end{center}
X
X\caption{\label{oildata}The gasoline recovery data}
X\end{table}
X
X
X\subsection{The Michaelson-Morley Speed of Light Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> Weekes: A Genstat Primer.\\
X{\bf Category:} \> Analysis of Variance.
X\end{tabbing}
X
X\subsubsection*{Description}
XThe classical data of Michaelson and Morley on the speed of light. The
Xdata consists of five experiments, each consisting of 20 consecutive
X``runs''. The response is the speed of light measurement, suitably coded.
XThe data is here viewed as a randomized block experiment with {\it
Xexperiment\/} and {\it run\/} as the factors. {\it run\/} may also be
Xconsidered a quantitative variate to account for linear (or polynomial)
Xchanges in the measurement over the course of a single experiment.
X
X\subsubsection*{Data}
XThe data is given in Table~\ref{morley} and may be read as a data frame
Xfrom file {\tt morley.data} in a form suitable for constructing a data frame.
X
X\begin{table}[ht]
X\begin{center}
X\begin{tabular}{|rrrrr|c@{\protect\strutt}|rrrrr|}
X \cline{1-5} \cline{7-11}
X\multicolumn{5}{|c|}{Runs 1--10}&\hspace*{1cm}&\multicolumn{5}{c|}{Runs
X11--20}\\
X ${\cal E}_1$ & ${\cal E}_2$ & ${\cal E}_3$ & ${\cal E}_4$ &
X ${\cal E}_5$ && ${\cal E}_1$ & ${\cal E}_2$ & ${\cal E}_3$ &
X ${\cal E}_4$ & ${\cal E}_5$\\
X \cline{1-5} \cline{7-11}
X 850 & 960 & 880 & 890 & 890 && 1000 & 830 & 880 & 910 & 870\\
X 740 & 940 & 880 & 810 & 840 && 980 & 790 & 910 & 920 & 870\\
X 900 & 960 & 880 & 810 & 780 && 930 & 810 & 850 & 890 & 810\\
X 1070 & 940 & 860 & 820 & 810 && 650 & 880 & 870 & 860 & 740\\
X 930 & 880 & 720 & 800 & 760 && 760 & 880 & 840 & 880 & 810\\
X 850 & 800 & 720 & 770 & 810 && 810 & 830 & 840 & 720 & 940\\
X 950 & 850 & 620 & 760 & 790 &&1000 & 800 & 850 & 840 & 950\\
X 980 & 880 & 860 & 740 & 810 &&1000 & 790 & 840 & 850 & 800\\
X 980 & 900 & 970 & 750 & 820 && 960 & 760 & 840 & 850 & 810\\
X 880 & 840 & 950 & 760 & 850 && 960 & 800 & 840 & 780 & 870\\
X \cline{1-5} \cline{7-11}
X\end{tabular}
X\end{center}
X
X\caption{\label{morley}The Michaelson-Morley speed of light data}
X\end{table}
X
X\subsection{The Rat Genotype Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> Quoted in Scheffe, H.: {\it The Analysis of Variance}\\
X{\bf Category:} \> Unbalanced double classification.
X\end{tabbing}
X
X
X\subsubsection*{Description}
XData from a foster feeding experiment with rat mothers and litters of four
Xdifferent genotypes: $A$, $F$, $I$ and $J$. The measurement is the litter
Xweight gain after a trial feeding period.
X
X\subsubsection*{Data}
X
X\begin{table}[ht]
X\begin{center}
X\begin{tabular}{@{\protect\strutt}|c|cccc|}
X\hline
XLitter's&\multicolumn{4}{c|}{Mother's Genotype}\\
XGenotype & $A$ & $F$ & $I$ & $J$ \\
X\hline
X$A$ & 61.5 & 55.0 & 52.5 & 42.0 \\
X & 68.2 & 42.0 & 61.8 & 54.0 \\
X & 64.0 & 60.2 & 49.5 & 61.0 \\
X & 65.0 & & 52.7 & 48.2 \\
X & 59.7 & & & 39.6 \\
X\hline
X$F$ & 60.3 & 50.8 & 56.5 & 51.3 \\
X & 51.7 & 64.7 & 59.0 & 40.5 \\
X & 49.3 & 61.7 & 47.2 & \\
X & 48.0 & 64.0 & 53.0 & \\
X & & 62.0 & & \\
X\hline
X$I$ & 37.0 & 56.3 & 39.7 & 50.0 \\
X & 36.3 & 69.8 & 46.0 & 43.8 \\
X & 68.0 & 67.0 & 61.3 & 54.5 \\
X & & & & 55.3 \\
X & & & & 55.7 \\
X\hline
X$J$ & 59.0 & 59.5 & 45.2 & 44.8 \\
X & 57.4 & 52.8 & 57.0 & 51.5 \\
X & 54.0 & 56.0 & 61.4 & 53.0 \\
X & 47.0 & & & 42.0 \\
X & & & & 54.0 \\
X\hline
X\end{tabular}
X\end{center}
X\caption{\label{genotype} The Rat Genotype Data}
X\end{table}
XThe data is given in Table~\ref{genotype} and may be read as a data frame from
Xfile {\tt genotype.data}.
X
X\subsection{Fisher's Sugar Beet Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> R. A. Fisher, {\sl Design of Experiments}.\\
X{\bf Category:} \> Analysis of variance and covariance.
X\end{tabbing}
X
X\subsubsection*{Description}
XA classical $3\times2^3$ randomized block experiment in four blocks of size
X24. The response is the total weight of sugarbeet roots off the plot, but
Xthis is accompanied by the number of roots measured. The suggestion is
Xthat number of roots should be a covariate to allow for varying plot size.
X
XThe factors are {\sl Variety}. (3 levels, $a$, $b$ and $c$), and N, P and K
Xeach at 2 levels, present or absent.
X
X\subsubsection*{Data}
XThe data is given in Table~\ref{sugar} and may be read from the file {\tt
Xsugar.data} in a form suitable to construct a data frame.
X
X\begin{table}[ht]
X\begin{center}
X\begin{tabular}{@{\protect\strutt}|cccc|*{4}{rr|}}
X\hline
X&&&&\multicolumn{2}{c|}{Block 1}&\multicolumn{2}{c|}{Block
X2}&\multicolumn{2}{c|}{Block 3}&\multicolumn{2}{c|}{Block 4}\\
X V & N & P & K & No & Wt & No & Wt & No & Wt & No
X & Wt\\
X\hline
X $a$ & $-$ & $-$ & $-$ & 124 & 162 & 133 & 162 & 114 & 127 & 127 & 158\\
X $a$ & $-$ & $-$ & $k$ & 131 & 152 & 161 & 164 & 130 & 141 & 145 & 188\\
X $a$ & $-$ & $p$ & $-$ & 115 & 173 & 134 & 175 & 134 & 142 & 109 & 162\\
X $a$ & $-$ & $p$ & $k$ & 126 & 140 & 133 & 158 & 106 & 148 & 132 & 160\\
X $a$ & $n$ & $-$ & $-$ & 136 & 184 & 134 & 178 & 127 & 168 & 139 & 199\\
X $a$ & $n$ & $-$ & $k$ & 134 & 112 & 156 & 193 & 101 & 171 & 138 & 191\\
X $a$ & $n$ & $p$ & $-$ & 132 & 190 & 104 & 166 & 119 & 157 & 132 & 193\\
X $a$ & $n$ & $p$ & $k$ & 120 & 175 & 147 & 155 & 107 & 139 & 148 & 192\\
X $b$ & $-$ & $-$ & $-$ & 145 & 133 & 147 & 130 & 139 & 138 & 127 & 128\\
X $b$ & $-$ & $-$ & $k$ & 156 & 117 & 152 & 137 & 107 & 121 & 147 & 147\\
X $b$ & $-$ & $p$ & $-$ & 152 & 140 & 138 & 101 & 125 & 124 & 120 & 143\\
X $b$ & $-$ & $p$ & $k$ & 137 & 127 & 145 & 132 & 125 & 132 & 143 & 139\\
X $b$ & $n$ & $-$ & $-$ & 124 & 163 & 138 & 159 & 140 & 166 & 159 & 174\\
X $b$ & $n$ & $-$ & $k$ & 136 & 143 & 142 & 144 & 133 & 142 & 148 & 159\\
X $b$ & $n$ & $p$ & $-$ & 140 & 168 & 142 & 150 & 133 & 118 & 138 & 157\\
X $b$ & $n$ & $p$ & $k$ & 146 & 144 & 135 & 160 & 138 & 155 & 140 & 153\\
X $c$ & $-$ & $-$ & $-$ & 113 & 122 & 138 & 132 & 119 & 123 & 127 & 146\\
X $c$ & $-$ & $-$ & $k$ & 91 & 107 & 149 & 171 & 118 & 142 & 129 & 151\\
X $c$ & $-$ & $p$ & $-$ & 123 & 118 & 139 & 142 & 127 & 120 & 124 & 138\\
X $c$ & $-$ & $p$ & $k$ & 129 & 140 & 126 & 115 & 129 & 130 & 142 & 152\\
X $c$ & $n$ & $-$ & $-$ & 121 & 118 & 141 & 152 & 127 & 149 & 127 & 165\\
X $c$ & $n$ & $-$ & $k$ & 126 & 148 & 128 & 152 & 107 & 147 & 110 & 136\\
X $c$ & $n$ & $p$ & $-$ & 103 & 112 & 144 & 175 & 102 & 152 & 143 & 173\\
X $c$ & $n$ & $p$ & $k$ & 120 & 162 & 125 & 160 & 129 & 173 & 137 & 185\\
X\hline
X\end{tabular}
X\end{center}
X\caption{\label{sugar}Fisher's sugar beet data}
X\end{table}
X
X
X\subsection{A Barley Split Plot Field Trial.}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> Unknown. Traditional data.\\
X{\bf Category:} \> Multistratum analysis of variance.
X\end{tabbing}
X
X\subsubsection*{Description}
XAn experiment involving barley varieties and manure (nitrogen) was conducted in 6
Xblocks of 3 whole plots.
X
XEach whole plot was divided into 4 subplots. Three varieties of barley were
Xused in the experiment with one variety being sown in each whole plot,
Xwhile the four levels of manure (0, 0.01, 0.02, and 0.04 tons per acre)
Xwere used, one level in each of the four subplots of each whole plot. In
Xthe above table $V_i$ denotes the $i$th variety and $N_j$ denotes the $j$th
Xlevel of nitrogen.
X
X\subsubsection*{Data}
X
X\begin{table}[ht]
X\begin{center}
X\begin{tabular}{@{\protect\strutt}|c|c|rrrr||c|c|rrrr|}
X\hline
XBlock & Variety & $N_1$ & $N_2$ & $N_3$ & $N_4$ &
XBlock & Variety & $N_1$ & $N_2$ & $N_3$ & $N_4$ \\
X\hline
X & $V_1$ & 111 & 130 & 157 & 174 &
X & $V_1$ & 74 & 89 & 81 & 122 \\
X I & $V_2$ & 117 & 114 & 161 & 141 &
X IV & $V_2$ & 64 & 103 & 132 & 133 \\
X & $V_3$ & 105 & 140 & 118 & 156 &
X & $V_3$ & 70 & 89 & 104 & 117 \\
X\hline
X & $V_1$ & 61 & 91 & 97 & 100 &
X & $V_1$ & 62 & 90 & 100 & 116 \\
X II & $V_2$ & 70 & 108 & 126 & 149 &
X V & $V_2$ & 80 & 82 & 94 & 126 \\
X & $V_3$ & 96 & 124 & 121 & 144 &
X & $V_3$ & 63 & 70 & 109 & 99 \\
X\hline
X & $V_1$ & 68 & 64 & 112 & 86 &
X & $V_1$ & 53 & 74 & 118 & 113 \\
XIII & $V_2$ & 60 & 102 & 89 & 96 &
X VI & $V_2$ & 89 & 82 & 86 & 104 \\
X & $V_3$ & 89 & 129 & 132 & 124 &
X & $V_3$ & 97 & 99 & 119 & 121 \\
X\hline
X\end{tabular}
X\caption{\label{barley} A split plot Barley field trial}
X\end{center}
X\end{table}
XThe data is given in Table~\ref{barley} and may be read as a data frame from
Xfile {\tt barley.data}.
X
X
X\subsection{The Snail Mortality Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> Zoology Department, The University of Adelaide.\\
X{\bf Category:} \> Generalized Linear Modelling.
X\end{tabbing}
X
X\subsubsection*{Description}
XGroups of 20 snails were held for periods of 1, 2, 3 or 4 weeks (exposure)
Xin carefully controlled conditions of temperature (3 levels) and relative
Xhumidity (4 levels). There were two species of snail, A and B, and the
Xexperiment was designed as a $4\times3\times4\times2$ completely randomized
Xdesign. At the end of the exposure time the snails were tested to see if
Xthey had survived; this process itself is fatal for the animals. The
Xobject of the exercise was to model the probability of survival in terms of
Xthe stimulus variables, and in particular to test for differences between
Xspecies.
X
XThe data is unusual in that in most cases fatalities during the experiment
Xwere fairly small.
X
X\subsubsection*{Data}
X
X\begin{table}[ht]
X\begin{center}
X\begin{tabular}{@{\protect\strutt}|c|c||*{4}{rrr|}}
X\hline
X\multicolumn{2}{|c||}{}&\multicolumn{12}{c|}{Relative Humidity}\\
X\multicolumn{2}{|c||}{}&\multicolumn{3}{c}{60.0\%}&\multicolumn{3}{c}{65.8\%}&%
X \multicolumn{3}{c}{70.5\%}&\multicolumn{3}{c|}{75.8\%}\\
X\hline
X\multicolumn{2}{|c||}{}&\multicolumn{3}{c|}{Temperature}&%
X\multicolumn{3}{|c|}{Temperature}&\multicolumn{3}{c|}{Temperature}&%
X\multicolumn{3}{c|}{Temperature}\\
X\multicolumn{1}{|c}{Species}& Exposure &
X 10 & 15 & 20 & 10 & 15 & 20 & 10 & 15 & 20 & 10 & 15 & 20\\
X\hline
XA & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
X & 2 & 0 & 1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
X & 3 & 1 & 4 & 5 & 0 & 2 & 4 & 0 & 2 & 3 & 0 & 1 & 2\\
X & 4 & 7 & 7 & 7 & 4 & 4 & 7 & 3 & 3 & 5 & 2 & 3 & 3\\
X\hline
X\hline
XB & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\
X & 2 & 0 & 3 & 2 & 0 & 2 & 1 & 0 & 0 & 1 & 1 & 0 & 1\\
X & 3 & 7 & 11 & 11 & 4 & 5 & 9 & 2 & 4 & 6 & 2 & 3 & 5\\
X & 4 & 12 & 14 & 16 & 10 & 12 & 12 & 5 & 7 & 9 & 4 & 5 & 7\\
X\hline
X\end{tabular}
X\end{center}
X
X\caption{\label{snails} The snail mortality data}
X\end{table}
XThe data is given in Table~\ref{snails} and may be read as a data frame from
Xfile {\tt snails.data}.
X
X
X\subsection{The Kalythos Blindness Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> S. D. Silvey: {\sl Statistical Inference}. (Fictitious?)\\
X{\bf Category:} \> Generalized linear modelling
X\end{tabbing}
X
X\subsubsection*{Description}
XOn the Greek island of Kalythos the male inhabitants suffer from a
Xcongenital eye disease, the effects of which become more marked with
Xincreasing age. Samples of islander males of various ages were tested for
Xblindness and the results recorded.
X
X\subsubsection*{Data}
X
X\begin{table}[ht]
X\begin{center}
X\begin{tabular}{@{\protect\strutt}|l|rrrrr|}
X\hline
XAge: & 20 & 35 & 45 & 55 & 70 \\
X\hline
XNo. tested: & 50 & 50 & 50 & 50 & 50 \\
X\hline
XNo. blind: & 6 & 17 & 26 & 37 & 44 \\
X\hline
X\end{tabular}
X\end{center}
X
X\caption{\label{kalythos}The Kalythos blindness data}
X\end{table}
XThe data is given in Table~\ref{kalythos} and may be read as a data frame from
Xfile {\tt kalythos.data}.
X
X\subsubsection*{Problems}
X
X\subsection{The Stormer Viscometer Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> E. J. Williams: {\sl Regression Analysis}, Wiley, 1959\\
X{\bf Category:} \> Nonlinear regression, special regression.
X\end{tabbing}
X
X\subsubsection*{Description}
XThe stormer viscometer measures the viscosity of a fluid by measuring the
Xtime taken for an inner cylinder in the mechanism to perform a fixed number
Xof revolutions in response to an actuating weight. The viscometer is
Xcalibrated by measuring the time taken with varying weights while the
Xmechanism is suspended in fluids of accurately known viscosity. The data
Xcomes from such a calibration, and theoretical considerations suggest a
Xnonlinear relationship between time, weight and viscosity of the form
X\[
XT = \frac{\beta v_i}{w_i - \theta} + E_i
X\]
Xwhere $\beta$ and $\theta$ are unknown parameters to be estimated.
X
X
X\subsubsection*{Data}
X
X\begin{table}[ht]
X\begin{center}
X\begin{tabular}{@{\protect\strutt}|r||r|r|r|}
X\hline
X&\multicolumn{3}{c|}{Weight}\\
XViscosity & 20 & 50 & 100\\
X\hline
X\hline
X 14.7 & 35.6 & 17.6 & \\
X\hline
X 27.5 & 54.3 & 24.3 & \\
X\hline
X 42.0 & 75.6 & 31.4 & \\
X\hline
X 75.7 & 121.2 & 47.2 & 24.6\\
X\hline
X 89.7 & 150.8 & 58.3 & 30.0\\
X\hline
X 146.6 & 229.0 & 85.6 & 41.7\\
X\hline
X 158.3 & 270.0 & 101.1 & 50.3\\
X\hline
X 161.1 & & 92.2 & 45.1\\
X\hline
X 298.3 & & 187.2 & 89.0\\
X & & & 86.5\\
X\hline
X\end{tabular}
X\end{center}
X
X\caption{\label{stormer}The Stormer viscometer calibration data}
X\end{table}
XThe data is given in Table~\ref{stormer} and may be read as a data frame from
Xfile {\tt stormer.data}.
X
X
X\subsection{The Chlorine availability data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> Draper \& Smith, {\it Applied Regression Analysis}, (adapted).\\
X{\bf Category:} \> Nonlinear regression
X\end{tabbing}
X
X\subsubsection*{Description}
X
XThe following set of industrial chemical data shows the amount of chlorine
Xavailable in a certain product at various times of testing after manufacture.
XA nonlinear regression model for the chlorine decay of the form
X\[
X Y = \beta_0 + \beta_1\exp(-\theta t)
X\]
Xhas been suggested on theoretical grounds, with $Y$ the amount remaining at
Xtime $t$.
X
X\subsubsection*{Data}
X
X\begin{table}[ht]
X\begin{center}
X\begin{tabular}{@{\protect\strutt}|c|l||c|l||c|l|}
X\hline
X Weeks & Percent available & Weeks & Percent available & Weeks &
X Percent available \\
X\hline
X 8 & 49, 49& 20 & 42, 43, 42& 32 & 40, 41\\
X 10 & 47, 47, 48, 48& 22 & 40, 41, 41& 34 & 40\\
X 12 & 43, 45, 46, 46& 24 & 40, 40, 42& 36 & 38, 41\\
X 14 & 43, 43, 45& 26 & 40, 41, 41& 38 & 40, 40\\
X 16 & 43, 43, 44& 28 & 40, 41& 40 & 39\\
X 18 & 45, 46& 30 & 38, 40, 40& 42 & 39\\
X\hline
X\end{tabular}
X\end{center}
X
X\caption{\label{chlorine} The Chlorine availability data.}
X\end{table}
XThe data is given in Table~\ref{chlorine} and may be read as a data frame from
Xfile {\tt chlorine.data}.
X
X\subsection{The Saturated Steam Pressure Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> Quoted in Draper \& Smith: {\it Applied Regression Analysis\ldots}\\
X{\bf Category:} \> Nonlinear regression.
X\end{tabbing}
X
X\subsubsection*{Description}
XThe data gives the temperature ($^0$C) and pressure (Pascals) in a
Xsaturated steam driven experimental device. The relationship between
Xpressure, $Y$, and temperature, $t$, in saturated steam can be written as
X\[
XY = \alpha \exp\left\{\beta t \over \gamma + t\right\} + E
X\]
XHowever a more realistic model may have the experimental errors
Xmultiplicative rather than additive, in which case an analysis in the log
Xscale using the model
X\[
X\log Y = \log\alpha + \left\{\beta t \over \gamma + t\right\} + E
X\]
Xmay be more appropriate.
X
X\subsubsection*{Data}
X
X\begin{table}[ht]
X\begin{center}
X\begin{tabular}{@{\protect\strutt}|*{3}{rr|}}
X\hline
X Temp & Press & Temp & Press & Temp & Press\\
X\hline
X 0 & 4.14 & 50 & 98.76 & 90 & 522.78\\
X 10 & 8.52 & 60 & 151.13 & 95 & 674.32\\
X 20 & 16.31 & 70 & 224.74 & 100 & 782.04\\
X 30 & 32.18 & 80 & 341.35 & 105 & 920.01\\
X 40 & 64.62 & 85 & 423.36 & &\\
X\hline
X\end{tabular}
X\end{center}
X\caption{\label{steam} Temperature and Pressure in Saturated Steam}
X\end{table}
XThe data is given in Table~\ref{steam} and may be read as a data frame from
Xfile {\tt steam.data}.
X
X\subsection{Count Rumford's Friction Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> Bates \& Watts: {\it Nonlinear Regression Analysis\ldots}\\
X{\bf Category:} \> Nonlinear regression
X\end{tabbing}
X
X\subsubsection*{Description}
XData on the amount of heat generated by friction was obtained by Lord
XRumford in 1798. A bore was fitted into a stationary cylinder and pressed
Xagainst the bottom by a screw. The bore was turned by a team of horses
Xfor 30 minutes, after which Lord Rumford ``suffered the thermometer to
Xremain in its place nearly three quarters of an hour, observing and noting
Xdown, at small intervals of time, the temperature indicated by it''.
X
XNewton's law of cooling suggests a nonlinear regression model of
Xthe form
X\[
XY = \beta_0 + \beta_1\exp(-\theta t)
X\]
Xwhere $Y$ is the temperature and $t$ is the time in minutes.
X
X\subsubsection*{Data}
X
X\begin{table}[ht]
X\begin{center}
X\begin{tabular}{@{\protect\strutt}|*{2}{rr|}}
X\hline
X Time & Temp & Time & Temp \\
X(min.) & ($^0$F) & (min.) & ($^0$F) \\
X\hline
X 4.0 & 126 & 24.0 & 115 \\
X 5.0 & 125 & 28.0 & 114 \\
X 7.0 & 123 & 31.0 & 113 \\
X 12.0 & 120 & 34.0 & 112 \\
X 14.0 & 119 & 37.5 & 111 \\
X 16.0 & 118 & 41.0 & 110 \\
X 20.0 & 116 & & \\
X\hline
X\end{tabular}
X\end{center}
X\caption{\label{rumford} The Rumford Friction Cooling Data}
X\end{table}
XThe data is given in Table~\ref{rumford} and may be read as a data frame from
Xfile {\tt rumford.data}.
X
X\subsection{The Jellyfish Data.}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> {\it Interactive Statistics}, Ed.\ Don McNeil.\\
X{\bf Category:} \> Bivariate, two sample data.
X\end{tabbing}
X
X\subsubsection*{Description}
XTwo samples of jellyfish, from Danger Island and Salamander Bay
Xrespectively, were measured for {\tt length} and {\tt width}.
X
X\subsubsection*{Data}
X
X\begin{table}[ht]
X\begin{center}
X\begin{tabular}{@{\protect\strutt}|*{4}{rr|}}
X\hline
X\multicolumn{4}{|c|}{Danger Island}&\multicolumn{4}{c|}
X{Salamander Bay}\\
X\hline
X Width & Length & Width & Length & Width & Length & Width & Length \\
X\hline
X 6.0 & 9.0 & 11.0 & 13.0 & 12.0 & 14.0 & 16.0 & 20.0\\
X 6.5 & 8.0 & 11.0 & 14.0 & 13.0 & 17.0 & 16.0 & 20.0\\
X 6.5 & 9.0 & 11.0 & 14.0 & 14.0 & 16.5 & 16.0 & 21.0\\
X 7.0 & 9.0 & 12.0 & 13.0 & 14.0 & 19.0 & 16.5 & 19.0\\
X 7.0 & 10.0 & 13.0 & 14.0 & 15.0 & 16.0 & 17.0 & 20.0\\
X 7.0 & 11.0 & 14.0 & 16.0 & 15.0 & 17.0 & 18.0 & 19.0\\
X 8.0 & 9.5 & 15.0 & 16.0 & 15.0 & 18.0 & 18.0 & 19.0\\
X 8.0 & 10.0 & 15.0 & 16.0 & 15.0 & 18.0 & 18.0 & 20.0\\
X 8.0 & 10.0 & 15.0 & 19.0 & 15.0 & 19.0 & 19.0 & 20.0\\
X 8.0 & 11.0 & 16.0 & 16.0 & 15.0 & 21.0 & 19.0 & 22.0\\
X 9.0 & 11.0 & & & 16.0 & 18.0 & 20.0 & 22.0\\
X 10.0 & 13.0 & & & 16.0 & 19.0 & 21.0 & 21.0\\
X\hline
X\end{tabular}
X\end{center}
X\caption{\label{jelly} The Jellyfish data -- Danger Island and Salamander Bay}
X\end{table}
XThe data is given in Table~\ref{jelly} and may be read as a data frame from
Xfile {\tt jellyfish.data}.
X
X\subsection{Archaelogical Pottery Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> Tubb, A. {\em et al.\/} Archaeometry, {\bf 22}, 153--171, (1980)\\
X{\bf Category:} \> Multivariate analysis
X\end{tabbing}
X
X\subsubsection*{Description}
X The data arises from a chemical analysis of 26 samples of pottery found
X at Romano-British kiln sites in Wales, Gwent and the New Forest. The
X variables describe the composition, in terms of various metals, and are
X expressed as percentages of the oxides of the metals.
X
X The metals are aluminium, iron, magnesium, calcium and sodium and the
X sites are
X\begin{center}
XL: Llanederyn, \quad C: Caldicot\quad I: Island Thorns\quad A: Ashley Rails
X\end{center}
X
X\subsubsection*{Data}
X
X\begin{table}[ht]
X\begin{center}
X\begin{tabular}{@{\protect\strutt}|*{2}{c|rrrrr|}}
X\hline
X Site & Al & Fe & Mg & Ca & Na & Site & Al & Fe & Mg & Ca & Na\\
X\hline
X L & 14.4 & 7.00 & 4.30 & 0.15 & 0.51 & C & 11.8 & 5.44 & 3.94 & 0.30 & 0.04\\
X L & 13.8 & 7.08 & 3.43 & 0.12 & 0.17 & C & 11.6 & 5.39 & 3.77 & 0.29 & 0.06\\
X L & 14.6 & 7.09 & 3.88 & 0.13 & 0.20 & I & 18.3 & 1.28 & 0.67 & 0.03 & 0.03\\
X L & 11.5 & 6.37 & 5.64 & 0.16 & 0.14 & I & 15.8 & 2.39 & 0.63 & 0.01 & 0.04\\
X L & 13.8 & 7.06 & 5.34 & 0.20 & 0.20 & I & 18.0 & 1.50 & 0.67 & 0.01 & 0.06\\
X L & 10.9 & 6.26 & 3.47 & 0.17 & 0.22 & I & 18.0 & 1.88 & 0.68 & 0.01 & 0.04\\
X L & 10.1 & 4.26 & 4.26 & 0.20 & 0.18 & I & 20.8 & 1.51 & 0.72 & 0.07 & 0.10\\
X L & 11.6 & 5.78 & 5.91 & 0.18 & 0.16 & A & 17.7 & 1.12 & 0.56 & 0.06 & 0.06\\
X L & 11.1 & 5.49 & 4.52 & 0.29 & 0.30 & A & 18.3 & 1.14 & 0.67 & 0.06 & 0.05\\
X L & 13.4 & 6.92 & 7.23 & 0.28 & 0.20 & A & 16.7 & 0.92 & 0.53 & 0.01 & 0.05\\
X L & 12.4 & 6.13 & 5.69 & 0.22 & 0.54 & A & 14.8 & 2.74 & 0.67 & 0.03 & 0.05\\
X L & 13.1 & 6.64 & 5.51 & 0.31 & 0.24 & A & 19.1 & 1.64 & 0.60 & 0.10 & 0.03\\
X L & 12.7 & 6.69 & 4.45 & 0.20 & 0.22&&&&&&\\
X L & 12.5 & 6.44 & 3.94 & 0.22 & 0.23&&&&&&\\
X\hline
X\end{tabular}
X\end{center}
X\caption{\label{pottery} The Pottery Composition Data}
X\end{table}
XThe data is given in Table~\ref{pottery} and may be read as a data frame from
Xfile {\tt pottery.data}.
X
X\subsection{The Beaujolais Quality Data}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> Quoted in Weekes: {\em A Genstat Primer}\\
X{\bf Category:} \> Multivariate analsysis
X\end{tabbing}
X
X\subsubsection*{Description}
XQuality measurements for some identified samples of young Beaujolais.
XExtracted from Table 1 in M.~G.~Jackson, {\em et al\/}: Red wine quality:
Xcorrelations between colour, aroma and flavour and pigment and other
Xparameters of young Beaujolais, {\em Journal of Science of Food and
XAgriculture}, {\bf 29}, 715--727, (1978).
X
X\subsubsection*{Data}
X
X\begin{table}[ht]
X\begin{center}
X\begin{tabular}{@{\protect\strutt}|*{2}{c|rrrr|}}
X\hline
XLabel & OQ & AC & pH & TSO & Label & OQ & AC & pH & TSO \\
X\hline
X A & 13.54 & 1.51 & 3.36 & 13.8 & I & 12.25 & 1.32 & 3.38 & 1.4 \\
X B & 12.58 & 1.35 & 3.15 & 5.2 & J & 14.04 & 1.52 & 3.61 & 4.5 \\
X C & 11.83 & 1.09 & 3.30 & 10.6 & K & 12.67 & 1.62 & 3.38 & 0.4 \\
X D & 12.83 & 1.15 & 3.41 & 2.2 & L & 13.54 & 1.57 & 3.55 & 7.9 \\
X E & 12.83 & 1.32 & 3.44 & 2.3 & M & 13.75 & 1.63 & 3.34 & 6.3 \\
X F & 12.12 & 1.23 & 3.31 & 10.5 & N & 9.63 & 0.78 & 3.19 &40.4 \\
X G & 11.29 & 1.14 & 3.49 & 2.5 & O & 12.42 & 1.14 & 3.31 & 3.1 \\
X H & 12.79 & 1.22 & 3.56 & 16.7 & & & & & \\
X\hline
X\end{tabular}
X\end{center}
X\caption{\label{wine} Quality Measurements on Young Beaujolais Wine Samples}
X\end{table}
XThe data is given in Table~\ref{wine} and may be read as a data frame from
Xfile {\tt beaujolais.data}.
X
X\subsection{The Painter's Data of de Piles}
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \> Weekes: A Genstat Primer.\\
X{\bf Category:} \> Multivariate Analysis: Discriminant Analysis.
X\end{tabbing}
X
X\subsubsection*{Description}
XThe data shows the subjective assessment, on a 0--20 integer scale, of 54
Xclassical painters. The painters were assessed on four characteristics:
Xcomposition, drawing, colour and expression. The data is due to the
XEighteenth century art critic, de Piles.
X
XThe School to which a painter belongs is indicated by a letter code as follows:
X\begin{center}
X{\newdimen\wid
X\setbox0=\hbox{Seventeenth Century\quad}
X\wid=\wd0
X\begin{tabular}{@{\protect\strutt}|*{2}{cp{\wid}|}}
X\hline
XA & Renaissance & E & Lombard \\
XB & Mannerist & F & Sixteenth Century\\
XC & Seicento & G & Seventeenth Century \\
XD & Venetian & H & French \\
X\hline
X\end{tabular}
X}
X\end{center}
X%
X% Number of observations: 54
X% Number of variables: 5 (including the school)
X% Source: Davenport and Studdert-Kennedy, op.cit. "
X
X\subsubsection*{Data}
X{\def\0{\phantom{0}}
X\begin{table}[ht]
X\begin{center}
X\small
X\begin{tabular}{|l|cccc|c|}
X\hline
X & Composition & Drawing & Colour & Expression & School\\
X\hline
XDa Udine & 10 & \08 & 16 & \03 & A\\
XDa Vinci & 15 & 16 & \04 & 14 & A\\
XDel Piombo & \08 & 13 & 16 & \07 & A\\
XDel Sarto & 12 & 16 & \09 & \08 & A\\
XFr.\ Penni & \00 & 15 & \08 & \00 & A\\
XGuilio Romano & 15 & 16 & \04 & 14 & A\\
XMichelangelo & \08 & 17 & \04 & \08 & A\\
XPerino del Vaga & 15 & 16 & \07 & \06 & A\\
XPerugino & \04 & 12 & 10 & \04 & A\\
XRaphael & 17 & 18 & 12 & 18 & A\\
X\hline
XF. Zucarro & 10 & 13 & \08 & \08 & B\\
XFr.\ Salviata & 13 & 15 & \08 & \08 & B\\
XParmigiano & 10 & 15 & \06 & \06 & B\\
XPrimaticcio & 15 & 14 & \07 & 10 & B\\
XT. Zucarro & 13 & 14 & 10 & \09 & B\\
XVolterra & 12 & 15 & \05 & \08 & B\\
X\hline
XBarocci & 14 & 15 & \06 & 10 & C\\
XCortona & 16 & 14 & 12 & \06 & C\\
XJosepin & 10 & 10 & \06 & \02 & C\\
XL. Jordaens & 13 & 12 & \09 & \06 & C\\
XTesta & 11 & 15 & \00 & \06 & C\\
XVanius & 15 & 15 & 12 & 13 & C\\
X\hline
XBassano & \06 & \08 & 17 & \00 & D\\
XBellini & \04 & \06 & 14 & \00 & D\\
XGiorgione & \08 & \09 & 18 & \04 & D\\
XMurillo & \06 & \08 & 15 & \04 & D\\
XPalma Giovane & 12 & \09 & 14 & \06 & D\\
XPalma Vecchio & \05 & \06 & 16 & \00 & D\\
XPordenone & \08 & 14 & 17 & \05 & D\\
XTintoretto & 15 & 14 & 16 & \04 & D\\
XTitian & 12 & 15 & 18 & \06 & D\\
XVeronese & 15 & 10 & 16 & \03 & D\\
X\hline
XAlbani & 14 & 14 & 10 & \06 & E\\
XCaravaggio & \06 & \06 & 16 & \00 & E\\
XCorregio & 13 & 13 & 15 & 12 & E\\
XDomenichino & 15 & 17 & \09 & 17 & E\\
XGuercino & 18 & 10 & 10 & \04 & E\\
XLanfranco & 14 & 13 & 10 & \05 & E\\
XThe Carraci & 15 & 17 & 13 & 13 & E\\
X\hline
XDurer & \08 & 10 & 10 & \08 & F\\
XHolbein & \09 & 10 & 16 & 13 & F\\
XPourbus & \04 & 15 & \06 & \06 & F\\
XVan Leyden & \08 & \06 & \06 & \04 & F\\
X\hline
XDiepenbeck & 11 & 10 & 14 & \06 & G\\
XJ. Jordaens & 10 & \08 & 16 & \06 & G\\
XOtho Venius & 13 & 14 & 10 & 10 & G\\
XRembrandt & 15 & \06 & 17 & 12 & G\\
XRubens & 18 & 13 & 17 & 17 & G\\
XTeniers & 15 & 12 & 13 & \06 & G\\
XVan Dyck & 15 & 10 & 17 & 13 & G\\
X\hline
XBourdon & 10 & \08 & \08 & \04 & H\\
XLe Brun & 16 & 16 & \08 & 16 & H\\
XLe Suer & 15 & 15 & \04 & 15 & H\\
XPoussin & 15 & 17 & \06 & 15 & H\\
X\hline
X\end{tabular}
X\end{center}
X\caption{\label{paint} The Subjective Assessment Data of de Piles}
X\end{table}
X}
XThe data is given in Table~\ref{paint} and may be read as a data frame from
Xfile {\tt painters.data}.
X
X
X\endinput
X******************************************************************************
X\subsection{ }
X\begin{tabbing}
X{\bf Category:} \= \kill
X{\bf Source:} \>
X{\bf Category:} \>
X\end{tabbing}
X
X\subsubsection*{Description}
X
X\subsubsection*{Data}
X
X\begin{table}[ht]
X\begin{center}
X\begin{tabular}{@{\protect\strutt} }
X\hline
X
X
X
X\hline
X\end{tabular}
X\end{center}
X
X\caption{\label{ } }
X\end{table}
XThe data is given in Table~\ref{ } and may be read as a data frame from
Xfile {\tt }.
X
X\subsubsection*{Problems}
X\begin{enumerate}
X\item
X
X\item
X
X\item
X
X\end{enumerate}
X\endinput
END_OF_FILE
if test 42927 -ne `wc -c <'SplusDS/exercises.tex'`; then
echo shar: \"'SplusDS/exercises.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/exercises.tex'
fi
if test -f 'SplusDS/fancyheadings.sty' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/fancyheadings.sty'\"
else
echo shar: Extracting \"'SplusDS/fancyheadings.sty'\" \(9673 characters\)
sed "s/^X//" >'SplusDS/fancyheadings.sty' <<'END_OF_FILE'
X% fancyheadings.sty version 1.0
X% Fancy headers and footers.
X% Piet van Oostrum, Dept of Computer Science, University of Utrecht
X% Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands
X% Telephone: +31-30-531806. piet@cs.ruu.nl (mcvax!hp4nl!ruuinf!piet)
X% March, 1989.
X
X% Here is a documentstylestyle option that allows you to customize your
X% page headers and footers in an easy way. It combines features that were
X% separately available in other pagestyles, without introducing much
X% complexity. You can define:
X% - three-part headers and footers
X% - rules in header and footer
X% - headers and footers wider than \textwidth
X% - multiline headers and footers
X% - separate headers and footers for even and odd pages
X% - separate headers and footers for chapter pages
X%
X% To use this pagestyle, you must include the ``fancyheadings'' style
X% option in your \documentstyle, and issue the \pagestyle{fancy} command.
X% The \pagestyle{fancy} command should be issued after any changes made to
X% \textwidth.
X%
X% The page layout will be as follows:
X%
X% LHEAD CHEAD RHEAD
X% ----------------------------------- (rule)
X%
X% page body
X%
X%
X% ----------------------------------- (rule)
X% LFOOT CFOOT RFOOT
X%
X% The L-fields will be leftadjusted, the C-fields centered and the
X% R-fields rightadjusted.
X% Each of the six fields and the two rules can be defined separately.
X%
X% Simple use:
X%
X% The header and footer fields can be defined by commands \lhead{LHEAD}
X% and so on for the other fields. If the field depends on something in the
X% document (e.g. section titles) you must in general use the \markboth and
X% \markright commands, otherwise a title may end on the wrong page. You
X% can do this e.g. by redefining the commands \chaptermark, \sectionmark
X% and so on (see example below). The defaults for these marks are as in
X% the standard pagestyles. The marks can be put into a header or footer
X% field by referencing \leftmark and \rightmark.
X%
X% Rules in header and footer
X%
X% The thickness of the rules below the header and above the footer can be
X% changed by redefining the length parameters \headrulewidth (default
X% 0.4pt) and \footrulewidth (default 0). These may be redefined by the
X% \setlength command. A thickness of 0pt makes the rule invisible.
X% If you want to make more complicated changes, you have to redefine the
X% commands \headrule and/or \footrule.
X%
X% Headers and footers wider than \textwidth
X%
X% The headers and footers are set in a box of width \headwidth. The
X% default for this is the value of \textwidth. You can make it wider (or
X% smaller) by redefining \headwidth with the \setlength or \addtolength
X% command. The headers and footers will stick out the page on the same
X% side as the marginal notes. For example to include the marginal notes,
X% add both \marginparsep and \marginparwidth to \headwidth (see also the
X% example below).
X%
X% Multiline headers and footers
X%
X% Each of the six fields is set in an appropriate parbox, so you can put a
X% multiline part in it with the \\ command. It is also possible to put
X% extra space in it with the \vspace command. Note that if you do this you
X% will probably have to increase the \headheight or \footskip lengths.
X%
X% Separate headers and footers for even and odd pages
X%
X% If you want the headers and footers to be different on even- and
X% odd-numbered pages in the ``twoside'' style, the field-defining macros
X% can be given an optional argument, to be used on the even-numbered
X% pages, like \lhead[EVEN-LHEAD]{ODD-RHEAD}.
X%
X% Separate headers and footers for chapter pages
X%
X% LaTeX gives a \thispagestyle{plain} command for the first page of the
X% document, the first page of each chapter and a couple of other pages. It
X% might be incompatible with your pagestyle. In this case you can use a
X% slightly different version of the pagestyle, called \pagestyle{fancyplain}.
X% This pagestyle redefines the pagestyle ``plain'' to also use pagestyle
X% ``fancy'' with the following modifications:
X% - the thicknesses of the rules is defined by \plainheadrulewidth and
X% \plainfootrulewidth (both default 0).
X% - the 6 fields may be defined separately for the plain pages by
X% giving them the value \fancyplain{PLAIN-VALUE}{NORMAL-VALUE}. This
X% construct may be used in both the optional argument and the normal
X% argument. Thus \lhead[\fancyplain{F1}{F2}]{\fancyplain{F3}{F4}}
X% specifies the LHEAD value in a two-sided document:
X% F1 on an even-numbered ``plain'' page
X% F2 on an even-numbered normal page
X% F3 on an odd-numbered ``plain'' page
X% F4 on an odd-numbered normal page.
X%
X% Defaults:
X%
X% \headrulewidth 0.4pt
X% \footrulewidth 0pt
X% \plainheadrulewidth 0pt
X% \plainfootrulewidth 0pt
X%
X% \lhead[\fancyplain{}{\sl\rightmark}]{\fancyplain{}{\sl\leftmark}}
X% % i.e. empty on ``plain'' pages \rightmark on even, \leftmark on odd pages
X% \chead{}
X% \rhead[\fancyplain{}{\sl\leftmark}]{\fancyplain{}{\sl\rightmark}}
X% % i.e. empty on ``plain'' pages \leftmark on even, \rightmark on odd pages
X% \lfoot{}
X% \cfoot{\rm\thepage} % page number
X% \rfoot{}
X%
X% Examples:
X%
X% To put two lines containing the section title and the subsection title
X% in the righthandside corner, use:
X%
X% \documentstyle[fancyheadings]{article}
X% \pagestyle{fancy}
X% \renewcommand{\sectionmark}[1]{\markboth{#1}{}}
X% \renewcommand{\subsectionmark}[1]{\markright{#1}}
X% \rfoot{\leftmark\\\rightmark}
X%
X% The following definitions give an approximation of the style used in the
X% LaTeX book:
X%
X% \documentstyle[fancyheadings]{book}
X% \pagestyle{fancyplain}
X% \addtolength{\headwidth}{\marginparsep}
X% \addtolength{\headwidth}{\marginparwidth}
X% \renewcommand{\chaptermark}[1]{\markboth{#1}{#1}} % remember chapter title
X% \renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
X% % section number and title
X% \lhead[\fancyplain{}{\bf\thepage}]{\fancyplain{}{\bf\rightmark}}
X% \rhead[\fancyplain{}{\bf\leftmark}]{\fancyplain{}{\bf\thepage}}
X% \cfoot{}
X
X%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X\def\lhead{\@ifnextchar[{\@xlhead}{\@ylhead}}
X\def\@xlhead[#1]#2{\gdef\@elhead{#1}\gdef\@olhead{#2}}
X\def\@ylhead#1{\gdef\@elhead{#1}\gdef\@olhead{#1}}
X
X\def\chead{\@ifnextchar[{\@xchead}{\@ychead}}
X\def\@xchead[#1]#2{\gdef\@echead{#1}\gdef\@ochead{#2}}
X\def\@ychead#1{\gdef\@echead{#1}\gdef\@ochead{#1}}
X
X\def\rhead{\@ifnextchar[{\@xrhead}{\@yrhead}}
X\def\@xrhead[#1]#2{\gdef\@erhead{#1}\gdef\@orhead{#2}}
X\def\@yrhead#1{\gdef\@erhead{#1}\gdef\@orhead{#1}}
X
X\def\lfoot{\@ifnextchar[{\@xlfoot}{\@ylfoot}}
X\def\@xlfoot[#1]#2{\gdef\@elfoot{#1}\gdef\@olfoot{#2}}
X\def\@ylfoot#1{\gdef\@elfoot{#1}\gdef\@olfoot{#1}}
X
X\def\cfoot{\@ifnextchar[{\@xcfoot}{\@ycfoot}}
X\def\@xcfoot[#1]#2{\gdef\@ecfoot{#1}\gdef\@ocfoot{#2}}
X\def\@ycfoot#1{\gdef\@ecfoot{#1}\gdef\@ocfoot{#1}}
X
X\def\rfoot{\@ifnextchar[{\@xrfoot}{\@yrfoot}}
X\def\@xrfoot[#1]#2{\gdef\@erfoot{#1}\gdef\@orfoot{#2}}
X\def\@yrfoot#1{\gdef\@erfoot{#1}\gdef\@orfoot{#1}}
X
X\newdimen\headrulewidth
X\newdimen\footrulewidth
X\newdimen\plainheadrulewidth
X\newdimen\plainfootrulewidth
X\newdimen\headwidth
X\newif\if@fancyplain \@fancyplainfalse
X\def\fancyplain#1#2{\if@fancyplain#1\else#2\fi}
X
X% Initialization of the head and foot text.
X
X\headrulewidth 0.4pt
X\footrulewidth\z@
X\plainheadrulewidth\z@
X\plainfootrulewidth\z@
X
X\lhead[\fancyplain{}{\sl\rightmark}]{\fancyplain{}{\sl\leftmark}}
X% i.e. empty on ``plain'' pages \rightmark on even, \leftmark on odd pages
X\chead{}
X\rhead[\fancyplain{}{\sl\leftmark}]{\fancyplain{}{\sl\rightmark}}
X% i.e. empty on ``plain'' pages \leftmark on even, \rightmark on odd pages
X\lfoot{}
X\cfoot{\rm\thepage} % page number
X\rfoot{}
X
X% Put together a header or footer given the left, center and
X% right text, fillers at left and right and a rule.
X% The \lap commands put the text into an hbox of zero size,
X% so overlapping text does not generate an errormessage.
X
X\def\@fancyhead#1#2#3#4#5{#1\hbox to\headwidth{\vbox{\hbox
X{\rlap{\parbox[b]{\headwidth}{\raggedright#2\strut}}\hfill
X\parbox[b]{\headwidth}{\centering#3\strut}\hfill
X\llap{\parbox[b]{\headwidth}{\raggedleft#4\strut}}}\headrule}}#5}
X
X
X\def\@fancyfoot#1#2#3#4#5{#1\hbox to\headwidth{\vbox{\footrule
X\hbox{\rlap{\parbox[t]{\headwidth}{\raggedright#2\strut}}\hfill
X\parbox[t]{\headwidth}{\centering#3\strut}\hfill
X\llap{\parbox[t]{\headwidth}{\raggedleft#4\strut}}}}}#5}
X
X\def\headrule{{\if@fancyplain\headrulewidth\plainheadrulewidth\fi
X\hrule\@height\headrulewidth\@width\headwidth \vskip-\headrulewidth}}
X
X\def\footrule{{\if@fancyplain\footrulewidth\plainfootrulewidth\fi
X\vskip-0.3\normalbaselineskip\vskip-\footrulewidth
X\hrule\@width\headwidth\@height\footrulewidth\vskip0.3\normalbaselineskip}}
X
X\def\ps@fancy{
X\let\@mkboth\markboth
X\@ifundefined{chapter}{\def\sectionmark##1{\markboth
X{\uppercase{\ifnum \c@secnumdepth>\z@
X \thesection\hskip 1em\relax \fi ##1}}{}}
X\def\subsectionmark##1{\markright {\ifnum \c@secnumdepth >\@ne
X \thesubsection\hskip 1em\relax \fi ##1}}}
X{\def\chaptermark##1{\markboth {\uppercase{\ifnum \c@secnumdepth>\m@ne
X \@chapapp\ \thechapter. \ \fi ##1}}{}}
X\def\sectionmark##1{\markright{\uppercase{\ifnum \c@secnumdepth >\z@
X \thesection. \ \fi ##1}}}}
X\def\@oddhead{\@fancyhead\relax\@olhead\@ochead\@orhead\hss}
X\def\@oddfoot{\@fancyfoot\relax\@olfoot\@ocfoot\@orfoot\hss}
X\def\@evenhead{\@fancyhead\hss\@elhead\@echead\@erhead\relax}
X\def\@evenfoot{\@fancyfoot\hss\@elfoot\@ecfoot\@erfoot\relax}
X\headwidth\textwidth}
X\def\ps@fancyplain{\ps@fancy \let\ps@plain\ps@plain@fancy}
X\def\ps@plain@fancy{\@fancyplaintrue\ps@fancy}
END_OF_FILE
if test 9673 -ne `wc -c <'SplusDS/fancyheadings.sty'`; then
echo shar: \"'SplusDS/fancyheadings.sty'\" unpacked with wrong size!
fi
# end of 'SplusDS/fancyheadings.sty'
fi
if test -f 'SplusDS/functions.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/functions.aux'\"
else
echo shar: Extracting \"'SplusDS/functions.aux'\" \(2547 characters\)
sed "s/^X//" >'SplusDS/functions.aux' <<'END_OF_FILE'
X\relax
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {9}Writing your own functions}{31}}
X\newlabel{functions}{{9}{31}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {9.1}Defining new binary operators.}{31}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {9.2}Named arguments and defaults. ``\string\pldots\space ''}{32}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {9.3}Assignments within functions are local. Frames.}{32}}
X\@writefile{lof}{\string\contentsline\space {figure}{\string\numberline\space {4}{\ignorespaces Use of the ellipsis argument, ``\string\pldots\space ''}}{33}}
X\newlabel{ellipsis}{{4}{33}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {9.4}More advanced examples}{33}}
X\@writefile{lof}{\string\contentsline\space {figure}{\string\numberline\space {5}{\ignorespaces A function for block design efficiencies}}{33}}
X\newlabel{effic}{{5}{33}}
X\@writefile{lof}{\string\contentsline\space {figure}{\string\numberline\space {6}{\ignorespaces A function for printing arrays in compact form}}{34}}
X\newlabel{nodimnames}{{6}{34}}
X\@writefile{lof}{\string\contentsline\space {figure}{\string\numberline\space {7}{\ignorespaces A recursive function within a function}}{35}}
X\newlabel{recfun}{{7}{35}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {9.5}Customizing the environment. {\string\ptt\space .First} and {\string\ptt\space .Last}}{35}}
X\@writefile{lof}{\string\contentsline\space {figure}{\string\numberline\space {8}{\ignorespaces An example of a {\string\ptt\space .First()} function}}{35}}
X\newlabel{pointfirst}{{8}{35}}
X\@writefile{lof}{\string\contentsline\space {figure}{\string\numberline\space {9}{\ignorespaces An example of a {\string\ptt\space .Last()} function}}{36}}
X\newlabel{pointlast}{{9}{36}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {9.6}Classes, generic functions and object orientation}{36}}
X\newlabel{oops}{{9.6}{36}}
X\global\@namedef{cp@functions}{
X\setcounter{page}{37}
X\setcounter{equation}{0}
X\setcounter{enumi}{6}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{7}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{9}
X\setcounter{subsection}{6}
X\setcounter{subsubsection}{0}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{9}
X\setcounter{table}{0}
X}
END_OF_FILE
if test 2547 -ne `wc -c <'SplusDS/functions.aux'`; then
echo shar: \"'SplusDS/functions.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/functions.aux'
fi
if test -f 'SplusDS/functions.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/functions.tex'\"
else
echo shar: Extracting \"'SplusDS/functions.tex'\" \(15724 characters\)
sed "s/^X//" >'SplusDS/functions.tex' <<'END_OF_FILE'
X% -*-latex-*-
X% Document name: Splus.tex
X%
X% Version 2.0, March, 1992
X%
X{\raggedbottom
X\section{Writing your own functions}
X\label{functions}
X
XAs we have seen informally along the way, the \splus. language allows the user
Xto create objects of mode {\sl function\/}. These are true \splus. functions
Xthat are stored in a special internal form and may be used in further
Xexpressions and so on. In the process the language gains enormously in
Xpower, convenience and elegance, and learning to write useful functions is
Xone of the main ways to make your use of \splus. comfortable and productive.
X
XIt should be emphasized that most of the functions supplied as part of the
X\splus. system, such as {\tt mean()}, {\tt var()}, {\tt
Xpostscript()} and so on, are themselves written in \splus. and thus do
Xnot differ materially from user written functions.
X
XA function is defined by an assignment of the form
X
X\Sprompt name <- function({\sl arg$_1$\/}, {\sl arg$_2$\/}, \ldots) {\sl
Xexpression\/}
X
XThe {\tt {\sl expression\/}} is an \splus. expression, (usually a
Xgrouped expression), that uses the arguments, {\sl arg$_i$}, to calculate a
Xvalue. The value of the expression is the value returned for the function.
X
XA call to the function then usually takes the form {\tt name({\sl expr\/}$_1$, {\sl
Xexpr\/}$_2$, \ldots)} and may occur anywhere a function call is legitimate.
X
XFor example, consider a function to emulate directly the {\tt MATLAB}
Xbackslash command, which returns the coefficients of the orthogonal
Xprojection of the vector $y$ onto the column space of the matrix, $X$.
XThus given a vector $y^{n\times1}$ and a matrix $X^{n\times p}$ then
X\[
XX\backslash y =^{\rm def.} (X'X)^{-}X'y
X\]
Xwhere $(X'X)^{-}$ is a generalized inverse of $X'X$.
X\begin{verbatim}
X> bslash <- function(X, y)
X {
X X <- qr(X)
X qr.coef(X, y)
X }
X\end{verbatim}
X
XAfter this object is created it is permanent, like all objects,
Xand may be used in statements such as
X
X\Sprompt regcoeff <- bslash(Design, yvar)
X
Xand so on.
X
XThe classical \splus. function {\tt lsfit()} does this job quite well, and
Xmore. It in turn uses the functions {\tt qr()} and {\tt qr.coef()} in the
Xslightly counterintuitive way above to do this part of the calculation.
XHence there is probably some value in having just this part isolated in a
Xsimple to use function if it is going to be in frequent use. If so, we may
Xwish to make it a matrix binary operator for even more convenient use.
X
X\subsection{Defining new binary operators.}
X
XHad we given the {\tt bslash()} function a different name, namely one of
Xthe form
X\begin{center}
X{\tt \%{\sl anything\/}\%}
X\end{center}
Xit could have been used as a {\sl binary operator} in expressions rather
Xthan in function form. Suppose, for example, we choose {\tt !} for the
Xinternal character. The function definition would then start as
X
X\Sprompt "\%!\%" <- function(X, y) \lbrac \ldots\ \rbrac
X
X(Note the use of quote marks.) The function could then be used as
X{\tt X \%!\% y}. (The backslash symbol itself is not a convenient choice
Xas it presents special problems in this context.)
X
XThe matrix multiplication operator, {\tt \%*\%}, and the outer product
Xmatrix operator {\tt \%o\%} are other examples of binary operators defined
Xin this way.
X
X\subsection{Named arguments and defaults. ``\ldots''}
X
XAs first noted in \S\ref{regseq} if arguments to called functions are given
Xin the ``{\tt {\sl name\/}={\sl object}}'' form, they may be given in any
Xorder. Furthermore the argument sequence may begin in the unnamed,
Xpositional form, and specify named arguments after the positional
Xarguments.
X
XThus if there is a function {\tt fun1} defined by
X
X\Sprompt fun1 <- function(data, data.frame, graph, limit) \lbrac
X\ldots\footnote{This ellipsis is used as a customary typographical device
Xto mean an abridgement. This is not the case in the latter part of
Xsection.}\rbrac
X
XThen the function may be invoked in several ways, for example
X
X\Sprompt ans <- fun1(d, df, 20, T)
X
X\Sprompt ans <- fun1(d, df, graph=T, limit=20)
X
X\Sprompt ans <- fun1(data=d, limit=20, graph=T, data.frame=df)
X
Xare all equivalent.
X
XIn many cases arguments can be given commonly appropriate default values,
Xin which case they may be omitted altogether from the call when the
Xdefaults are appropriate. For example, if {\tt fun1} were defined as
X
X\Sprompt fun1 <- function(data, data.frame, graph=T, limit=20) \lbrac
X\ldots{\addtocounter{footnote}{-1}\footnotemark}\rbrac
X
Xit could be called as
X
X\Sprompt ans <- fun1(d, df)
X
Xwhich is now equivalent to the three cases above, or as
X
X\Sprompt ans <- fun1(d, df, limit=10)
X
Xwhich changes one of the defaults.
X
XIt is important to note that defaults may be arbitrary expressions, even
Xinvolving other arguments to the same function; they are not restricted to
Xbe constants as in our simple example here.
X
XAnother frequent requirement is to allow one function to pass on argument
Xsettings to another. For example many graphics functions use the function
X{\tt par()} and functions like {\tt plot()} allow the user to pass on
Xgraphical parameters to {\tt par()} to control the graphical output. This
Xcan be done by including an extra argument, literally ``{\tt\ldots}'', of
Xthe function, which may then be passed on. An outline example is given in
XFigure~\ref{ellipsis}.
X\begin{figure}[ht]
X\hrule\medskip
X\begin{verbatim}
Xfun1 <- function(data, data.frame, graph=T, limit=20, ...)
X{
X [omitted statements]
X
X if (graph)
X par(pch="*", ...)
X
X [more omissions]
X}
X\end{verbatim}
X\caption{\label{ellipsis} Use of the ellipsis argument, ``\ldots''}
X\medskip\hrule
X\end{figure}
XNote here that the ellipses, ``{\tt\dots}'' are literal \splus., not a
Xtypographical device.
X
X
X\subsection{Assignments within functions are local. Frames.}
X
XNote that {\sl any ordinary assignments done within the function are local
Xand temporary and lost after exit from the function}. Thus the assignment
X{\tt X <- qr(X)} does not affect the value of the argument in the calling
Xprogram.
X
XTo understand completely the rules governing the scope of \splus. assignments
Xthe reader needs to be familiar with the notion of an evaluation {\sl
Xframe}. This is a somewhat advanced, though hardly difficult, topic and is
Xnot covered further in these notes.
X
XIf global and permanent assignments are intended within a function, then
Xthe `superassignment' operator, `{\tt<<-}' can be used. See the {\tt help}
Xdocument for details, and also see the {\tt synchronize()} function.
X
X\subsection{More advanced examples}
X\subsubsection*{Efficiency factors in block designs}
XAs a more complete, if a little pedestrian, example of a function, consider
Xfinding the efficiency factors for a block design. (Some aspects of this
Xproblem have already been discussed in \S\ref{indexarrays}.)
X
XA block design is defined by two factor, say {\tt blocks} ({\tt b} levels)
Xand {\tt varieties}, ({\tt v} levels). If $R^{v\times v}$ and $K^{b\times
Xb}$ are the {\em replications\/} and {\em block size\/} matrices, and
X$N^{b\times v}$ is the incidence matrix, then the efficiency factors are
Xdefined as the eigenvalues of the matrix
X\[
XE = I_v - R^{-1/2}N'K^{-1}NR^{-1/2} = I_v - A'A
X\]
Xwhere $A = K^{-1/2}NR^{-1/2}$. One way to write the function is as in
XFigure~\ref{effic}.
X
X\begin{figure}[ht]
X\hrule\medskip
X\begin{verbatim}
X> bdeff <- function(blocks, varieties) {
X blocks <- as.factor(blocks) # minor safety move
X b <- length(levels(blocks))
X varieties <- as.factor(varieties) # minor safety move
X v <- length(levels(varieties))
X K <- as.vector(table(blocks)) # remove dim attr
X R <- as.vector(table(varieties)) # remove dim attr
X N <- table(blocks, varieties)
X A <- 1/sqrt(K) * N * rep(1/sqrt(R), rep(b, v))
X sv <- svd(A)
X list(eff=1 - sv$d^2, blockcv=sv$u, varietycv=sv$v)
X }
X\end{verbatim}
X\caption{\label{effic} A function for block design efficiencies}
X\medskip\hrule
X\end{figure}
XIt is numerically slightly better to work with the singular value
Xdecomposition on this occasion rather than the eigenvalue routines.
X
XThe result of the function is a list giving not only the efficiency factors
Xas the first component, but also the block and variety cononical contrasts,
Xsince sometimes these give additional useful qualitative information.
X
X\subsubsection*{Dropping all names in a printed array}
X
XFor printing purposes with large matrices or arrays, it is often useful to
Xprint them in close block form without the array names or numbers.
XRemoving the {\tt dimnames} attribute will not achieve this effect, but
Xrather the array must be given a {\tt dimnames} attribute consisting of
Xempty strings. For example to print a matrix, {\tt X}
X
X\Sprompt temp <- X
X
X\Sprompt dimnames(temp) <- list(rep("", nrow(X)), rep("", ncol(X))
X
X\Sprompt temp; rm(temp)
X
XThis can be much more conveniently done using a function, {\tt
Xno.dimnames()}, shown in Figure~\ref{nodimnames}, as a ``wrap around'' to
Xachieve the same result. It also illustrates how some effective and useful
Xuser functions can be quite short.
X\begin{figure}[ht]
X\hrule\medskip
X\begin{verbatim}
Xno.dimnames <- function(a){
X#
X# Remove all dimension names from an array for compact printing.
X#
X d <- list()
X l <- 0
X for(i in dim(a)) {
X d[[l <- l + 1]] <- rep("", i)
X }
X dimnames(a) <- d
X a
X}
X\end{verbatim}
X\caption{\label{nodimnames} A function for printing arrays in compact form}
X\medskip\hrule
X\end{figure}
XWith this function defined, an array may be printed in close format using
X
X\Sprompt no.dimnames(X)
X
XThis is particularly useful for large integer arrays, where patterns are
Xthe real interest rather than the values.
X
X
X\subsubsection*{Recursive numerical integration}
X
XFunctions may be recursive, and may themselves define functions within
Xthemselves. Note, however, that such functions, or indeed variables, are
Xnot inherited by called functions in higher evaluation frames as they would
Xbe if they were on the search list.
X
XThe example in Figure~\ref{recfun} shows a naive way of performing
Xone dimensional numerical integration. The integrand is evaluated at the
Xend points of the range and in the middle. If the one-panel trapezium rule
Xanswer is close enough to the two panel, then the latter is returned as the
Xvalue. Otherwise the same process is recursively applied to each panel.
XThe result is an adaptive integration process that concentrates function
Xevaluations in regions where the integrand is furtherest from linear.
XThere is, however, a heavy overhead, and the function is only competitive
Xwith other algorithms when the integrand is both smooth and very difficult
Xto evaluate.
X
XThe example is also given partly as a little puzzle in \splus. programming.
X\begin{figure}[ht]
X\hrule\medskip
X\begin{verbatim}
Xarea <- function(f, a, b, eps = 1.0e-06, lim = 10)
X{
X fun1 <- function(f, a, b, fa, fb, a0, eps, lim, fun)
X {
X d <- (a + b)/2
X h <- (b - a)/4
X fd <- f(d)
X a1 <- h * (fa + fd)
X a2 <- h * (fd + fb)
X if(abs(a0 - a1 - a2) < eps || lim == 0)
X return(a1 + a2)
X else {
X return(fun(f, a, d, fa, fd, a1, eps, lim - 1, fun) +
X fun(f, d, b, fd, fb, a2, eps, lim - 1, fun))
X }
X }
X fa <- f(a)
X fb <- f(b)
X a0 <- ((fa + fb) * (b - a))/2
X fun1(f, a, b, fa, fb, a0, eps, lim, fun1)
X}
X\end{verbatim}
X\caption{\label{recfun} A recursive function within a function}
X\medskip\hrule
X\end{figure}
X
X\subsection{Customizing the environment. {\tt .First} and {\tt .Last}}
X
XAny function named {\tt .First()} in the {\tt .Data} directory has a
Xspecial status. It is automatically performed at the beginning of an
X\splus. session and may be used to initialize the environment. For
Xexample, the definition in Figure~\ref{pointfirst} alters the prompt to
X{\tt\$} and sets up various other useful things that can then be taken for
Xgranted in the rest of the session.
X\begin{figure}[ht]
X\hrule\medskip
X\begin{verbatim}
X> .First <- function() {
X options(prompt="$ ", continue="+\t") # $ is the prompt
X options(digits=5, length=999) # custom numbers and printout
X options(gui="motif") # default graphics user interface
X tek4014() # for terminal work
X par(pch = "+") # plotting character
X attach(paste(unix("echo $HOME"), "/.Data", sep = ""))
X # Home of my personal library
X library(examples) # attach also the system examples
X }
X\end{verbatim}
X\caption{\label{pointfirst} An example of a {\tt .First()} function}
X\medskip\hrule
X\end{figure}
XSimilarly a function {\tt .Last()}, if defined, is executed at the very end
Xof the session. An example is given in Figure~\ref{pointlast}
X\begin{figure}[ht]
X\hrule\medskip
X\begin{verbatim}
X> .Last <- function() {
X graphics.off() # a small safety measure.
X cat(paste(unix("date"),"\nAdios\n")) # Is it time for lunch?
X }
X\end{verbatim}
X\caption{\label{pointlast} An example of a {\tt .Last()} function}
X\medskip\hrule
X\end{figure}
X
X\subsection{Classes, generic functions and object orientation}
X\label{oops}
XThe class of an object determines how it will be treated by what are known
Xas {\sl generic\/} functions. Put the other way round, a generic function
Xperforms a task or action on its arguments {\sl specific to the class of
Xthe argument itself}. If the argument lacks any class attribute, or has a
Xclass not catered for specifically by the generic function in question,
Xthere is always a {\sl default action\/} provided.
X
XAn example makes things clearer. In a sense the {\tt print()}
Xfunction has always been generic, since its action is to adopt a style of
Xoutput appropriate to its arguments. Thus a matrix appears as a matrix, a
Xvector as a vector, and so on. (Note that the {\tt print()} function
Xcan be called explicitly, or implicitly by giving an expression as a
Xcomplete command.)
X
XThe August~1991 release of \splus. increases the number of such functions,
Xalters the mechanism by which they are implemented and via the class
Xmechanism offers the user the facility of designing and writing generic
Xfunctions for special purposes. Among the other new, or newly generic
Xfunctions are {\tt plot()} for displaying objects graphically, {\tt
Xsummary()} for summarising analyses of various types, and {\tt anova()} for
Xcomparing statistical models.
X
XThe number of generic functions that can treat a class in a specific way
Xcan be quite large. For example, the functions that can accommodate in
Xsome fashion objects of class {\tt data.frame} include
X\[
X{\tt
X\begin{tabular}{@{\protect\strutt}*{6}{l}}
X{[}, & {[[<-}, & dbdetach, & dimnames<-, & pairs, & signif, \\
X{[<-}, & aperm, & dim, & formula, & plot, & summary, \\
X{[[}, & atan, & dimnames, & ordered<-, & print, & t,
X\end{tabular}
X}
X\]
XA currently complete list can be got by using the {\tt methods()} function:
X
X\Sprompt methods(class="data.frame")
X
XConversely the number of classes a generic function can handle can also be
Xquite large. For example the {\tt plot()} function has variants for
Xclasses of object
X\[
X{\tt
X\begin{tabular}{@{\protect\strutt}*{5}{l}}
X data.frame,& default,& glm,& pregam,& surv.fit,\\
X design,& factor,& lm,& preloess,& tree, \\
X formula,& gam,& loess,& profile,& tree.sequence,
X \end{tabular}}
X\]
Xand perhaps more. A complete list can be got again by using the {\tt
Xmethods()} function:
X
X\Sprompt methods(plot)
X
XThe reader is referred to the official references for a complete discussion
Xof this mechanism.
X}
END_OF_FILE
if test 15724 -ne `wc -c <'SplusDS/functions.tex'`; then
echo shar: \"'SplusDS/functions.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/functions.tex'
fi
if test -f 'SplusDS/graphics.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/graphics.aux'\"
else
echo shar: Extracting \"'SplusDS/graphics.aux'\" \(1833 characters\)
sed "s/^X//" >'SplusDS/graphics.aux' <<'END_OF_FILE'
X\relax
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {11}Graphical procedures}{48}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {11.1}High-level plotting commands}{48}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {11.1.1}The {\string\ptt\space plot()} function}{48}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {11.1.2}Displaying multivariate data}{49}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {11.1.3}Display graphics}{49}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {11.1.4}Arguments to high-level plotting functions}{50}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {11.2}Low-level plotting commands}{51}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {11.3}Interactive graphics functions}{52}}
X\newlabel{sec:interplot}{{11.3}{52}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {11.4}Using graphics parameters}{53}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {11.4.1}Permanent changes: the {\string\ptt\space par()} function}{53}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {11.4.2}Temporary changes: arguments to graphics functions}{54}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {11.5}Graphics parameters list}{54}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {11.5.1}Graphical elements}{54}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {11.5.2}Axes and Tick marks}{55}}
END_OF_FILE
if test 1833 -ne `wc -c <'SplusDS/graphics.aux'`; then
echo shar: \"'SplusDS/graphics.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/graphics.aux'
fi
if test -f 'SplusDS/graphics.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/graphics.tex'\"
else
echo shar: Extracting \"'SplusDS/graphics.tex'\" \(39368 characters\)
sed "s/^X//" >'SplusDS/graphics.tex' <<'END_OF_FILE'
X% -*-spluslatex-*-
X% Document name: Splus.tex
X%
X% Version 3.0, June 1992 (David Smith)
X%
X%% Master: Splus.tex
X\section{Graphical procedures}
X
XThe graphical facilities are an important and extremely versatile component
Xof the \splus. environment. Best results are obtained when \splus. is used
Xwith a high quality graphics system such as {\sf X}$-$windows, although
Xeven a simple {\sf ASCII} terminal can be quite effective for some
Xpurposes.
X
XBefore the graphical facilities of \splus. may be used, it is necessary to
Xinform \s. what type of device is being used by starting a {\em device
Xdriver}. In an {\sf X}$-$windows environment, the command to do this may be
X
X\Sprompt X11()
X
X(which creates a separate window in which high-quality graphical
Xoutput will appear,) or for a simpler graphics terminal the command
X
X\Sprompt tek4014()
X
Xmay be appropriate.
X
XOnce a device driver is running \splus. plotting commands can be used to
Xconstruct and display graphical objects. Plotting commands are divided
Xinto three basic groups:
X\begin{description}
X \item[High-level] plotting functions create a new plot on the graphics
X device, possibly with axes, labels, titles and so on.
X \item[Low-level] plotting functions add more information to an
X existing plot, such as extra points, lines and labels.
X \item[Interactive] graphics functions allow you interactively add
X information to, or extract information from, an existing plot, using a
X pointing device such as a mouse.
X\end{description}
XFurthermore, \s. maintains a list of {\em graphical parameters\/} which
Xallow you to customise your plots.
X
X\subsection{High-level plotting commands}
XHigh-level plotting functions are designed to generate a complete plot of
Xthe data passed as arguments to the function. Where appropriate, axes,
Xlabels and titles are automatically generated (unless you request
Xotherwise.) High-level plotting commands always start a new plot, erasing
Xthe current plot if necessary.
X
X\subsubsection{The {\tt plot()} function}
XOne of the most frequently used plotting functions in \s. is the {\tt
Xplot()} function. This is a {\em generic\/} function: the type of plot
Xproduced is dependent on the type or {\em class\/} of the first argument.
X
X\bigskip
X{
X% Various TeX muckings around. Dammit.
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}} \def\splus.{{\sf
XS-PLUS}} \newdimen\leftdim \leftdim=1.25truein \newdimen\rightdim
X\rightdim=\hsize \advance\rightdim by -\leftdim \advance\rightdim by -8pt
X\raggedbottom \tabskip=0pt \halign to \hsize{\vtop{\hsize=\leftdim
X\parindent=0pt\parskip=0pt \tt\obeylines\strutt#}\tabskip=50pt plus 50pt
Xminus 50pt &\vtop{\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr
X\separate
Xplot(x,y)
Xplot(xy)
X&
XIf {\tt x} and {\tt y} are vectors, {\tt plot(x,y)} produces a
Xscatterplot of {\tt x} against {\tt y}. The same effect can be
Xproduced by supplying one argument (second form) as either a list
Xcontaining two elements {\tt x} and {\tt y} or a two-column
Xmatrix.\cr
X\separate
Xplot(x)
X&
XProduces a time series plot if {\tt x} is a numeric vector or time
Xseries object, or an Argand diagram if {\tt x} is a complex vector.\cr
X\separate
Xplot(f)
Xplot(f,y)
X&
X{\tt f} is a factor object, {\tt y} is a numeric vector. The first
Xform generates a bar plot of {\tt f}; the second form produces
Xboxplots of {\tt y} for each level of {\tt f}.\cr
X\separate
Xplot(df)
Xplot(\~ expr)
Xplot(y \~ expr)
X&
X{\tt df} is a data frame, {\tt y} is any object, {\tt expr} is a list
Xof object names separated by `{\tt +}' (e.g. {\tt a + b + c}). The
Xfirst two forms produce distributional plots of the variables in a
Xdata frame (first form) or of a number of named objects (second
Xform). The third form plots {\tt y} against every object named in {\tt
Xexpr}.\cr
X\separate
X}}
X
X\subsubsection{Displaying multivariate data}
X\s. provides two very useful functions for representing multivariate
Xdata. If {\tt X} is a numeric matrix or data frame, the command
X
X\Sprompt pairs(X)
X
Xproduces a pairwise scatterplot matrix of the variables defined by the
Xcolumns of {\tt X}, i.e. every column of {\tt X} is plotted against
Xevery other column of {\tt X} and the resulting $n(n-1)$ plots are
Xarranged in a matrix with plot scales constant over the rows and
Xcolumns of the matrix.
X
XWhen three or four variables are involved a {\em coplot\/} may be more
Xenlightening. If {\tt a} and {\tt b} are numeric vectors and {\tt c}
Xis a numeric vector or factor object (all of the same length), then
Xthe command
X
X\Sprompt coplot(a \~ b | c)
X
Xproduces a number of scatterplots of {\tt a} against {\tt b} for given
Xvalues of {\tt c}. If {\tt c} is a factor, this simply means that {\tt
Xa} is plotted against {\tt b} for every level of {\tt c}. When {\tt c}
Xis numeric, it is divided into a number of {\em conditioning
Xintervals\/} and for each interval {\tt a} is plotted against {\tt b}
Xfor values of {\tt c} within the interval. The number and position of
Xintervals can be controlled with {\tt given.values=} argument to {\tt
Xcoplot()} --- the function {\tt co.intervals()} is useful for
Xselecting intervals. You can also use two ``given'' variables with a
Xcommand like
X
X\Sprompt coplot(a \~ b | c + d)
X
Xwhich produces scatterplots of {\tt a} against {\tt b} for every joint
Xconditioning interval of {\tt c} and {\tt d}.
X
XThe {\tt coplot()} and {\tt pairs()} function both take an argument
X{\tt panel=} which can be used to customise the type of plot which
Xappears in each panel. The default is {\tt points()} to produce a
Xscatterplot but by supplying some other low-level graphics function of
Xtwo vectors {\tt x} and {\tt y} as the value of {\tt panel=} you can
Xproduce any type of plot you wish. An example panel function useful
Xfor coplots is {\tt panel.smooth()}.
X
X\subsubsection{Display graphics}
X
XOther high-level graphics functions produce different types of plots.
XSome examples are:
X\bigskip{
X% Various TeX muckings around. Dammit.
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}} \def\splus.{{\sf
XS-PLUS}} \newdimen\leftdim \leftdim=1.25truein \newdimen\rightdim
X\rightdim=\hsize \advance\rightdim by -\leftdim \advance\rightdim by -8pt
X\raggedbottom \tabskip=0pt \halign to \hsize{\vtop{\hsize=\leftdim
X\parindent=0pt\parskip=0pt \tt\obeylines\strutt#}\tabskip=50pt plus 50pt
Xminus 50pt &\vtop{\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr \separate
Xtsplot(x1,x2,...)
X&
XPlots any number of time series on the same scale. This automatic
Xsimultaneous scaling feature is also useful when the {\tt x}$_i$'s are
Xordinary numeric vectors, in which case they are plotted against the
Xnumbers $1,2,3,\ldots$.
X\cr \separate
Xqqnorm(x)
Xqqplot(x,y)
X&
XDistribution-comparison plots. The first form plots the numeric vector
X{\tt x} against the expected Normal order scores (a normal scores
Xplot.) The second form plots the quantiles of {\tt x} against those of
X{\tt y} to compare their respective distributions.
X\cr \separate
Xhist(x)
Xhist(x,nclass=$n$)
Xhist(x,breaks=\ldots)
X&
XProduces a histogram of the numeric vector {\tt x}. A sensible number
Xof classes is usually chosen, but a recommendation can be given with
Xthe {\tt nclass=} argument. Alternatively, the breakpoints can be
Xspecified exactly with the {\tt breaks=} argument. If the {\tt
Xprob\-abil\-ity=T} argument is given, the bars represent relative
Xfrequencies instead of counts.
X\cr \separate
Xdotchart(x,\ldots)
X&Construct a dotchart of the data in {\tt x}. In a dotchart the $y-$axis
Xgives a labelling of the data in {\tt x} and the $x-$axis gives its value.
XFor example it allows easy visual selection of all data entries with values
Xlying in specified ranges.\cr\separate
Xpie(slices,
X\quad names,
X\quad explode=\ldots)
X&
XMake a pie diagram, including the possibility of some pieces displaced or
X``exploded'' out from the centre. (Pie diagrams are especially good for
Xshowing to administrators and bosses, but not much else, in my opinion.)\cr
X\separate
X}}
X
X\subsubsection{Arguments to high-level plotting functions}
XThere are a number of arguments which may be passed to high-level
Xgraphics functions, as follows:
X\bigskip
X{
X% Various TeX muckings around. Dammit.
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}} \def\splus.{{\sf
XS-PLUS}} \newdimen\leftdim \leftdim=1.25truein \newdimen\rightdim
X\rightdim=\hsize \advance\rightdim by -\leftdim \advance\rightdim by -8pt
X\raggedbottom \tabskip=0pt \halign to \hsize{\vtop{\hsize=\leftdim
X\parindent=0pt\parskip=0pt \tt\obeylines\strutt#}\tabskip=50pt plus 50pt
Xminus 50pt &\vtop{\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr \separate
Xadd=T
X&
XForces the function to act as a low-level graphics function,
Xsuperimposing the plot on the current plot (some functions only).
X\cr \separate
Xaxes=F
X&
XSuppresses generation of axes --- useful for adding your own custom
Xaxes with the {\tt axis()} function. The default, {\tt axes=T}, means
Xinclude axes.\cr
X\separate
Xlog="x"
Xlog="y"
Xlog="xy"
X&
XCauses the $x$, $y$ or both axes to be logarithmic. Only works for
Xscatterplots (and variants). \cr
X\separate
Xtype= & The {\tt type=} argument controls the type of plot
Xproduced, as follows: \cr
Xtype="p" & Plot individual points (the default) \cr
Xtype="l" & Plot lines \cr
Xtype="b" & Plot points connected by lines (``both'') \cr
Xtype="o" & Plot points overlaid by lines \cr
Xtype="h" & Plot vertical lines from points to the zero axis
X(``high-density'') \cr
Xtype="s"
Xtype="S" & Step-function plots. In the first form, the top of the
Xvertical defines the point; in the second, the bottom.\cr
Xtype="n" & No plotting at all. However axes are still drawn (by
Xdefault) and the coordinate system is set up according to the data.
XIdeal for creating plots with subsequent low-level graphics functions.\cr
X\separate
Xxlab="string"
Xylab="string"
X&
XAxis labels for the $x$ and $y$ axes. Use these arguments to change
Xthe default labels, usually the names of the objects used in the call
Xto the high-level plotting function. \cr
Xmain="string" & Figure title, placed at the top of the plot in a large
Xfont.\cr
Xsub="string" & Sub-title, placed just below the $x$-axis in a smaller
Xfont.\cr
X\separate
X}}
X
X\subsection{Low-level plotting commands}
XSometimes the high-level plotting functions don't produce exactly the
Xkind of plot you desire. In this case, low-level plotting commands can
Xbe used to add extra information (such as points, lines or text) to
Xthe current plot.
X
XSome of the more useful low-level plotting functions
Xare:
X\bigskip
X{
X% Various TeX muckings around. Dammit.
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}} \def\splus.{{\sf
XS-PLUS}} \newdimen\leftdim \leftdim=1.25truein \newdimen\rightdim
X\rightdim=\hsize \advance\rightdim by -\leftdim \advance\rightdim by -8pt
X\raggedbottom \tabskip=0pt \halign to \hsize{\vtop{\hsize=\leftdim
X\parindent=0pt\parskip=0pt \tt\obeylines\strutt#}\tabskip=50pt plus 50pt
Xminus 50pt &\vtop{\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr \separate
Xpoints(x,y)
Xlines(x,y)
X&
XAdds points or connected lines to the current plot. {\tt plot()}'s
X{\tt type=} argument can also be passed to these functions (and
Xdefaults to {\tt "p"} for {\tt points()} and {\tt "l"} for {\tt
Xlines()}.)
X\cr\separate
Xtext(x, y,
X\quad labels, \ldots)
X&
XAdd text to a plot at points given by {\tt x, y}. Normally {\tt labels} is
Xan integer or character vector in which case {\tt labels[i]} is plotted at
Xpoint {\tt (x[i], y[i])}. The default is {\tt 1:length(x)}.
X
XNote: This function is often used in the sequence\\
X{\tt\quad > plot(x, y, type="n"); text(x, y, names)}\\
XThe graphics parameter {\tt type="n"} suppresses the points but sets up the
Xaxes, and the {\tt text()} function supplies special characters, as
Xspecified by the character vector {\tt names} for the points.\cr
X\separate
Xabline(a, b)
Xabline(h=y)
Xabline(v=x)
Xabline({\sl lm.obj\/})
X&
XAdds a line of slope {\tt b} and intercept {\tt a} to the current plot.
X{\tt h=y} may be used to specify {\tt y}-coordinates for the heights
Xof horizontal lines to go across a plot, and {\tt v=x} similarly for
Xthe {\tt x}-coordinates for vertical lines. Also {\sl lm.obj\/} may
Xbe list with a {\tt \$coefficients} component of length 2 (such as the
Xresult of model-fitting functions,) which are taken as an intercept
Xand slope, in that order.
X\cr
X\separate
Xpolygon(x, y,
X\quad \ldots)
X&
XDraws a polygon defined by the ordered vertices in ({\tt x},{\tt y}).
X and
X(optionally) shade it in with hatch lines, or fill it if the graphics
Xdevice allows the filling of figures.\cr
X\separate
Xlegend(x,y,
X\quad legend,...)
X&
XAdds a legend to the current plot at the specified position. Plotting
Xcharacters, line styles, colours etc. are identified with the labels
Xin the character vector {\tt legend}. At least one other argument {\tt
Xv} (a vector the same length as {\tt legend}) with the corresponding
Xvalues of the plotting unit must also be given, as follows:
X\cr
Xlegend( ,angle=v) & Shading angles \cr
Xlegend( ,
X\quad density=v) & Shading densities \cr
Xlegend( ,fill=v) & Colours for filled boxes \cr
Xlegend( ,col=v) & Colours in which points or lines will be
X drawn \cr
Xlegend( ,lty=v) & Line styles \cr
Xlegend( ,pch=v) & Plotting characters (character vector) \cr
Xlegend( ,marks=v) & Plotting symbols, as obtained when using a
Xnumeric argument to {\tt pch=} (numeric vector). \cr
X\separate
Xtitle(main,sub)
X&
XAdds a title {\tt main} to the top of the current plot in a large font and
X(optionally) a sub-title {\tt sub} at the bottom in a smaller font.
X\cr \separate
Xaxis(side,...)
X&
XAdds an axis to the current plot on the side given by the first
Xargument (1 to 4, counting clockwise from the bottom.) Other arguments
Xcontrol the positioning of the axis within or beside the plot, and
Xtick positions and labels. Useful for adding custom axes after calling
X{\tt plot()} with the {\tt axes=F} argument.\cr
X\separate
X}}
X
XLow-level plotting functions usually require some positioning
Xinformation (e.g. $x$ and $y$ coordinates) to determine where to place
Xthe new plot elements. Coordinates are given in terms of {\em user
Xcoordinates\/} which are defined by the previous high-level graphics
Xcommand and are chosen based on the supplied data.
X
XWhere {\tt x} and {\tt y} arguments are required, it is also
Xsufficient to supply a single argument being a list with elements
Xnamed {\tt x} and {\tt y}. Similarly a matrix with two columns is also
Xvalid input. In this way functions such as {\tt locator()} (see below)
Xmay be used to specify positions on a plot interactively.
X
X\subsection{Interactive graphics functions}
X\label{sec:interplot}
X\s. also provides functions which allow users to extract or add
Xinformation to a plot using a mouse. The simplest of these is the {\tt
Xlocator()} function:
X\bigskip
X{
X% Various TeX muckings around. Dammit.
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}} \def\splus.{{\sf
XS-PLUS}} \newdimen\leftdim \leftdim=1.25truein \newdimen\rightdim
X\rightdim=\hsize \advance\rightdim by -\leftdim \advance\rightdim by -8pt
X\raggedbottom \tabskip=0pt \halign to \hsize{\vtop{\hsize=\leftdim
X\parindent=0pt\parskip=0pt \tt\obeylines\strutt#}\tabskip=50pt plus 50pt
Xminus 50pt &\vtop{\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr \separate
Xlocator(n,type)
X&
XWaits for the user to select locations on the current plot using the
Xleft mouse button. This continues until {\tt n} (default 500) points
Xhave been selected, or the middle mouse button is pressed. The {\tt
Xtype} argument allows for plotting at the selected points and has the
Xsame effect as for high-level graphics commands; the default is no
Xplotting. {\tt locator()} returns the locations of the points selected
Xas a list with two components {\tt x} and {\tt y}.\cr\separate}}
X
X{\tt locator()} is usually called with no arguments. It is
Xparticularly useful for interactively selecting positions for graphic
Xelements such as legends or labels when it is difficult to calculate
Xin advance where the graphic should be placed. For example, to place
Xsome informative text near an outlying point, the command
X
X\Sprompt text(locator(1), "Outlier", adj=0)
X
Xmay be useful. {\tt locator()} will still work if the current device does not
Xsupport a mouse; in this case the user will be prompted for $x$ and
X$y$ coordinates.
X
X\bigskip
X{
X% Various TeX muckings around. Dammit.
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}} \def\splus.{{\sf
XS-PLUS}} \newdimen\leftdim \leftdim=1.25truein \newdimen\rightdim
X\rightdim=\hsize \advance\rightdim by -\leftdim \advance\rightdim by -8pt
X\raggedbottom \tabskip=0pt \halign to \hsize{\vtop{\hsize=\leftdim
X\parindent=0pt\parskip=0pt \tt\obeylines\strutt#}\tabskip=50pt plus 50pt
Xminus 50pt &\vtop{\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr \separate
Xidentify(x,y,
X\quad labels)
X&
XAllow the user to highlight any of the points defined by {\tt x} and
X{\tt y} (using the left mouse button) by plotting the corresponding
Xcomponent of {\tt labels} nearby (or the index number of the point if
X{\tt labels} is absent). Returns the indices of the selected points
Xwhen the middle button is pressed.\cr\separate}}
X
XSometimes we want to identify particular {\em points\/} on a plot,
Xrather than their positions. For example, we may wish the user to
Xselect some observation of interest from a graphical display and then
Xmanipulate that observation in some way. Given a number of $(x,y)$
Xcoordinates in two numeric vectors {\tt x} and {\tt y}, we could use
Xthe {\tt identify()} function as follows:
X
X\Sprompt plot(x,y)
X
X\Sprompt identify(x,y)
X
XThe {\tt identify()} functions performs no plotting itself, but simply
Xallows the user to move the mouse pointer and click the left mouse
Xbutton near a point. The point nearest the mouse pointer will be and
Xhighlighted with its index number (i.e. its position in the {\tt
Xx}/{\tt y} vectors) plotted nearby. Alternatively, you could use some
Xinformative string (such as a case name) as a highlight by using the
X{\tt labels} argument to {\tt identify()}, or disable highlighting
Xaltogether with the {\tt plot=F} argument. When the middle button is
Xpressed, {\tt identify()} returns the indices of the selected points;
Xyou can use these indices to extract the selected points from the
Xoriginal vectors {\tt x} and {\tt y}.
X
X\subsection{Using graphics parameters}
X
XWhen creating graphics, particularly for presentation or publication
Xpurposes, \s. does not always produce exactly that which is required.
XYou can, however, customise almost every aspect of the display using
X{\em graphics parameters.\/} \s. maintains a list of a large number of
Xgraphics parameters which control things such as line style, colours,
Xfigure arrangement and text justification among many others. Every
Xgraphics parameter has a name (such as `{\tt col}', which controls
Xcolours,) and a value (a colour number, for example.)
X
XA separate list of graphics parameters is maintained for each active
Xdevice, and each device has a default set of parameters when
Xinitialised.
XGraphics parameters can be set in two ways: either permanently, affecting
Xall graphics functions which access the current device; or temporarily,
Xaffecting only a single graphics function call.
X
X\subsubsection{Permanent changes: the {\tt par()} function}
X
XThe {\tt par()} function is used to access and modify the list of
Xgraphics parameters for the current graphics device.
X
X\bigskip
X{
X% Various TeX muckings around. Dammit.
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}} \def\splus.{{\sf
XS-PLUS}} \newdimen\leftdim \leftdim=1.25truein \newdimen\rightdim
X\rightdim=\hsize \advance\rightdim by -\leftdim \advance\rightdim by -8pt
X\raggedbottom \tabskip=0pt \halign to \hsize{\vtop{\hsize=\leftdim
X\parindent=0pt\parskip=0pt \tt\obeylines\strutt#}\tabskip=50pt plus 50pt
Xminus 50pt &\vtop{\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr \separate
Xpar()
X&
XWithout arguments, returns a list of all graphics parameters and their
Xvalues for the current device. \cr
Xpar(c("col",
X\quad "lty"))
X&
XWith a character vector argument, returns only the named graphics
Xparameters (again, as a list.) \cr
Xpar(col=4,lty=2)
X&
XWith named arguments (or a single list argument) , sets the values of
Xthe named graphics parameters, and returns the original values of the
Xparameters as a list.\cr
X\separate}}
X
XSetting graphics parameters with the {\tt par()} function changes the
Xvalue of the parameters {\em permanently,} in the sense that all
Xfuture calls to graphics functions (on the current device) will be
Xaffected by the new value. You can think of setting graphics
Xparameters in this way as setting `default' values for the parameters,
Xwhich will be used by all graphics functions unless an alternative
Xvalue is given.
X
XNote that calls to {\tt par()} {\em always\/} affect the global values
Xof graphics parameters, even when {\tt par()} is called from within a
Xfunction. This is often undesirable behaviour --- usually we want to
Xset some graphics parameters, do some plotting, and then restore the
Xoriginal values so as not to affect the user's \s. session. You can
Xrestore the initial values by saving the result of {\tt par()} when
Xmaking changes, and restoring the initial values when plotting is
Xcomplete.
X
X\Sprompt oldpar <- par(col=4,lty=2)
X
X\ldots plotting commands \ldots
X
X\Sprompt par(oldpar)
X
X\subsubsection{Temporary changes: arguments to graphics functions}
X
XGraphics parameters may also be passed to (almost) any graphics
Xfunction as named arguments. This has the same effect as passing the
Xarguments to the {\tt par()} function, except that the changes only
Xlast for the duration of the function call. For example:
X
X\Sprompt plot(x,y,pch="+")
X
Xproduces a scatterplot using a plus sign as the plotting character,
Xwithout changing the default plotting character for future plots.
X
X\subsection{Graphics parameters list}
X
XThe following sections detail many of the commonly-used graphical
Xparameters. The \s. help documentation for the {\tt par()} function
Xprovides a more concise summary; this is provided as a somewhat more
Xdetailed alternative.
X
XGraphics parameters will be presented in the following form:
X\bigskip
X{
X% Various TeX muckings around. Dammit. [For parameters]
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}} \def\splus.{{\sf
XS-PLUS}} \newdimen\leftdim \leftdim=1.00truein \newdimen\rightdim
X\rightdim=\hsize \advance\rightdim by -\leftdim \advance\rightdim by -8pt
X\raggedbottom \tabskip=0pt \halign to \hsize{\vtop{\hsize=\leftdim
X\parindent=0pt\parskip=0pt \tt\obeylines\strutt#}\tabskip=50pt plus 50pt
Xminus 50pt &\vtop{\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr \separate
Xname=value
X&
XA description of the parameter's effect. {\tt name} is the name of the
Xparameter, i.e. the argument name to use in calls to {\tt par()} or a
Xgraphics function. {\tt value} is a typical value you might use when
Xsetting the parameter.\cr \separate}}
X
X\subsubsection{Graphical elements}
X
X\s. plots are made up of points, lines, text and polygons (filled
Xregions.) Graphical parameters exist which control how these {\em
Xgraphical elements\/} are drawn, as follows:
X
X\bigskip
X{
X% Various TeX muckings around. Dammit. [For parameters]
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}} \def\splus.{{\sf
XS-PLUS}} \newdimen\leftdim \leftdim=1.00truein \newdimen\rightdim
X\rightdim=\hsize \advance\rightdim by -\leftdim \advance\rightdim by -8pt
X\raggedbottom \tabskip=0pt \halign to \hsize{\vtop{\hsize=\leftdim
X\parindent=0pt\parskip=0pt \tt\obeylines\strutt#}\tabskip=50pt plus 50pt
Xminus 50pt &\vtop{\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr \separate
Xpch="+"
X&
XCharacter to be used for plotting points. The default varies with
Xgraphics drivers, but it is usually `{\tt *}' for terminals or window
Xdevices, and `$\bullet$' for {\sf {\sf PostScript}} devices. Plotted points
Xtend to appear slightly above or below the appropriate position unless
Xyou use {\tt "."} as the plotting character, which produces centred
Xpoints. \cr
Xpch=4
X&
XWhen {\tt pch} is given as an integer between 0 and 18 inclusive, a
Xspecialised plotting symbol is produced. To see what the symbols are,
Xuse the command
X
X\Sprompt legend(locator(1),as.character(0:18),marks=0:18)
X
X\cr
X\separate
Xlty=2
X&
XLine types. Alternative line styles are not supported on all graphics
Xdevices (and vary on those that do) but line type 1 is always a solid
Xline, and line types 2 and onwards are dotted or dashed lines, or some
Xcombination of both.\cr
X\separate
Xlwd=2
X&
XLine widths. Desired width of lines, in multiples of the `standard'
Xline width. Affects axis lines as well as lines drawn with {\tt lines()},
Xetc.\cr
X\separate
Xcol=2
X&
XColours to be used for points, lines, text, filled regions and images.
XEach of these graphic elements has a list of possible colours, and the
Xvalue of this parameter is an index to that list. Obviously, this
Xparameter applies only to a limited range of devices.\cr
X\separate
Xfont=2
X&
XFont to use for text. The appropriate value of this parameter is
Xdependent on the graphics device being used; for the {\tt
Xpostscript()} device this is an index to the system dataset {\tt
Xps.fonts}.\cr
X\separate
Xadj=-0.1
X&
XJustification of text relative to the plotting position. 0 means left
Xjustify, 1 means right justify and 0.5 means to centre horizontally about the
Xplotting position. The actual value is the percentage of text that
Xappears to the left of the plotting position, so a value of -0.1
Xleaves a gap of 10\%\ of the text width between the text and the
Xplotting position.\cr
X\separate
Xcex=1.5
X&
XCharacter expansion. The value is the desired size of text characters
X(including plotting characters) relative to the default text size.\cr
X\separate}}
X
X\subsubsection{Axes and Tick marks}
X
XMany of \s.'s high-level plots have axes, and you can axes yourself
Xwith the low-level {\tt axis()} graphics function. Axes have three
Xmain components: the {\em axis line\/} (line style controlled by the
X{\tt lty} graphics parameter), the {\em tick marks\/} (which mark off
Xunit divisions along the axis line) and the {\em tick labels\/} (which
Xmark the units.) These components can be customised with the following
Xgraphics parameters.
X
X\bigskip
X{
X% Various TeX muckings around. Dammit. [For parameters]
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}} \def\splus.{{\sf
XS-PLUS}} \newdimen\leftdim \leftdim=1.00truein \newdimen\rightdim
X\rightdim=\hsize \advance\rightdim by -\leftdim \advance\rightdim by -8pt
X\raggedbottom \tabskip=0pt \halign to \hsize{\vtop{\hsize=\leftdim
X\parindent=0pt\parskip=0pt \tt\obeylines\strutt#}\tabskip=50pt plus 50pt
Xminus 50pt &\vtop{\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr \separate
Xlab=c(5,7,12)
X&
XThe first two numbers are the desired number of tick intervals on the
X$x$ and $y$ axes respectively. The third number is the desired length
Xof axis labels, in characters (including the decimal point.) Choosing
Xa too-small value for this parameter may result in all tick labels
Xbeing rounded to the same number!\cr
X\separate
Xlas=1
X&
XOrientation of axis labels. 0 means always parallel to axis, 1 means
Xalways horizontal, and 2 mean always perpendicular to the axis.\cr
X\separate
Xmgp=c(3,1,0)
X&
XPositions of axis components. The first component is the distance from
Xthe axis label to the axis position, in text lines. The second
Xcomponent is the distance to the tick labels, and the final component
Xis the distance from the axis position to the axis line (usually
Xzero). Positive numbers measure outside the plot region, negative
Xnumbers inside. \cr
X\separate
Xtck=0.01
X&
XLength of tick marks, as a fraction of the size of the plotting
Xregion. When {\tt tck} is small (less than 0.5) the tick marks on the
X$x$ and $y$ axes are forced to be the same size. A value of 1 gives
Xgrid lines. Negative values give tick marks outside the plotting
Xregion. Use {\tt tck=0.01} and {\tt mgp=c(1,-1.5,0)} for internal tick
Xmarks.\cr
X\separate
Xxaxs="s"
Xyaxs="d"
X&
XAxis styles for the $x$ and $y$ axes, respectively. With styles {\tt
X"s"} (standard) and {\tt "e"} (extended) the smallest and largest tick
Xmarks always lie outside the range of the data. Extended axes may be
Xwidened slightly if any points are very near the edge. This style of
Xaxis can sometimes leave large blank gaps near the edges. With styles
X{\tt "i"} (internal) and {\tt "r"} (the default) tick marks always
Xfall within the range of the data, however style {\tt "r"} leaves a
Xsmall amount of space at the edges.
X
XSetting this parameter to {\tt "d"} (direct axis) ``locks in'' the
Xcurrent axis and uses it for all future plots (or until the parameter
Xis set to one of the other values above, at least.) Useful for
Xgenerating series of fixed-scale plots.\cr
X\separate}}
X
X\subsubsection{Figure Margins}
X
XA single plot in \s. is known as a {\tt figure} and comprises a {\em
Xplot region\/} surrounded by margins (possibly containing axis labels,
Xtitles, etc.) and (usually) bounded by the axes themselves. A typical
Xfigure appears in Figure~\ref{fig:figure}. Graphics parameters
Xcontrolling figure layout include:
X
X\begin{figure}[ht]
X \begin{center}
X \include{parfig2}
X \caption{Anatomy of an S figure}
X \label{fig:figure}
X \end{center}
X\end{figure}
X
X\bigskip
X{
X% Various TeX muckings around. Dammit. [For parameters]
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}} \def\splus.{{\sf
XS-PLUS}} \newdimen\leftdim \leftdim=1.25truein \newdimen\rightdim
X\rightdim=\hsize \advance\rightdim by -\leftdim \advance\rightdim by -8pt
X\raggedbottom \tabskip=0pt \halign to \hsize{\vtop{\hsize=\leftdim
X\parindent=0pt\parskip=0pt \tt\obeylines\strutt#}\tabskip=50pt plus 50pt
Xminus 50pt &\vtop{\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr \separate
Xmai=
X\quad c(1,0.5,0.5,0)
X&
XWidths of the bottom, left, top and right margins, respectively,
Xmeasured in inches.
X\cr
Xmar=c(4,2,2,1)
X&
XSimilar to {\tt mai}, except the measurement unit is text lines.
X\cr\separate}}
X
X{\tt mar} and {\tt mai} are equivalent in the sense that setting one
Xchanges the value of the other. The default values chosen for this
Xparameter are often too large; the right-hand margin is rarely needed,
Xand neither is the top margin if no title is being used. The bottom
Xand left margins must be large enough to accommodate the axis and tick
Xlabels. Furthermore, the default is chosen without regard to the size
Xof the device surface: for example, using the {\tt postscript()}
Xdriver with the {\tt height=4} argument will result in a plot which is
Xabout 50\%\ margin unless {\tt mar} or {\tt mai} are set explicitly.
XWhen multiple figures are in use (see below) the margins are reduced
Xby half, however this may not be enough when many figures share the
Xsame page.
X
X\subsubsection{Multiple figure environment}
X
X\s. allows you to create an $n \times m$ array of figures
Xon a single page. Each figure has its own margins, and the array of
Xfigures is optionally surrounded by an {\em outer margin\/} as shown
Xin Figure~\ref{fig:multifig}.
X
X\begin{figure}[ht]
X \begin{center}
X \include{multifig}
X \caption{Page layout in multiple figure mode}
X \label{fig:multifig}
X \end{center}
X\end{figure}
X
XThe graphical parameters relating to multiple figures are as follows:
X\bigskip
X{
X% Various TeX muckings around. Dammit. [For parameters]
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}} \def\splus.{{\sf
XS-PLUS}} \newdimen\leftdim \leftdim=1.25truein \newdimen\rightdim
X\rightdim=\hsize \advance\rightdim by -\leftdim \advance\rightdim by -8pt
X\raggedbottom \tabskip=0pt \halign to \hsize{\vtop{\hsize=\leftdim
X\parindent=0pt\parskip=0pt \tt\obeylines\strutt#}\tabskip=50pt plus 50pt
Xminus 50pt &\vtop{\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr \separate
Xmfcol=c(3,2)
Xmfrow=c(2,4)
X&
XSet size of multiple figure array. The first value is the number of
Xrows; the second is the number of columns. The only difference between
Xthese two parameters is that setting {\tt mfcol} causes figures to be
Xfilled by column; {\tt mfrow} fills by rows. The arrangement in
XFigure~\ref{fig:multifig} would have been created by setting {\tt
Xmfrow=c(3,2)}; the figure shows the page after four plots have been
Xdrawn.\cr
X\separate
Xmfg=c(2,2,3,2)
X&
XPosition of current figure in a multiple figure environment. The first
Xtwo numbers are the row and column of the current figure; the last two
Xare the number of rows and columns in the multiple figure array. Set
Xthis parameter to jump between figures in the array. You can even use
Xdifferent values for the last two numbers than the ``true'' values for
Xunequally-sized figures on the same page.\cr
X\separate
Xfig=c(4,9,1,4)/10
X&
XPosition of the current figure on the page. Values are the positions of
Xthe left, right, bottom and top edges respectively, as a
Xpercentage of the page measured from the bottom left corner. The
Xexample value would be for a figure in the bottom right of the page.
XSet this parameter for arbitrary positioning of figures within a
Xpage.\cr
X\separate
Xoma=c(2,0,3,0)
Xomi=c(0,0,0.8,0)
X&
XSize of outer margins. Like {\tt mar} and {\tt mai}, the first
Xmeasures in text lines and the second in inches, starting with the
Xbottom margin and working clockwise.\cr
X\separate}}
X
XOuter margins are particularly useful for page-wise titles, etc. Text
Xcan be added to the outer margins with the {\tt mtext()} function with
Xargument {\tt outer=T}. There are no outer margins by default,
Xhowever, so you must create them explicitly using {\tt oma} or {\tt
Xomi}.
X
X\subsection{Device drivers}
X
X\s. can generate graphics (of varying levels of quality) on almost any
Xtype of display or printing device. Before this can begin, however,
X\s. needs to be informed what type of device it is dealing with. This
Xis done by starting a {\em device driver.} The purpose of a device
Xdriver is to convert graphical instructions from \s. (`draw a line,'
Xfor example) into a form that the particular device can understand.
X
XDevice drivers are started by calling a device driver function. There
Xis one such function for every device driver: type {\tt help(Devices)}
Xfor a list of them all. For example, issuing the command
X
X\Sprompt postscript()
X
Xcauses all future graphics output to be sent to the printer in {\sf
X{\sf PostScript}} format.
XSome commonly-used device drivers are:
X
X\bigskip
X{
X% Various TeX muckings around. Dammit. [For parameters]
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}} \def\splus.{{\sf
XS-PLUS}} \newdimen\leftdim \leftdim=1.25truein \newdimen\rightdim
X\rightdim=\hsize \advance\rightdim by -\leftdim \advance\rightdim by -8pt
X\raggedbottom \tabskip=0pt \halign to \hsize{\vtop{\hsize=\leftdim
X\parindent=0pt\parskip=0pt \tt\obeylines\strutt#}\tabskip=50pt plus 50pt
Xminus 50pt &\vtop{\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr \separate
Xmotif()
Xopenlook()
XX11()
X&
XFor use with the {\sf X11} or {\sf Open Windows} window systems.\cr
Xsuntools()
X&
XFor use with the {\sf SunView} windowing system.\cr
X\separate
Xpostscript()
X&
XFor printing on {\sf PostScript} printers, or creating {\sf PostScript} graphics
Xfiles.\cr
X\separate
Xprinter()
Xcrt()
X&
XFor terminals with little or no graphics capabilities. ASCII-based
Xgraphics are generated.\cr
X\separate}}
X
XWhen you have finished with a device, be sure to terminate the device
Xdriver by issuing the command
X
X\Sprompt dev.off()
X
XThis ensures that the device finishes cleanly; for example in the case
Xof hardcopy devices this ensures that every page is completed and has
Xbeen sent to the printer.
X
X\subsubsection{{\sf PostScript} diagrams for typeset documents.}
XBy passing the {\tt file} argument to the {\tt postscript()} device
Xdriver function, you may store the graphics in {\sf PostScript} format
Xin a file of your choice. The plot will be in portrait orientation
Xunless the {\tt horizontal=T} argument is given, and you can control
Xthe size of the graphic with the {\tt width} and {\tt height}
Xarguments (the plot will be scaled as appropriate to fit these
Xdimensions.) For example, the command
X
X\Sprompt postscript("file.ps", height=4)
X
Xwill produce a file containing {\sf PostScript} code for a figure~4 inches
Xhigh, perhaps for inclusion in a document. \footnote{{\bf Warning:} The
X{\sf PostScript} code produced by the {\tt postscript()} device driver is
X{\em not\/} {\sf Encapsulated PostScript}, and thus including it in a
Xdocument electronically (as opposed to physical cut-and-paste) can be
Xrather problematic. For this type of application, a better solution is to
Xuse the {\tt fig()} driver (available from {\sf statlib}) and use a
Xconversion program (such as {\tt fig2dev} to convert the resultant {\sf
Xfig} code to {\sf Encapsulated PostScript}.} It is important to note that
Xif the file named in the command already exists, it will be overwritten.
XThis is the case even if the file was only created earlier in the same \s.
Xsession.
X
X\subsubsection{Multiple graphics devices}
X\label{multdev}
X
XIn advanced use of \s. it is often useful to have several graphics devices
Xin use at the one time. Of course only one graphics device can accept
Xgraphics commands at any one time, and this is known as the ``current
Xdevice''. When multiple devices are open, they form a numbered sequence
Xwith names giving the kind of device at any position.
X
XThe main commands used for operating with multiple devices, and their
Xmeanings are as follows:
X\bigskip
X{
X% Various TeX muckings around. Dammit.
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}}
X\newdimen\leftdim \leftdim=1.25truein
X\newdimen\rightdim \rightdim=\hsize
X\advance\rightdim by -\leftdim \advance\rightdim by -8pt
X\raggedbottom \tabskip=0pt
X\halign to \hsize{\vtop{\hsize=\leftdim
X\parindent=0pt\parskip=0pt \tt\obeylines\strutt#}\tabskip=50pt plus 50pt
Xminus 50pt &\vtop{\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr
X\separate
Xmotif()
Xpostscript()
X$\ldots$
X&
XEach new call to a device driver function opens a new graphics device,
Xthus extending by one the device list. This device becomes the current
Xdevice, to which graphics output will be sent.
X\cr
X\separate
Xdev.list()
X& returns the number and name of all active devices. The device at
Xposition 1 on the list is always the ``null device'' which does not accept
Xgraphics commands at all.
X\cr
X\separate
Xdev.next()
Xdev.prev()
X& returns the number and name of the graphics device next to, or previous
Xto the current device, respectively.
X\cr
X\separate
Xdev.set(which=k)
X& can be used to change the current graphics device to the one at position
X{\tt k} of the device list. Returns the number and label of the device.
X\cr
X\separate
Xdef.off(k)
X& Terminate the graphics device at point {\tt k} of the device list. For
Xsome devices, such as {\tt postscript} devices, this will either print the
Xfile immediately or correctly complete the file for later printing,
Xdepending on how the device was initiated.
X\cr
X\separate
Xdev.copy(device,
X\quad \ldots, which=k)
Xdev.print(device,
X\quad \ldots, which=k)
X& Make a copy of the device {\tt k}. {\tt device} is a device function,
Xsuch as {\tt postscript}, with extra arguments, if needed, specified by
X{\tt \ldots}. {\tt dev.print} is similar, but the copied device is
Ximmediately closed, so that end actions, such as printing hardcopies, are
Ximmediately performed. (See also {\tt printgraph()}).
X\cr
X\separate
Xgraphics.off()
X& Terminate all graphics devices on the list, except the null device.
X\cr
X\separate
X}}
END_OF_FILE
if test 39368 -ne `wc -c <'SplusDS/graphics.tex'`; then
echo shar: \"'SplusDS/graphics.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/graphics.tex'
fi
if test -f 'SplusDS/intro.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/intro.aux'\"
else
echo shar: Extracting \"'SplusDS/intro.aux'\" \(2171 characters\)
sed "s/^X//" >'SplusDS/intro.aux' <<'END_OF_FILE'
X\relax
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {1}Introduction and Preliminaries}{1}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.1}Reference manuals}{1}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.2}{\string\psf\space S-PLUS} and {\string\psf\space X--}windows}{1}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.3}Using {\string\psf\space S-PLUS} interactively}{2}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.4}An introductory session}{2}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.5}{\string\psf\space S-PLUS} and {\string\psf\space UNIX}}{3}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.6}Getting help with functions and features}{3}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.7}{\string\psf\space S-PLUS} commands. Case sensitivity.}{3}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.8}Recall and correction of previous commands}{4}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {1.8.1}{\string\psf\space S-PLUS}}{4}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {1.8.2}Vanilla {\string\psf\space S}}{4}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.9}Executing commands from, or diverting output to, a file}{4}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.10}Data directories. Permanency. Removing objects.}{5}}
X\global\@namedef{cp@intro}{
X\setcounter{page}{6}
X\setcounter{equation}{0}
X\setcounter{enumi}{6}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{0}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{1}
X\setcounter{subsection}{10}
X\setcounter{subsubsection}{0}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{0}
X\setcounter{table}{0}
X}
END_OF_FILE
if test 2171 -ne `wc -c <'SplusDS/intro.aux'`; then
echo shar: \"'SplusDS/intro.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/intro.aux'
fi
if test -f 'SplusDS/intro.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/intro.tex'\"
else
echo shar: Extracting \"'SplusDS/intro.tex'\" \(12995 characters\)
sed "s/^X//" >'SplusDS/intro.tex' <<'END_OF_FILE'
X% -*-latex-*-
X% Document name: Splus.tex
X%
X% Version 2.0, March, 1992
X%
X
X\section{Introduction and Preliminaries}
X\pagenumbering{arabic}
X
X\splus. is an integrated suite of software facilities for data manipulation,
Xcalculation and graphical display. Among other things it has
X
X \begin{itemize}
X \item an effective data handling and storage facility,
X \item a suite of operators for calculations on arrays, in particular
X matrices,
X \item a large, coherent, integrated collection of intermediate tools for
X data analysis,
X \item graphical facilities for data analysis and display either at a
X workstation or on hardcopy, and
X \item a well developed, simple and effective programming language which
X includes conditionals, loops, user defined recursive functions and
X input and output facilities. (Indeed most of the system supplied
X functions are themselves written in the \splus. language.)
X \end{itemize}
X
XThe term ``environment'' is intended to characterize it as a fully planned
Xand coherent system, rather than an incremental accretion of very specific
Xand inflexible tools, as is frequently the case with other data analysis
Xsoftware.
X
X\splus. is very much a vehicle for newly developing methods of interactive
Xdata analysis. As such it is very dynamic, and new releases have not
Xalways been fully upwardly compatible with previous releases. Some users
Xwelcome the changes because of the bonus of new technology and new methods
Xthat come with new releases; others seem to be more worried by the fact
Xthat old code no longer works. Although \splus. is intended as a
Xprogramming language, in my view one should regard programmes written in
X\splus. as essentially ephemeral.
X
XThe name \s. (or \splus.), as with many names within the {\sf UNIX} world,
Xis not explained, but left as a cryptic puzzle, and probably a weak pun.
XHowever its authors insist it does {\sl not\/} stand for ``Statistics''!
X
XThese notes will be mainly concerned with \splus., an enhanced version of
X\s. distributed by Statistical Sciences, Inc., Seattle, Washington.
X
X\subsection{Reference manuals}
X
XThe basic reference is {\sl The New \s. Language: A Programming Environment
Xfor Data Analysis and Graphics\/} by Richard A.~Becker, John M.~Chambers
Xand Allan R.~Wilks. The new features of the August 1991 release of \s. are
Xcovered in {\sl Statistical Models in \s.} Edited by John M.~Chambers and
XTrevor J.~Hastie. In addition there are specifically \splus. reference
Xbooks: {\sl \splus. User's Manual\/} (Volumes 1 \& 2) and {\sl \splus.
XReference Manual\/} (in two volumes, {\sl A--K} and {\sl L--Z}).
X
XIt is not the intention of these notes to replace these manuals. Rather these
Xnotes are intended as a brief introduction to the \splus. programming language
Xand a minor amplification of some important points. Ultimately the user of
X\splus. will need to consult this reference manual, probably
Xfrequently.
X
X
X\subsection{\splus. and {\sf X--}windows}
X
XThe most convenient way to use \splus. is at a high quality graphics
Xworkstation running a windowing system. Since these are becoming more
Xreadily available, these notes are aimed at users who have this facility.
XIn particular we will occasionally refer to the use of \splus. on an {\sf
XX--}window system, and even with the {\sf motif} window manager,
Xalthough the vast bulk of what is said applies generally to any
Ximplementation of the \splus. environment.
X
XSetting up a workstation to take full advantage of the customizable
Xfeatures of \splus. is a straightforward if somewhat tedious procedure, and
Xwill not be considered further here. Users in difficulty should seek local
Xexpert help.
X
X\subsection{Using \splus. interactively}
X
XWhen you use the \splus. program it issues a prompt when it expects input
Xcommands. The default prompt is ``\/{\tt>}'', which is sometimes the same
Xas the shell prompt, and so it may appear that nothing is happening.
XHowever, as we shall see, it is easy to change to a different \splus. prompt if
Xyou wish. In these notes we will assume that the shell prompt is
X``\/{\tt\$}''.
X
XIn using \splus. the suggested procedure for the first occasion is as follows:
X
X \begin{enumerate}
X \item Create a separate sub-directory, say {\tt work}, to hold data
X files on which you will use \splus. for this problem. This
X will be the working directory whenever you use \splus. for this
X particular problem.
X
X\Shell mkdir work
X
X\Shell cd work
X
X \item Place any data files you wish to use with \splus. in {\tt work}.
X
X \item Create a sub-directory of {\tt work} called {\tt .Data} for use
Xby \splus..
X
X\Shell mkdir .Data
X
X \item Start the \splus. program with the command
X
X\Shell Splus -e
X
X \item At this point \splus. commands may be issued (see later).
X
X \item To quit the \splus. program the command is
X
X\Sprompt q()
X
X\Shell
X
X \end{enumerate}
X
XThe procedure is simpler using \splus. after the first time:
X
XMake {\tt work} the working directory and start the program as before:
X
X\Shell cd work
X
X\Shell Splus -e
X
X Use the \splus. program, terminating with the {\tt q()} command at the
Xend of the session.
X
X\subsection{An introductory session}
X
XReaders wishing to get a feel for \splus. at a workstation (or terminal)
Xbefore proceeding are strongly advised to work through the model
Xintroductory session given in Appendix~\ref{intro}, starting on page~\pageref{intro}.
X
X
X\subsection{\splus. and {\sf UNIX}}
X
X\splus. allows escape to the operating system at any time in the session. If a
Xcommand, on a new line, begins with an exclamation mark then the rest of
Xthe line is interpreted as a {\sf UNIX} command. So for example to look
Xthrough a data file without leaving \splus. you could use
X
X\Sprompt !more curious.dat
X
XWhen you finish paging the file the \splus. session is resumed.
X
XIn fact the integration of \splus. into {\sf UNIX} is very complete. For
Xexample, there is a command, {\tt unix(\ldots)}, that executes any unix
Xcommand, (specified as a character string argument), and passes on any
Xoutput from the command as a character string to the program. Essentially
Xthe full power of the operating system remains easily available to the user
Xof the \splus. program during any session.
X
XThere are non-{\sf UNIX} implementations of \splus., for example for {\sf
XDOS}. Users should consult the appropriate user guides for more information.
X
X\subsection{Getting help with functions and features}
X
X\splus. has an inbuilt help facility similar to the {\tt man} facility of {\sf
XUNIX}. To get more information on any specific named function, for example
X{\tt solve} the command is
X
X\Sprompt help(solve)
X
XAn alternative is
X
X\Sprompt ?solve
X
XFor a feature specified by special characters, the argument must be
Xenclosed in double quotes, making it a `character string':
X
X\Sprompt help("[[")
X
XA much more comprehensive help facility is available with the {\sf
XX--}windows version of \splus. The command
X
X\Sprompt help.start(gui="motif")
X
Xcauses a ``help window'' to appear (with the ``motif'' graphical user
Xinterface). It is at this point possible to select items interactively
Xfrom a series of menus, and the selection process again causes other
Xwindows to appear with the help information. This may be either scanned at
Xthe screen and dismissed, or sent to a printer for hardcopy, or both.
X
X\subsection{\splus. commands. Case sensitivity.}
X
XTechnically \splus. is a {\sl function language\/} with a very simple syntax.
XIt is {\sl case sensitive\/} as are most {\sf UNIX} based packages, so {\tt
XA} and {\tt a} are different variables.
X
XElementary commands consist of either {\sl expressions\/} or {\sl
Xassignments\/}. If an expression is given as a command, it is evaluated,
Xprinted, and the value is lost. An assignment also evaluates an expression
Xand passes the value to a variable but the result is not printed
Xautomatically.
X
XCommands are separated either by a semi-colon, {\tt ;}, or by a newline.
XIf a command is not complete at the end of a line, \splus. will give a
Xdifferent prompt, for example
X
X\Contd \
X
Xon second and subsequent lines and continue to read input until the command
Xis syntactically complete. This prompt may also be changed if the user
Xwishes. In these notes we will generally omit the continuation prompt and
Xindicate continuation by simple indenting.
X
X\subsection{Recall and correction of previous commands}
X
X\subsubsection{\splus.}
X\splus. (but not plain \s.) provides a mechanism for recall and correction
Xof previous commands. For interactive use this is a vital facility and
Xgreatly increases the productive output of most people. To invoke \splus.
Xwith the command recall facility enabled use the {\tt -e} flag:
X
X\Sprompt Splus -e
X
XWithin the session, command recall is available using either {\sf
Xemacs}-style or {\sf vi}-style commands. The former is very similar to
Xcommand recall with an interactive shell such as {\sf tcsh}. Details are
Xgiven in Appendix~\ref{cleditor} of these notes, or they may be found in
Xthe reference manual or the online help documents.
X
X\subsubsection{Vanilla \s.}
XWith \s. no built-in mechanism is available, but there are two common ways
Xof obtaining command recall for interactive sessions.
X
X\begin{itemize}
X\item Run the \s. session under {\sf emacs} using {\sf S--}mode, a major
Xmode designed to support \s.. This is probably more convenient than even
Xthe inbuilt editor of \splus. in the long term, however it does require a
Xgood deal of preliminary effort for persons not familiar with the {\sf
Xemacs} editor. It also often requires a dedicated workstation with a good
Xdeal of memory and other resources.
X
X\item Run the \s. session under some front end processor, such as the
Xpublic domain {\sf fep} program, available from the public sources
Xarchives. This provides essentially the same service as the inbuilt
X\splus. editor, but with somewhat more overhead, (but a great deal less
Xoverhead than {\sf emacs} requires.)
X
X\end{itemize}
X
X\subsection{Executing commands from, or diverting output to, a file}
X
XIf commands are stored on an external file, say {\tt commands.S} in the
Xworking directory {\tt work}, they may be executed at any time in an
X\splus. session with the command
X
X\Sprompt source("commands.S")
X
XSimilarly
X
X\Sprompt sink("record.lis")
X
Xwill divert all subsequent output from the terminal to an external
Xfile, {\tt record.lis}. The command
X
X\Sprompt sink()
X
Xrestores it to the terminal once again.
X
X\subsection{Data directories. Permanency. Removing objects.}
X
XAll objects created during your \splus. sessions are stored, in a special form,
Xin the {\tt .Data} sub-directory of your working directory {\tt work}, say.
X
XEach object is held as a separate file of the same name and so may be
Xmanipulated by the usual {\sf UNIX} commands such as {\tt rm}, {\tt cp} and
X{\tt mv}. This means that if you resume your \splus. session at a later time,
Xobjects created in previous sessions are still available, which is a highly
Xconvenient feature.
X
XThis also explains why it is recommended that you should use separate
Xworking directories for different jobs. Common names for objects are
Xsingle letter names like {\tt x}, {\tt y} and so on, and if two problems
Xshare the same {\tt .Data} sub-directory the objects will become mixed up
Xand you may overwrite one with another.
X
XThere is, however, another method of partitioning variables within the same
X{\tt .Data} directory using {\sl data frames\/}. These are discussed
Xfurther in \S\ref{dataframes}.
X
XIn \splus., to get a list of names of the objects currently defined use the
Xcommand
X
X\Sprompt objects()
X
Xwhose result is a vector of character strings giving the names.
X
XWhen \splus. looks for an object, it searches in turn through a sequence of
Xplaces known as the {\sl search list}. Usually the first entry in the
Xsearch list is the {\tt .Data} sub-directory of the current working
Xdirectory. The names of the places currently on the search list are
Xdisplayed by the function
X
X\Sprompt search()
X
XThe names of the objects held in any place in the search list can be
Xdisplayed by giving the {\tt objects()} function an argument. For example
X
X\Sprompt objects(2)
X
Xlists the contents of the entity at position 2 of the search list. The
Xsearch list can contain either data frames and allies, which are themselves
Xinternal \splus. objects, as well as directories of files which are {\sf
XUNIX} objects.
X
XExtra entities can be added to this list with the {\tt attach()} function
Xand removed with the {\tt detach()} function, details of which can be found
Xin the manual or the {\tt help} facility.
X
XTo remove objects permanently the function {\tt rm} is available:
X
X\Sprompt rm(x, y, z, ink, junk, temp, foo, bar)
X
XThe function {\tt remove()} can be used to remove objects
Xwith non-stan\-dard names. Also the ordinary {\sf UNIX} facility, {\tt
Xrm}, may be used to remove the appropriate files in the {\tt .Data}
Xdirectory, as mentioned above.
X
X
END_OF_FILE
if test 12995 -ne `wc -c <'SplusDS/intro.tex'`; then
echo shar: \"'SplusDS/intro.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/intro.tex'
fi
if test -f 'SplusDS/lists.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/lists.aux'\"
else
echo shar: Extracting \"'SplusDS/lists.aux'\" \(2175 characters\)
sed "s/^X//" >'SplusDS/lists.aux' <<'END_OF_FILE'
X\relax
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {6}Lists, data frames, and their uses}{23}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {6.1}Lists}{23}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {6.2}Constructing and modifying lists}{23}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {6.2.1}Concatenating lists}{24}}
X\newlabel{cwithlists}{{6.2.1}{24}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {6.3}Some functions returning a list result}{24}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {6.3.1}Eigenvalues and eigenvectors}{24}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {6.3.2}Singular value decomposition and determinants}{24}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {6.3.3}Least squares fitting and the $QR$ decomposition}{25}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {6.4}Data frames}{25}}
X\newlabel{dataframes}{{6.4}{25}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {6.4.1}Making data frames}{26}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {6.4.2}{\string\ptt\space attach()} and {\string\ptt\space detach()}}{26}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {6.4.3}Working with data frames}{26}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {6.4.4}Attaching arbitrary lists}{27}}
X\newlabel{atlist}{{6.4.4}{27}}
X\global\@namedef{cp@lists}{
X\setcounter{page}{28}
X\setcounter{equation}{0}
X\setcounter{enumi}{6}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{6}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{6}
X\setcounter{subsection}{4}
X\setcounter{subsubsection}{4}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{1}
X\setcounter{table}{0}
X}
END_OF_FILE
if test 2175 -ne `wc -c <'SplusDS/lists.aux'`; then
echo shar: \"'SplusDS/lists.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/lists.aux'
fi
if test -f 'SplusDS/lists.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/lists.tex'\"
else
echo shar: Extracting \"'SplusDS/lists.tex'\" \(12783 characters\)
sed "s/^X//" >'SplusDS/lists.tex' <<'END_OF_FILE'
X% -*-latex-*-
X% Document name: Splus.tex
X%
X% Version 2.0, March, 1992
X%
X\section{Lists, data frames, and their uses}
X
X\subsection{Lists}
X
XAn \splus. {\sl list} is an object consisting of an ordered collection of
Xobjects known as its {\sl components}.
X
XThere is no particular need for the components to be of the same mode or
Xtype, and, for example, a list could consist of a numeric vector, a logical
Xvalue, a matrix, a complex vector, a character array, a function, and so
Xon.
X
XComponents are always {\sl numbered\/} and may always be referred to as
Xsuch. Thus if {\tt St} is the name of a list with four components, these
Xmay be individually referred to as {\tt St[[1]]}, {\tt St[[2]]}, {\tt
XSt[[3]]} and {\tt St[[4]]}. If, further, {\tt St[[3]]} is a triply
Xsubscripted array then {\tt St[[3]][1,1,1]} is its first entry and {\tt
Xdim(St[[3]])} is its dimension vector, and so on.
X
XIf {\tt St} is a list, then the function {\tt length(St)} gives the number
Xof (top level) components it has.
X
XComponents of lists may also be {\sl named}, and in this case the component
Xmay be referred to either by giving the component name as a character
Xstring in place of the number in double square brackets, or, more
Xconveniently, by giving an expression of the form
X
X\Sprompt {\sl name\/}\${\sl component\_name}
X
Xfor the same thing.
X
XThis is a very useful convention as it makes it easier to get the right
Xcomponent if you forget the number. So if the components of {\tt St} above
Xhad been named, and the names were {\tt x}, {\tt y}, {\tt coefficients} and
X{\tt covariance} they could be referred to as {\tt St\$y}, {\tt
XSt\$covariance} and so on, (or indeed as {\tt St[["y"]]}, {\tt
XSt[["covariance"]]} \ldots{} but this form is rarely if ever needed).
X
XIt is very important to distinguish {\tt St[[1]]} from {\tt St[1]}.
X``{\tt[[\ldots]]}'' is the operator used to select a single element,
Xwhereas ``{\tt[\ldots]}'' is a general subscripting operator. Thus the
Xformer is the {\sl first object in the list} {\tt St}, and if it is a named
Xlist the name is {\sl not\/} included. The latter is a {\sl sublist of the
Xlist {\tt St} consisting of the first entry only. If it is a named list,
Xthe name is transferred to the sublist.}
X
XThe names of components may be abbreviated down to the minimum number of
Xletters needed to identify them uniquely. Thus {\tt St\$coefficients} may
Xbe minimally specified as {\tt St\$coe} and {\tt St\$covariance} as {\tt
XSt\$cov}.
X
XThe vector of names is in fact simply an attribute of the list like any
Xother and may be handled as such. Other structures besides lists may, of
Xcourse, similarly be given a {\sl names\/} attribute also.
X
X
X\subsection{Constructing and modifying lists}
X
XNew lists may be formed from existing objects by the function {\tt
Xlist()}. An assignment of the form
X
X\Sprompt St <- list({\sl name\/}$_1$={\sl object\/}$_1$, {\sl
Xname\/}$_2$={\sl object\/$_2$}, \ldots,{\sl name\/}$_m$={\sl object\/}$_m$)
X
Xsets up a list {\tt St} of $m$ components using {\tt {\sl
Xcomp\/}$_1$}, \ldots, {\tt {\sl comp\/}$_m$} for the components and giving
Xthem names as specified by the argument names, (which can be freely
Xchosen). If these names are omitted, the components are numbered only.
XThe components used to form the list are {\sl copied} when forming the new
Xlist and the originals are not affected.
X
XLists, like any subscripted object, can be extended by specifying
Xadditional components. For example
X
X\Sprompt St[5] <- list(matrix=Mat)
X
X\subsubsection{Concatenating lists}
X\label{cwithlists}
X
XWhen the concatenation function {\tt c()} is given list arguments, the
Xresult is an object of mode list also, whose components are those of the
Xargument lists joined together in sequence.
X
X\Sprompt list.ABC <- c(list.A, list.B, list.C)
X
XRecall that with vector objects as arguments the concatenation function
Xsimilarly joined together all arguments into a single vector structure. In
Xthis case all other attributes, such as {\tt dim} attributes, are
Xdiscarded.
X
X\subsection{Some functions returning a list result}
XFunctions and expressions in \splus. must return a single object as their
Xresult; in cases where the result has several component parts, the usual
Xform is that of a list with named components.
X
X\subsubsection{Eigenvalues and eigenvectors}
X
XThe function {\tt eigen(Sm)} calculates the eigenvalues and eigenvectors of
Xa symmetric matrix {\tt Sm}. The result of this function is a list of two
Xcomponents named {\tt values} and {\tt vectors}. The assignment
X
X\Sprompt ev <- eigen(Sm)
X
Xwill assign this list to {\tt ev}. Then {\tt ev\$val} is the vector of
Xeigenvalues of {\tt Sm} and {\tt ev\$vec} is the matrix of corresponding
Xeigenvectors. Had we only needed the eigenvalues we could have used the
Xassignment:
X
X\Sprompt evals <- eigen(Sm)\$values
X
X\noindent{\tt evals} now holds the vector of eigenvalues and the second
Xcomponent is discarded. If the expression
X
X\Sprompt eigen(Sm)
X
Xis used by itself as a command the two components are printed, with
Xtheir names, at the terminal.
X
X\subsubsection{Singular value decomposition and determinants}
X
XThe function {\tt svd(M)} takes an arbitrary matrix argument, {\tt M}, and
Xcalculates the singular value decomposition of {\tt M}. This consists of a
Xmatrix of orthonormal columns {\tt U} with the same column space as {\tt
XM}, a second matrix of orthonormal columns {\tt V} whose column space is
Xthe row space of {\tt M} and a diagonal matrix of positive entries {\tt D}
Xsuch that {\tt M = U \%*\% D \%*\% t(V)}. {\tt D} is actually returned as
Xa vector of the diagonal elements. The result of {\tt svd(M)} is actually
Xa list of three components named {\tt d}, {\tt u} and {\tt v}, with evident
Xmeanings.
X
XIf {\tt M} is in fact square, then, it is not hard to see that
X
X\Sprompt absdetM <- prod(svd(M)\$d)
X
Xcalculates the absolute value of the determinant of {\tt M}. If this
Xcalculation were needed often with a variety of matrices it could be
Xdefined as an \splus. function
X
X\Sprompt absdet <- function(M) prod(svd(M)\$d)
X
Xafter which we could use {\tt absdet()} as just another \splus. function.
XAs a further trivial but potentially useful example, you might like to
Xconsider writing a function, say {\tt tr()}, to calculate the trace
Xof a square matrix. [Hint: You will not need to use an explicit loop.
XLook again at the {\tt diag()} function.]
X
XFunctions will be discussed formally later in these notes.
X
X\subsubsection{Least squares fitting and the $QR$ decomposition}
X
XThe function {\tt lsfit()} returns a list giving results of a least
Xsquares fitting procedure. An assignment such as
X
X\Sprompt ans <- lsfit(X, y)
X
Xgives the results of a least squares fit where {\tt y} is the vector of
Xobservations and {\tt X} is the design matrix. See the help facility for
Xmore details, and also for the follow-up function {\tt ls.diag()} for,
Xamong other things, regression diagnostics. Note that a grand mean term is
Xautomatically included and need not be included explicitly as a column of
X{\tt X}.
X
XAnother closely related function is {\tt qr()} and its allies.
XConsider the following assignments
X
X\Sprompt Xplus <- qr(X)
X
X\Sprompt b <- qr.coef(Xplus, y)
X
X\Sprompt fit <- qr.fitted(Xplus, y)
X
X\Sprompt res <- qr.resid(Xplus, y)
X
XThese compute the orthogonal projection of {\tt y} onto the range of
X{\tt X} in {\tt fit}, the projection onto the orthogonal complement in {\tt
Xres} and the coefficient vector for the projection in {\tt b}, that is,
X{\tt b} is essentially the result of the {\tt MATLAB} `backslash' operator.
X
XIt is not assumed that {\tt X} has full column rank. Redundancies will be
Xdiscovered and removed as they are found.
X
XThis alternative is the older, low level way to perform least squares
Xcalculations. Although still useful in some contexts, it would now
Xgenerally be replaced by the statistical models features, as will be
Xdiscussed in \S\ref{models}.
X
X
X\subsection{Data frames}
X\label{dataframes}
XA {\sl data frame\/} is a list with class {\tt data.frame}. There are
Xrestrictions on lists that may be made into data frames, namely
X\begin{itemize}
X\item The components must be vectors (numeric, character, or logical),
Xfactors, numeric matrices, lists, or other data frames.
X
X\item Matrices, lists, and data frames provide as many variables to the
Xnew data frame as they have columns, elements, or variables, respectively.
X
X\item Numeric vectors and factors are included as is, and non-numeric
Xvectors are coerced to be factors, whose levels are the unique values
Xappearing in the vector.
X
X\item Vector structures appearing as variables of the data frame must all
Xhave the {\sl same length}, and matrix structures must all have the same
X{\sl row size}.
X\end{itemize}
X
XData frames may in many ways be regarded as a matrix with columns possibly
Xof differing modes and attributes. It may be displayed in matrix form, and
Xits rows and columns extracted using matrix indexing conventions.
X
X\subsubsection{Making data frames}
X
XObjects satisfying the restrictions placed on the columns (components) of a
Xdata frame may be used to form one using the function {\tt data.frame}:
X
X\Sprompt accountants <- data.frame(home=statef,loot=income, shot=incomef)
X
XA list whose components conform to the restrictions of a data frame may be
X{\sl coerced\/} into a data frame using the function {\tt as.data.frame()}
X
XThe simplest way to construct a data frame from scratch is to use the {\tt
Xread.table()} function to read an entire data frame from an external
Xfile. This is discussed further in \S\ref{reading}.
X
X\subsubsection{{\tt attach()} and {\tt detach()}}
X
XThe {\tt\$} notation, such as {\tt accountants\$statef}, for list components
Xis not always very convenient. A useful facility would be somehow to make
Xthe components of a list or data frame temporarily visible as variables
Xunder their component name, without the need to quote the list name
Xexplicitly each time.
X
XThe {\tt attach()} function, as well as having a directory name as
Xits argument, may also have a data frame. Thus suppose {\tt lentils} is a
Xdata frame with three variables {\tt lentils\$u}, {\tt lentils\$v}, {\tt
Xlentils\$w}. The attach
X
X\Sprompt attach(lentils)
X
Xplaces the data frame in the search list at position~2, and provided there
Xare no variables {\tt u}, {\tt v} or {\tt w} in position~1, {\tt u}, {\tt
Xv} and {\tt w} are available as variables from the data frame in their own
Xright. At this point an assignment such as
X
X\Sprompt u <- v+w
X
Xdoes not replace the component {\tt u} of the data frame, but rather masks
Xit with another variable {\tt u} in the working directory at position~1 on
Xthe search list. To make a permanent change to the data frame itself, the
Xsimplest way is to resort once again to the {\tt\$} notation:
X
X\Sprompt lentils\$u <- v+w
X
XHowever the new value of component {\tt u} is not visible until the data
Xframe is detached and attached again.
X
XTo detach a data frame, use the function
X
X\Sprompt detach()
X
XMore precisely, this statement detaches from the search list the entity
Xcurrently at position~2. Thus in the present context the variables {\tt
Xu}, {\tt v} and {\tt w} would be no longer visible, except under the list
Xnotation as {\tt lentils\$u} and so on.
X
X\subsubsection{Working with data frames}
X
XA useful convention that allows you to work with many different problems
Xcomfortably together in the same working directory is
X\begin{itemize}
X\item gather together all variables for any well defined and separate
Xproblem in a data frame under a suitably informative name;
X
X\item when working with a problem attach the appropriate data frame at
Xposition~2, and use the working directory at level~1 for operational
Xquantities and temporary variables;
X
X\item before leaving a problem, add any variables you wish to keep for
Xfuture reference to the data frame using the {\tt\$} form of assignment,
Xand then {\tt detach()};
X
X\item finally remove all unwanted variables from the working directory and
Xkeep it a clean of left-over temporary variables as possible.
X\end{itemize}
X
XIn this way it is quite simple to work with many problems in the same
Xdirectory, all of which have variables named {\tt x}, {\tt y} and {\tt z},
Xfor example.
X
X\subsubsection{Attaching arbitrary lists}
X\label{atlist}
X
X{\tt attach()} is a generic function that allows not only directories and
Xdata frames to be attached to the search list, but other classes of object
Xas well. In particular any object of mode {\tt list} may be attached in
Xthe same way:
X
X\Sprompt attach(any.old.list)
X
XIt is also possible to attach objects of class {\tt pframe}, to so-called
X{\em parametrized data frames}, needed for nonlinear regression and
Xelsewhere.
X
XBeing a generic function it is also possible to add methods for attaching
Xyet more classes of object should the need arise.
END_OF_FILE
if test 12783 -ne `wc -c <'SplusDS/lists.tex'`; then
echo shar: \"'SplusDS/lists.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/lists.tex'
fi
if test -f 'SplusDS/loops.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/loops.aux'\"
else
echo shar: Extracting \"'SplusDS/loops.aux'\" \(828 characters\)
sed "s/^X//" >'SplusDS/loops.aux' <<'END_OF_FILE'
X\relax
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {8}More language features. Loops and conditional execution}{30}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.1}Grouped expressions}{30}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.2}Control statements}{30}}
X\newlabel{loops}{{8.2}{30}}
X\global\@namedef{cp@loops}{
X\setcounter{page}{31}
X\setcounter{equation}{0}
X\setcounter{enumi}{6}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{6}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{8}
X\setcounter{subsection}{2}
X\setcounter{subsubsection}{0}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{3}
X\setcounter{table}{0}
X}
END_OF_FILE
if test 828 -ne `wc -c <'SplusDS/loops.aux'`; then
echo shar: \"'SplusDS/loops.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/loops.aux'
fi
if test -f 'SplusDS/loops.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/loops.tex'\"
else
echo shar: Extracting \"'SplusDS/loops.tex'\" \(2893 characters\)
sed "s/^X//" >'SplusDS/loops.tex' <<'END_OF_FILE'
X% -*-latex-*-
X% Document name: Splus.tex
X%
X% Version 2.0, March, 1992
X%
X
X\section{More language features. Loops and conditional execution}
X
X\subsection{Grouped expressions}
X
X\splus. is an expression language in the sense that its only command type is a
Xfunction or expression which returns a result. Even an assignment is an
Xexpression whose result is the value assigned, and it may be used wherever
Xany expression may be used; in particular multiple assignments are
Xpossible.
X
XCommands may be grouped together in braces, {\tt\char'173{}expr$_1$;
Xexpr$_2$;\ldots; expr$_m$\char'175}, in which case the value of the group is
Xthe result of the last expression in the group evaluated. Since such a
Xgroup is also an expression it may, for example, be itself included in
Xparentheses and used a part of an even larger expression, and so on.
X
X\subsection{Control statements}
X\label{loops}
XThe language has available a conditional construction of the form
X
X\Sprompt if ({\sl expr$_1$\/}) {\sl expr$_2$\/} else {\sl expr$_3$\/}
X
Xwhere {\sl expr$_1$\/} must evaluate to a logical value and the
Xresult of the entire expression is then evident.
X
XThere is also a {\tt for}--loop construction which has the form
X
X\Sprompt for ({\tt {\sl name\/}} in {\sl expr$_1$\/}) {\sl expr$_2$\/}
X
Xwhere {\tt {\sl name\/}} is the loop variable. {\tt expr$_1$} is a vector
Xexpression, (often a sequence like {\tt 1:20}), and {\tt expr$_2$} is often
Xa grouped expression with its sub-expressions written in terms of the dummy
X{\sl name\/}. {\tt expr$_2$} is repeatedly evaluated as {\sl name} ranges
Xthrough the values in the vector result of {\tt expr$_1$}.
X
XAs an example, suppose {\tt ind} is a vector of class indicators and we
Xwish to produce separate plots of {\tt y} versus {\tt x} within classes.
XOne possibility here is to use {\tt coplot()} to be discussed later, which
Xwill produce an array of plots corresponding to each level of the factor.
XAnother way to do this, now putting all plots on the one display, is as
Xfollows:
X
X\Sprompt yc <- split(y, ind); xc <- split(x, ind)
X
X\Sprompt for (i in 1:length(yc)){\char'173}plot(xc[[i]], yc[[i]]);
X
X\Contd abline(lsfit(xc[[i]], yc[[i]]))\char'175
X
X(Note the function {\tt split()} which produces a list of vectors got by
Xsplitting a larger vector according to the classes specified by a category.
XThis is a useful function, mostly used in connection with boxplots. See
Xthe {\tt help} facility for further details.)
X
XOther looping facilities include the
X
X\Sprompt repeat {\sl expr\/}
X
Xstatement and the
X
X\Sprompt while ({\sl condition\/}) {\sl expr\/}
X
Xstatement. The {\tt break} statement can be used to terminate any
Xloop abnormally, and {\tt next} can be used to discontinue one particular
Xcycle.
X
XControl statements are most often used in connection with {\sl functions\/}
Xwhich are discussed in \S\ref{functions}, and where more examples will
Xemerge.
END_OF_FILE
if test 2893 -ne `wc -c <'SplusDS/loops.tex'`; then
echo shar: \"'SplusDS/loops.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/loops.tex'
fi
if test -f 'SplusDS/macros.el' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/macros.el'\"
else
echo shar: Extracting \"'SplusDS/macros.el'\" \(372 characters\)
sed "s/^X//" >'SplusDS/macros.el' <<'END_OF_FILE'
X(fset 'comp
X "xsave-some-buf
xcompile
latex Splus
b*compilation*
1>")
X
X(fset 'look
X "xshell
<xdvi Splus &
Splus.tex
<includeonly")
X
X(fset 'xdvi
X "xshell
<xdvi Splus &
Splus.tex
<includeonly")
X
X(fset 'co
X "xsave-some-buf
xcompile
latex Splus
b*compilation*
1>")
X
X(fset 'lo
X "xshell
<xdvi Splus &
Splus.tex
<includeonly")
END_OF_FILE
echo shar: 38 control characters may be missing from \"'SplusDS/macros.el'\"
if test 372 -ne `wc -c <'SplusDS/macros.el'`; then
echo shar: \"'SplusDS/macros.el'\" unpacked with wrong size!
fi
# end of 'SplusDS/macros.el'
fi
if test -f 'SplusDS/models.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/models.aux'\"
else
echo shar: Extracting \"'SplusDS/models.aux'\" \(3051 characters\)
sed "s/^X//" >'SplusDS/models.aux' <<'END_OF_FILE'
X\relax
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {10}Statistical models in {\string\psf\space S-PLUS}}{37}}
X\newlabel{models}{{10}{37}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {10.1}Defining statistical models; formul\ae }{37}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {10.2}Regression models; fitted model objects}{38}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {1}{\ignorespaces Summary of model operator semantics}}{39}}
X\newlabel{operators}{{1}{39}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {10.3}Generic functions for extracting information}{39}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {10.4}Analysis of variance; comparing models}{39}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {2}{\ignorespaces Commonly used generic functions on class {\string\ptt\space lm} objects}}{40}}
X\newlabel{generic}{{2}{40}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {10.4.1}ANOVA tables}{40}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {10.5}Updating fitted models. The ditto name ``{\string\ptt\space .}''}{41}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {10.6}Generalized linear models; families}{41}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {10.6.1}Families}{42}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {10.6.2}The {\string\ptt\space glm()} function}{42}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {3}{\ignorespaces Families and the link functions available to them}}{43}}
X\newlabel{links}{{3}{43}}
X\@writefile{lot}{\string\contentsline\space {table}{\string\numberline\space {4}{\ignorespaces The Kalythos blindness data}}{44}}
X\newlabel{blind}{{4}{44}}
X\newlabel{storm}{{1}{45}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {10.7}Nonlinear regression models; parametrized data frames}{45}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {10.7.1}Changes to the form of the model formula}{45}}
X\@writefile{toc}{\string\contentsline\space {subsubsection}{\string\numberline\space {10.7.2}Specifying the parameters}{46}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {10.8}Some non-standard models}{47}}
X\global\@namedef{cp@models}{
X\setcounter{page}{48}
X\setcounter{equation}{1}
X\setcounter{enumi}{6}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{7}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{10}
X\setcounter{subsection}{8}
X\setcounter{subsubsection}{0}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{9}
X\setcounter{table}{4}
X}
END_OF_FILE
if test 3051 -ne `wc -c <'SplusDS/models.aux'`; then
echo shar: \"'SplusDS/models.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/models.aux'
fi
if test -f 'SplusDS/models.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/models.tex'\"
else
echo shar: Extracting \"'SplusDS/models.tex'\" \(32072 characters\)
sed "s/^X//" >'SplusDS/models.tex' <<'END_OF_FILE'
X% -*-latex-*-
X% Document name: Splus.tex
X%
X% Version 2.0, March, 1992
X%
X\def\strutt{\vrule height 3ex depth 1ex width 0em}
X
X
X\section{Statistical models in \splus.}
X\label{models}
XThis section presumes the reader has some familiarity with statistical
Xmethodology, in particular with regression analysis and the analysis of
Xvariance. Later we make some rather more ambitious presumptions, namely
Xthat something is known about generalized linear models and nonlinear
Xregression.
X
XThe requirements for fitting statistical models are sufficiently well
Xdefined to make it possible to construct general tools that apply in a
Xbroad spectrum of problems. Since the August~1991 release \splus. provides
Xan interlocking suite of facilities that make fitting statistical models
Xvery simple. However these are not at the same high level as those in,
Xsay, {\sf Genstat}, especially in the form of the output which in keeping
Xwith general \splus. policy is rather minimal.
X
X\subsection{Defining statistical models; formul\ae}
XThe template for a statistical model is a linear regression model with
Xindependent, homoscedastic errors
X\[
Xy_i = \sum_{j=0}^p\beta_jx_{ij} + e_i,\qquad e_i\sim{\rm NID}(0,\sigma^2),\qquad
Xi = 1,2,\ldots,n
X\]
XIn matrix terms this would be written
X\[
X{\bmit y} = {\bf X}{\bmit\beta} + {\bmit e}
X\]
Xwhere the ${\bmit y}$ is the response vector, ${\bf X}$ is the {\sl model
Xmatrix\/} or {\sl design matrix\/} and has columns ${\bmit x}_0$, ${\bmit
Xx}_1$, $\ldots$, ${\bmit x}_p$, the determining variables. Very often
X${\bmit x}_0$ will be a column of 1s defining an {\sl intercept\/} term.
X
X
X{\small
X{\bf Examples.}
X
XBefore giving a formal specification, a few examples may usefully set the
Xpicture.
X
XSuppose {\tt y}, {\tt x}, {\tt x0}, {\tt x1}, {\tt x2}, \ldots{} are
Xnumeric variables, {\tt X is a matrix} and {\tt A}, {\tt B}, {\tt C},
X\ldots{} are factors. The following formul\ae{} on the left side below
Xspecify statistical models as described on the right.
X
X{
X% Various TeX muckings around. Dammit.
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}}
X\def\splus.{{\sf S-PLUS}}
X\newdimen\leftdim
X\leftdim=1.25truein
X\newdimen\rightdim
X\rightdim=\hsize
X\advance\rightdim by -\leftdim
X\advance\rightdim by -8pt
X\raggedbottom
X\tabskip=0pt
X\halign to \hsize{\vtop{\hsize=\leftdim \parindent=0pt\parskip=0pt
X\tt\obeylines\strutt#}\tabskip=50pt plus 50pt minus 50pt
X&\vtop{\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr
X\separate
Xy \~ x
Xy \~ 1 + x
X&
XBoth imply the same simple linear regression model of $y$ on $x$. The
Xfirst has an implicit intercept term, and the second an explicit one.
X\cr
X\separate
Xy \~ -1 + x
Xy \~ x - 1
X&
XSimple linear regression of $y$ on $x$ through the origin, (that is,
Xwithout an intercept term).
X\cr
X\separate
Xlog(y) \~ x1 + x2
X&
XMultiple regression of the transformed variable, $\log(y)$, on $x_1$ and
X$x_2$ (with an implicit intercept term).
X\cr
X\separate
Xy \~ poly(x,2)
Xy \~ 1 + x + I(x\^2)
X&
XPolynomial regression of $y$ on $x$ of degree 2. The first form uses
Xorthogonal polynomials, and the second uses explicit powers, as basis.
X\cr
X\separate
Xy \~ X + poly(x,2)
X&
XMultiple regression $y$ with model matrix consisting of the matrix $X$ as
Xwell as polynomial terms in $x$ to degree 2.
X\cr
X\separate
Xy \~ A
X&
XSingle classification analysis of variance model of $y$, with classes
Xdetermined by $A$.
X\cr
X\separate
Xy \~ A + x
X&
XSingle classification analysis of covariance model of $y$, with classes
Xdetermined by $A$, and with covariate $x$.
X\cr
X\separate
Xy \~ A*B
Xy \~ A + B + A:B
Xy \~ B \%in\% A
Xy \~ A/B
X&
XTwo factor non-additive model of $y$ on $A$ and $B$. The first two specify
Xthe same crossed classification and the second two specify the same nested
Xclassification. In abstract terms all four specify the same model
Xsubspace.
X\cr
X\separate
Xy \~ (A + B + C)\^2
Xy \~ A*B*C - A:B:C
X&
XThree factor experiment but with a model containing main effects and two
Xfactor interactions only. Both formul\ae{} specify the same model.
X\cr
X\separate
Xy \~ A * x
Xy \~ A/x
Xy \~ A/(1 + x) - 1
X&
XSeparate simple linear regression models of $y$ on $x$ within the levels of
X$A$, with different codings. The last form produces explicit estimates of
Xas many different intercepts and slopes as there are levels in $A$.
X\cr
X\separate
Xy \~ A*B + Error(C)
X&
XAn experiment with two treatment factors, $A$ and $B$, and error
Xstrata determined by factor $C$. For example a split plot experiment,
Xwith whole plots, (and hence also subplots), determined by factor $C$.
X\cr
X\separate}}
X}
X
XThe operator \~ is used to define a {\sl model formula\/} in \splus.. The
Xform, for an ordinary linear model, is
X\begin{center}
X\sl response \~ $[\pm]$ term$_1$ $\pm$ term$_2$ $\pm$ term$_3$ $\pm$
X$\cdots$
X\end{center}
X
X\begin{description}
X\item[{\sl response\/}] is a vector or matrix, (or expression evaluating to
Xa vector or matrix) defining the response variable(s).
X\item[$\pm$] is an operator, either {\tt +} or {\tt -}, implying
Xthe inclusion or exclusion of a term in the model, (the first is optional).
X\item[{\sl term}] is either
X\begin{itemize}
X\item a vector or matrix expression, or {\tt 1},
X\item a factor, or
X\item a {\sl formula expression} consisting of factors, vectors or matrices
Xconnected by {\sl formula operators}.
X\end{itemize}
XIn all cases each term defines a collection of columns either to be added
Xto or removed from the model matrix. A {\tt 1} stands for an intercept
Xcolumn and is by default included in the model matrix unless explicitly
Xremoved.
X\end{description}
XThe {\sl formula operators\/} are similar in effect to the Wilkinson and
XRogers notation used used by such programs a {\sf Glim} and {\sf Genstat}.
XOne inevitable change is that the operator ``{\tt.}'' becomes ``{\tt:}''
Xsince the period is a valid name character in \splus.. The notation is
Xsummarised as in the Table~\ref{operators} (based on Chambers \& Hastie,
Xp.\ 29).
X\begin{table}[ht]
X\[
X\begin{tabular}{@{\protect\strutt}|l|p{4.13in}|}
X\hline
XForm & Meaning \\
X\hline
X\tt $Y$ \~ $M$ & $Y$ is modelled as $M$\\
X\tt $M_1$ + $M_2$ & Include $M_1$ and $M_2$\\
X\tt $M_1$ - $M_2$ & Include $M_1$ leaving out terms of $M_2$\\
X\tt $M_1$:$M_2$ & The tensor product of $M_1$ and $M_2$. If both terms
Xfactors, then the ``subclasses'' factor.\\
X\tt $M_1$ \%in\% $M_2$ & Similar to {\tt $M_1$:$M_2$}, but with a different
Xcoding.\\
X\tt $M_1$*$M_2$ & \tt $M_1$ + $M_2$ + $M_1$:$M_2$\\
X\tt $M_1$/$M_2$ & \tt $M_1$ + $M_2$ \%in\% $M_1$\\
X\tt $M$\^$n$ & All terms in $M$ together with ``interactions'' up to order
X$n$\\
X\tt I($M$) & Insulate $M$. Inside $M$ all operators have their normal
Xarithmetic meaning, and that term appears in the model matrix.\\
X\hline
X\end{tabular}
X\]
X\caption{\label{operators} Summary of model operator semantics}
X\medskip\hrule
X\end{table}
X
XNote that inside the parentheses that usually enclose function arguments
Xall operators have their normal arithmetic meaning. The function {\tt
XI()} is an identity function used only to allow terms in model formul\ae{}
Xto be defined using arithmetic operators.
X
XNote particularly that the model formul\ae{} specify the {\em columns of
Xthe model matrix}, specification of the parameters is implicit. This is
Xnot the case in other contexts, for example in fitting nonlinear models
X
X\subsection{Regression models; fitted model objects}
XThe basic function for fitting ordinary multiple models is {\tt lm()}, and
Xa streamlined version of the call is as follows:
X
X\Sprompt {\sl fitted.model\/} <- lm({\sl formula}, data={\sl data.frame\/})
X
XFor example
X
X\Sprompt fm2 <- lm(y \~ x1 + x2, data=production)
X
Xwould fit a multiple regression model of $y$ on $x_1$ and $x_2$ (with
Ximplicit intercept term).
X
XThe important but technically optional parameter {\tt data=production\/}
Xspecifies that any variables needed to construct the model should come
Xfirst from the {\tt production} {\sl data frame\/}. {\em This is the case
Xregardless of whether data frame {\tt production} has been attached to the
Xsearch list or not}.
X
X\subsection{Generic functions for extracting information}
X
XThe value of {\tt lm()} is fitted model object; technically a list of
Xresults of class {\tt lm}. Information about the fitted model can then be
Xdisplayed, extracted, plotted and so on by using generic functions that
Xorient themselves to objects of class {\tt lm}. A full list of these at
Xthe present time is
X\[
X{\tt
X\begin{tabular}{@{\protect\strutt}*{6}{l}}
Xadd1 & coef & effects & kappa & predict & residuals \\
Xalias & deviance & family & labels & print & summary \\
Xanova & drop1 & formula & plot & proj &
X\end{tabular}}
X\]
XA brief description of the most commonly used ones is given in
XTable~\ref{generic}.
X\begin{table}[ht]
X\[
X\begin{tabular}{@{\protect\strutt}|p{1.55in}|p{3.4in}|}
X\hline
XFunction & Value or Effect \\
X\hline
X\tt anova({\sl object}$_1$,\hfil\break\hspace*{1em}
X {\sl object}$_2$) & Compare a submodel with an outer
Xmodel and product an analysis of variance table.\\
X\hline
X\tt coefficients({\sl object}) & Extract the regression coefficient
X(matrix).\hfil\break
XShort form: {\tt coef({\sl object})}.\\
X\hline
X\tt deviance({\sl object}) & Residual sum of squares, weighted if appropriate.\\
X\hline
X\tt formula({\sl object}) & Extract the model formula.\\
X\hline
X\tt plot({\sl object}) & Product two plots, one of the observations against
Xthe fitted values, the other of the absolute residuals against the fitted
Xvalues.\\
X\hline
X\tt predict({\sl object},\hfil\break\null\hfil newdata={\sl data.frame})
X\break
Xpredict.gam({\sl object},\hfil\break\null\hfill newdata={\sl data.frame})
X& The data frame supplied must have variables specified with the same
Xlabels as the original. The value is a vector or matrix of predicted
Xvalues corresponding to the determining variable values in {\sl
Xdata.frame}.\hfil\break \indent {\tt predict.gam()} is a safe alternative
Xto {\tt predict()} that can be used for {\tt lm}, {\tt glm} and {\tt gam}
Xfitted objects. It must be used, for example, in cases where orthogonal
Xpolynomials are used as the original basis functions, and the addition of
Xnew data implies different basis functions to the original.\\
X\hline
X\tt print({\sl object}) & Print a concise version of the object.\hfil\break
XMost often used implicitly.\\
X\hline
X\tt residuals({\sl object}) & Extract the (matrix of) residuals, weighted as
Xappropriate. Short form: {\tt resid({\sl object})}. \\
X\hline
X\tt summary({\sl object}) & Print a comprehensive summary of the results of
Xthe regression analysis. \\
X\hline
X\end{tabular}
X\]
X\caption{\label{generic} Commonly used generic functions on class {\tt lm}
Xobjects}
X\medskip\hrule
X\end{table}
X
X\subsection{Analysis of variance; comparing models}
X
XThe model fitting function {\tt aov({\tt formula}, data={\sl
Xdata.frame\/})} operates at the simplest level in a very similar way to the
Xfunction {\tt lm()}, and most of the generic functions listed in
XTable~\ref{generic} apply.
X
XIt should be noted that in addition {\tt aov()} allows an analysis of
Xmodels with multiple error strata such as split plot experiments, or
Xbalanced incomplete block designs with recovery of inter-block information
Xenvisaged. Model formula
X\begin{center}
X\tt
X{\sl response\/} \~ {\sl mean.formula\/} + Error({\sl strata.formula\/})
X\end{center}
XSpecifies a multi-stratum experiment with error strata defined by the {\sl
Xstrata.formula}. In the simplest case, {\sl strata.formula\/} is simply a
Xfactor, when it defines a two strata experiment, namely between and within
Xthe levels of the factor.
X
XFor example, with all determining variables factors a model formula such as
Xthat in:
X
X\Sprompt fm <- aov(yield \~ v + n*p*k + Error(farms/blocks), data=farm.data)
X
Xwould typically be used to describe an experiment with mean model {\tt v +
Xn*p*k} and three error strata, namely ``between farms'', ``within farms,
Xbetween blocks'' and ``within blocks''.
X
X\subsubsection{ANOVA tables}
XNote also that the analysis of variance table (or tables) are for a
Xsequence of fitted models. The sums of squares shown are the decrease in
Xthe residual sums of squares resulting from an inclusion of {\em that
Xterm\/} in the model at {\em that place\/} in the sequence. Hence only for
Xorthogonal experiments will the order of inclusion be inconsequential.
X
XFor multistratum experiments the procedure is first to project the response
Xonto the error strata, again in sequence, and to fit the mean model to each
Xprojection. For further details, see Chambers and Hastie, \S5.
X
XA more flexible alternative to the default full ANOVA table is to compare
Xtwo or more models directly using the {\tt anova()} function.
X
X\Sprompt anova({\sl fitted.model.1}, {\sl fitted.model.2}, \ldots)
X
XThe display is then an ANOVA table showing the differences between the
Xfitted models when fitted in sequence. The fitted models being compared
Xwould usually be an hierarchical sequence, of course. This does not give
Xdifferent information to the default, but rather makes it easier to
Xcomprehend and control.
X
X\subsection{Updating fitted models. The ditto name ``{\tt .}''}
X
XThe {\tt update()} function is largely a convenience function that allows a
Xmodel to be fitted that differs from one previously fitted usually by just
Xa few additional or removed terms. Its form is
X
X\Sprompt {\sl new.model\/} <- update({\sl old.model}, {\sl new.formula\/})
X
XIn the {\sl new.formula} the special name consisting of a period, ``.'',
Xonly, can be used to stand for ``the corresponding part of the old model
Xformula''. For example
X\begin{verbatim}
X> fm05 <- lm(y ~ x1 + x2 + x3 + x4 + x5, data=production)
X> fm6 <- update(fm05, . ~ . + x6)
X> smf6 <- update(fm6, sqrt(.) ~ .)
X\end{verbatim}
Xwould fit a five variate multiple regression with variables (presumably)
Xfrom the data frame {\tt production}, fit an additional model including a
Xsixth regressor variable, and fit a variant on the model where the response
Xhad a square root transform applied.
X
XNote especially that if the {\tt data=} argument is specified on the
Xoriginal call to the model fitting function, this information is passed on
Xthrough the fitted model object to {\tt update()} and its allies.
X
XThe name ``{\tt.}'' can also be used in other contexts, but with slightly
Xdifferent meaning. For example
X
X\Sprompt fmfull <- lm(y \~ . , data=production)
X
Xwould fit a model with response {\tt y} and regressor variables {\em all
Xother variables in the data frame {\tt production}}.
X
XOther functions for exploring incremental sequences of models are
X{\tt add1()}, {\tt drop1()}, {\tt step()} and {\tt stepwise()}. The names
Xof these give a good clue to their purpose, but for full details see the
Xhelp document.
X
X\subsection{Generalized linear models; families}
XGeneralized linear modelling is a development of linear models to
Xaccommodate both non-normal response distributions and transformations to
Xlinearity in a clean and straightforward way. A generalized linear model
Xmay be described in terms of the following sequence of assumptions:
X
X\begin{itemize}
X\item There is a response, $y$, of interest and stimulus variables $x_1$,
X$x_2$, \ldots whose values influence the distribution of the response.
X
X\item The stimulus variables influence the distribution of $y$ through {\em
Xa single linear function, only}. This linear function is called the {\em
Xlinear predictor}, and is usually written
X\[
X\eta = \beta_1x_1 + \beta_2x_2 +\cdots+\beta_px_p
X\]
Xhence $x_i$ has no influence on the distribution of $y$ if and only if
X$\beta_i=0$.
X
X\item The distribution of $y$ is of the form
X\[
Xf_Y(y;\mu,\varphi) = \exp\left[\frac{A}{\varphi}\left\{y\lambda(\mu) -
X\gamma\left(\lambda(\mu)\right)\right\} + \tau(y,\varphi)\right]
X\]
Xwhere $\varphi$ is a {\em scale parameter}, (possibly known), and is
Xconstant for all observations, $A$ represents a prior weight, assumed known
Xbut possibly varying with the observations, and $\mu$ is the mean of $y$.
XSo it is assumed that the distribution of $y$ is determined by its mean and
Xpossibly a scale parameter as well.
X
X\item The mean, $\mu$, is a smooth invertible function of the linear predictor:
X\[
X\mu = m(\eta),\qquad \eta = m^{-1}(\mu) = \ell(\mu)
X\]
Xand this inverse function, $\ell(.)$ is called the {\em link function}.
X\end{itemize}
X
XThese assumptions are loose enough to encompass a wide class of models
Xuseful in statistical practice, but tight enough to allow the development
Xof a unified methodology of estimation and inference, at least
Xapproximately. The reader is referred to any of the current reference
Xworks on the subject for full details, such as
X\begin{itemize}
X\item[] {\em Generalized linear models\/} by Peter McCullagh and John A~Nelder,
X2nd~edition, Chapman and Hall, 1989, or
X
X\item[] {\em An introduction to generalized linear models\/} by Annette
XJ~Dobson, Chapman and Hall, 1990.
X\end{itemize}
X
X\subsubsection{Families}
X
XThe class of generalized linear models handled by facilities supplied in
X\splus. includes {\sl gaussian}, {\sl binomial}, {\sl poisson}, {\sl
Xinverse gaussian\/} and {\sl gamma} response distributions and also {\sl
Xquasi-likelihood} models where the response distribution is not explicitly
Xspecified. In the latter case the {\em variance function\/} must be
Xspecified as a function of the mean, but in other cases this function is
Ximplied by the response distribution.
X
XEach response distribution admits a variety of link functions to connect
Xthe mean with the linear predictor. Those automatically available are as
Xin Table~\ref{links}.
X\begin{table}[ht]
X{\small
X\[
X\begin{tabular}{@{\protect\strutt}|c|*{6}{c|}}
X\hline
X&\multicolumn{6}{c|}{\protect\strutt Family Name}\\
X\cline{2-7}
XLink Function &\tt binomial &\tt gaussian &\tt Gamma &\tt inverse.gaussian &\tt
Xpoisson &\tt quasi \\
X\hline
X\tt logit & $\star$ & & & & & $\star$\\
X\tt probit & $\star$ & & & & & $\star$\\
X\tt cloglog & $\star$ & & & & & $\star$\\
X\tt identity & & $\star$ & $\star$& & $\star$ & $\star$\\
X\tt inverse & & & $\star$& & & $\star$\\
X\tt log & & & $\star$& & $\star$ & $\star$\\
X\tt 1/mu\^2 & & & & $\star$ & & $\star$\\
X\tt sqrt & & & & & $\star$ & $\star$\\
X\hline
X\end{tabular}
X\]
X}
X\caption{\label{links} Families and the link functions available to them}
X\medskip\hrule
X\end{table}
X
XThe combination of a response distribution, a link function and various
Xother pieces of information that are needed to carry out the modelling
Xexercise is called the {\em family\/} of the generalized linear model.
X
X\subsubsection{The {\tt glm()} function}
X
XSince the distribution of the response depends on the stimulus variables
Xthrough a single linear function {\em only}, the same mechanism as was used
Xfor linear models can still be used to specify the linear part of a
Xgeneralized model. The family has to be specified in a different way.
X
XThe \splus. function to fit a generalized linear model is {\tt glm()} which
Xuses the form
X
X\Sprompt {\sl fitted.model\/} <- glm({\sl formula}, family ={\sl
Xfamily.generator}, data={\sl data.frame})
X
XThe only new feature is the {\sl family.generator}, which is the way the
Xfamily is described. Although it seems a little complicated at first
Xsight, (it is the name of a function that generates a list of functions and
Xexpressions that together define and control the model and estimation
Xprocess), its use is quite simple.
X
XThe names of the standard, supplied family generators are given under
X``Family Name'' in Table~\ref{links}. Where there is a choice of links,
Xthe name of the link may also be supplied with the family name, in
Xparentheses as a parameter. In the case of the {\tt quasi} family,
Xthe variance function may also be specified in this way.
X
XSome examples make the process clear.
X
X
X\subsubsection*{The {\tt gaussian} family}
XA call such as
X
X\Sprompt fm <- glm(y \~ x1+x2, family=gaussian, data=sales)
X
Xachieves the same result as
X
X\Sprompt fm <- lm(y \~ x1+x2, data=sales)
X
Xbut much less efficiently. Note how the gaussian family is not
Xautomatically provided with a choice of links, so no parameter is allowed.
XIf a problem requires a gaussian family with a nonstandard link, this can
Xusually be achieved through the {\tt quasi} family, as we shall see later.
X
X\subsubsection*{The {\tt binomial} family}
XConsider a small, artificial example.
X
XOn the Greek island of Kalythos the male inhabitants suffer from a
Xcongenital eye disease, the effects of which become more marked with
Xincreasing age. Samples of islander males of various ages were tested for
Xblindness and the results recorded. The data is shown in
XTable~\ref{blind}.
X\begin{table}[ht]
X$$
X\begin{tabular}{@{\protect\strutt}|l|rrrrr|}
X\hline
XAge: & 20 & 35 & 45 & 55 & 70 \\
X\hline
XNo.\ tested: & 50 & 50 & 50 & 50 & 50 \\
X\hline
XNo.\ blind: & 6 & 17 & 26 & 37 & 44 \\
X\hline
X\end{tabular}
X$$
X\caption{\label{blind}The Kalythos blindness data}
X\medskip\hrule
X\end{table}
X
XThe problem we consider is to fit both logistic and probit models to this
Xdata, and to estimate for each model the LD50, that is the age at which the
Xchance of blindness for a male inhabitant is 50\%.
X
XIf $y$ is the number of blind at age $x$ and $n$ the number tested, both
Xmodels have the form
X\[
Xy \sim {\rm B}(n, F(\beta_0+\beta_1x))
X\]
Xwhere for the probit case, $F(z)= \Phi(z)$ is the standard normal
Xdistribution function, and in the logit case, (the default), $F(z) =
Xe^z/(1+e^z)$. In both cases the LD50 is
X\[
X\hbox{LD50} = -\beta_0/\beta_1
X\]
Xthat is, the point at which the argument of the distribution function is
Xzero.
X
XThe first step is to set the data up as a data frame
X
X\Sprompt kalythos <- data.frame(x=c(20,35,45,55,70), n=rep(50,5),
X
X\Contd \hspace*{1in} y=c(6,17,26,37,44))
X
XTo fit a binomial model using {\tt glm()} there are two possibilities for
Xthe response:
X\begin{itemize}
X\item If the response is a {\em vector\/} it is assumed to hold {\em
Xbinary\/} data, and so must be a $0,1$ vector.
X
X\item If the response is a {\em two column matrix\/} it is assumed that the
Xfirst column holds the number of successes for the trial and the second
Xholds the number of failures.
X\end{itemize}
X
XHere we need the second of these conventions, so we add a matrix to our
Xdata frame:
X
X\Sprompt kalythos\$Ymat <- cbind(kalythos\$y, kalythos\$n - kalythos\$y)
X
XTo fit the models we use
X
X\Sprompt fmp <- glm( Ymat\~x, family=binomial(link=probit), data=kalythos)
X
X\Sprompt fml <- glm( Ymat\~x, family=binomial, data=kalythos)
X
XSince the logit link is the default the parameter may be omitted on the
Xsecond call. To see the results of each fit we could use
X
X\Sprompt summary(fmp)
X
X\Sprompt summary(fml)
X
XBoth models fit (all too) well. To find the LD50 estimate we can use a
Xsimple function:
X
X\Sprompt ld50 <- function(b) -b[1]/b[2]
X
X\Sprompt ldp <- ld50(coef(fmp)); ldl <- ld50(coef(fmp)); c(ldp, ldl)
X
XThe actual estimates from this data are 43.663 years and 43.601 years
Xrespectively.
X
X\subsubsection*{Poisson models}
XWith the poisson family the default link is the {\tt log}, and in practice
Xthe major use of this family is to fit surrogate poisson log-linear models
Xto frequency data, whose actual distribution is often multinomial. This is
Xa large and important subject we will not discuss further here. It even
Xforms a major part of the use of non-gaussian generalized models overall.
X
XOccasionally genuinely poisson data arises in practice and in the past it
Xwas often analysed as gaussian data after either a log or a square-root
Xtransformation. As a graceful alternative to the latter, a poisson
Xgeneralized linear model may be fitted as in the following example:
X
X\Sprompt fmod <- glm(y \~ A+B + x, family=poisson(link=sqrt),
Xdata=worm.counts)
X
X\subsubsection*{Quasi-likelihood models}
X
XFor all families the variance of the response will depend on the mean and
Xwill have the scale parameter as a multiplier. The form of dependence of
Xthe variance on the mean is a characteristic of the response distribution;
Xfor example for the poisson distribution the $\hbox{Var}[y] = \mu$.
X
XFor quasi-likelihood estimation and inference the precise response
Xdistribution is not specified, but rather only a link function and the form
Xof the variance function as it depends on the mean. Since quasi-likelihood
Xestimation uses formally identical techniques to those for the gaussian
Xdistribution, this family provides a way of fitting gaussian models with
Xnon-standard link functions or variance functions, incidently.
X
XFor example, consider fitting the non-linear regression
X\begin{equation}
Xy = \frac{\theta_1z_1}{z_2 - \theta_2} + e \label{storm}
X\end{equation}
Xthis may be written alternatively as
X\[
Xy = \frac{1}{\beta_1x_1 + \beta_2x_2} + e
X\]
Xwhere $x_1 = z_2/z_1$, $x_2=-1/x_1$, $\beta_1=1/\theta_1$ and
X$\beta_2=\theta_2/\theta_1$. Supposing a suitable data frame to be set up
Xwe could fit this non-linear regression as
X
X\Sprompt nlfit <- glm(y\~x1+x2-1,family=\hfil\break
Xquasi(link=inverse,variance=constant), data=biochem)
X
XThe reader is referred to the manual and the help document for further
Xinformation, as needed.
X
X\subsection{Nonlinear regression models; parametrized data frames}
X\splus. provides two functions to fit nonlinear models that do not conform
Xeven to the partially linear paradigm of generalized linear models. These
Xare {\tt ms()} for arbitrary minimization problems where the objective
Xfunctions is a sum of similar terms, and {\tt nls()} for conventional
Xnonlinear least squares estimation of normal nonlinear regression models.
X
XIn this brief introduction we only consider the nonlinear regression
Xfunction {\tt nls()} and leave {\tt ms()} for the reader to pursue as
Xneeded.
X
X\subsubsection{Changes to the form of the model formula}
XIn specifying a linear, or generalized linear model we could allow the
Xregression parameters to be defined implicitly, and to be given names by
Xtransference from the column of the model matrix that they multiply.
X
XIn arbitrary nonlinear models no such simplicity applies and we have to
Xspecify the model as an ordinary expression that includes both determining
Xvariables and parameters together. For example to specify a model for a
Xnonlinear regression such as \ref{storm} above, we would use
X\begin{center}
X\tt
Xy \~ t1*x1/(x2 - t2)
X\end{center}
Xwhere {\tt y} is the response variable, {\tt x1} and {\tt x2} are
Xdetermining variables and {\tt t1} and {\tt t2} are scalar parameters.
X
XIn such model formul\ae{} all operators have their usual arithmetic
Xexpression meaning, and the useful facility of expanding factors and
Xforming cross and nested structures is no longer available. All parameters
Xmust be explicitly defined in the formula, even if they come from a linear
Xpart of the model.
X
X\subsubsection{Specifying the parameters}
XSince the model formula now contains both determining variables and
Xparameters, there has to be some mechanism for specifying which are which.
XBut of course once the parameters have been specified the remaining variates
Xin the model formula must be variables.
X
XAs well as specifying which are the parameters, it is also necessary in
Xthis case to specifying an initial approximation for each with which to
Xstart the iterative estimation procedure.
X
XThere are two ways of specifying this information:
X\begin{itemize}
X\item If the call to {\tt nls()} has a {\tt start=} parameter specified,
Xits value must be a list of named components. The names of the list
Xspecify the names of the parameters and the values specify the starting
Xvalues.
X
X\item If the data is held in a data frame, the parameters may similarly be
Xdefined as a {\sl parameters attribute\/} of the data frame.
X\end{itemize}
X
XSince our policy is generally to work with data frames as much as follows,
Xwe show the second possibility in the next example.
X
X\subsubsection*{Example}
X
XConsider again a nonlinear regression of the form~\ref{storm}. An easy
Xway to find initial estimates for the parameters is to regress $x_2y$ on
X$x_1$ and $x_2$:
X
X\Sprompt fm0 <- lm(x2*y \~ x1 + x2 - 1, data=biochem)
X
X\Sprompt th <- coef(fm0)
X
XTo name the parameters and associate them with the {\tt biochem} is done as
Xfollows:
X
X\Sprompt parameters(biochem) <- list(t1=th[1], t2=th[2])
X
XNow to fit the nonlinear regression model:
X
X\Sprompt fm <- nls(y \~ t1*x1/(x2 - t2), data=biochem)
X
XAt this point we could use the {\tt summary()} function and most of the
Xother generics to investigate the model and display information. To
Xextract the coefficients we could now use, for example
X
X\Sprompt th <- coef(fm)
X
Xand to make these least squares estimates the new values of the parameters
Xassociated with {\tt biochem} we could simply repeat the step
X
X\Sprompt parameters(biochem) <- list(t1=th[1], t2=th[2])
X
XNote that the function {\tt parameters()} may either be used as an
Xexpression, in which case it extracts the list of parameters from a data
Xframe, or it may be used as the target for an assignment, in which case it
Xaccepts a parameter list for a specified data frame. In this respect it is
Xvery similar to the {\tt attributes()} function. There is also a function
X{\tt param()} analogous to {\tt attr()}, which handles one parameter at a
Xtime under a character string name.
X
X\subsection{Some non-standard models}
XWe conclude this section with just a brief mention of some of the other
Xfacilities available in \splus. for special regression and data analysis
Xproblems.
X
X\begin{description}
X\item [Local approximating regressions.] The {\tt loess()} function fits
Xa nonparametric regression by using a locally weighted regression. Such
Xregressions are useful for highlighting a trend in messy data or for data
Xreduction to give some insight into a large data set.
X
X\item[Robust regression] There are several functions available for fitting
Xregression models in a way resistant to the influence of extreme outliers
Xin the data. The most sophisticated of these is {\tt rreg()}, but others
Xinclude {\tt lmsfit()} for least median squares regression and {\tt
Xl1fit()} for regression using the $L_1-$norm. However these do not as yet
Xhave the facility of using formul\ae{} to specify the model function, for
Xexample, and conform to an older protocol, which makes them sometimes
Xrather tedious to use. There is also a {\tt robust()} facility to change a
X{\tt glm} family object into a robust version for use with the {\tt glm()}
Xmodel fitting function.
X
X\item[Generalized additive models.] This technique aims to construct an
Xregression function from smooth additive functions of the determining
Xvariables, usually one for each determining variable. The function {\tt
Xgam()} is in many ways similar to the other model fitting functions
Xoutlined above. In addition there are other model fitting functions that
Xdo a similar job. These include {\tt avas()} and {\tt ace()}. On the
Xother hand {\tt ppreg()} is available for projection pursuit regression,
Xbut this technique is still very much in need of a complete theoretical
Xtreatment and further practical experience. These latter functions are
Xagain conforming to an older protocol for model fitting functions and lack
Xthe convenience of the newer functions.
X
X\item[Tree based models] Rather than seek an explicit global linear model
Xfor prediction or interpretation, tree based models seek to bifurcate the
Xdata, recursively, at critical points of the determining variables in
Xorder to partition the data ultimately into groups that are as homogeneous
Xas possible within, and as heterogeneous as possible between. The results
Xoften lead to insights that other data analysis methods tend not to yield.
X
XModels are again specified in the ordinary linear model form. The model
Xfitting function is {\tt tree()}, but many other generic functions such as
X{\tt plot()} and {\tt text()} are well adapted to displaying the results of
Xa tree-based model fit in a graphical way.
X
X\end{description}
X
X\endinput
END_OF_FILE
if test 32072 -ne `wc -c <'SplusDS/models.tex'`; then
echo shar: \"'SplusDS/models.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/models.tex'
fi
if test -f 'SplusDS/multifig.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/multifig.aux'\"
else
echo shar: Extracting \"'SplusDS/multifig.aux'\" \(436 characters\)
sed "s/^X//" >'SplusDS/multifig.aux' <<'END_OF_FILE'
X\relax
X\global\@namedef{cp@multifig}{
X\setcounter{page}{56}
X\setcounter{equation}{1}
X\setcounter{enumi}{6}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{7}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{11}
X\setcounter{subsection}{5}
X\setcounter{subsubsection}{4}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{10}
X\setcounter{table}{4}
X}
END_OF_FILE
if test 436 -ne `wc -c <'SplusDS/multifig.aux'`; then
echo shar: \"'SplusDS/multifig.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/multifig.aux'
fi
if test -f 'SplusDS/multifig.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/multifig.tex'\"
else
echo shar: Extracting \"'SplusDS/multifig.tex'\" \(3010 characters\)
sed "s/^X//" >'SplusDS/multifig.tex' <<'END_OF_FILE'
X\setlength{\unitlength}{0.0125in}%
X\begin{picture}(360,500)(60,260)
X\thicklines
X\put( 60,712){\vector(-1, 0){ 0}}
X\put( 60,712){\vector( 1, 0){ 40}}
X\put(199,757){\vector( 0, 1){ 0}}
X\put(199,757){\vector( 0,-1){ 36}}
X\put(100,580){\line( 1, 0){280}}
X\put(100,440){\line( 1, 0){280}}
X\put(240,720){\line( 0,-1){420}}
X\put(100,300){\framebox(280,420){}}
X\put( 60,260){\framebox(360,500){}}
X\multiput(162,280)(8.10256,0.00000){20}{\line( 1, 0){ 4.051}}
X\multiput(161,290)(8.15385,0.00000){20}{\line( 1, 0){ 4.077}}
X\multiput(161,270)(8.15385,0.00000){20}{\line( 1, 0){ 4.077}}
X\put(269,621){\framebox(18,60){}}
X\put(290,621){\framebox(17,43){}}
X\put(310,621){\framebox(16,31){}}
X\put(330,621){\framebox(16,40){}}
X\put(120,460){\framebox(100,100){}}
X\put(260,460){\framebox(100,100){}}
X\put(260,600){\framebox(100,100){}}
X\put(120,600){\framebox(100,100){}}
X\put(265,470){\line( 3, 5){ 15}}
X\put(280,495){\line( 2,-1){ 20}}
X\put(300,485){\line( 1, 5){ 10}}
X\put(310,535){\line( 3,-2){ 15}}
X\put(325,525){\line( 1, 1){ 20}}
X\put(199,678){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(187,670){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(184,656){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(174,650){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(162,650){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(156,631){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(145,620){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(153,618){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(135,614){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(138,548){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(163,528){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(193,538){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(138,523){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(163,518){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(188,518){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(203,508){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(208,483){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(173,473){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(173,493){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(158,488){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(143,503){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(123,503){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put(138,473){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt *}}}
X\put( 74,728){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt omi[2]}}}
X\put(206,734){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt omi[3]}}}
X\put(327,743){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt mfrow=c(3,2)}}}
X\put(328,274){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt oma[1]}}}
X\put(265,445){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twltt mfg=c(2,2,3,2)}}}
X\end{picture}
END_OF_FILE
if test 3010 -ne `wc -c <'SplusDS/multifig.tex'`; then
echo shar: \"'SplusDS/multifig.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/multifig.tex'
fi
if test -f 'SplusDS/objects.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/objects.aux'\"
else
echo shar: Extracting \"'SplusDS/objects.aux'\" \(1149 characters\)
sed "s/^X//" >'SplusDS/objects.aux' <<'END_OF_FILE'
X\relax
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {3}Objects, their modes and attributes}{11}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.1}Intrinsic attributes: {\string\psl\space mode\/} and {\string\psl\space length}}{11}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.2}Changing the length of an object}{12}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.3}{\string\ptt\space attributes()} and {\string\ptt\space attr()}}{12}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.4}The {\string\psl\space class} of an object}{12}}
X\global\@namedef{cp@objects}{
X\setcounter{page}{13}
X\setcounter{equation}{0}
X\setcounter{enumi}{6}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{4}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{3}
X\setcounter{subsection}{4}
X\setcounter{subsubsection}{0}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{0}
X\setcounter{table}{0}
X}
END_OF_FILE
if test 1149 -ne `wc -c <'SplusDS/objects.aux'`; then
echo shar: \"'SplusDS/objects.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/objects.aux'
fi
if test -f 'SplusDS/objects.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/objects.tex'\"
else
echo shar: Extracting \"'SplusDS/objects.tex'\" \(7546 characters\)
sed "s/^X//" >'SplusDS/objects.tex' <<'END_OF_FILE'
X% -*-latex-*-
X% Document name: Splus.tex
X%
X% Version 2.0, March, 1992
X%
X\section{Objects, their modes and attributes}
X
X\subsection{Intrinsic attributes: {\sl mode\/} and {\sl length}}
X
XThe entities \splus. operates on are technically known as {\sl objects\/}.
XExamples are vectors of numeric (real) or complex values, vectors of
Xlogical values and vectors of character strings. These are known as
X`atomic' structures since their components are all of the same type, or
X{\sl mode\/}, namely {\sl numeric\/}\footnote{{\sl numeric\/} mode is
Xactually an amalgam of three distinct modes, namely {\sl integer\/}, {\sl
Xsingle\/} precision and {\sl double\/} precision, as explained in the
Xmanual.}, {\sl complex\/}, {\sl logical\/} and {\sl character\/}
Xrespectively.
X
XVectors must have their values {\sl all of the same mode\/}. Thus any
Xgiven vector must be unambiguously either {\sl logical\/}, {\sl numeric\/},
X{\sl complex} or {\sl character\/}. The only mild exception to this rule
Xis the special ``value'' listed as {\tt NA} for quantities not available.
XNote that a vector can be empty and still have a mode. For example the
Xempty character string vector is listed as {\tt character(0)} and the empty
Xnumeric vector as {\tt numeric(0)}.
X
X\splus. also operates on objects called {\sl lists\/}, which are of mode {\sl
Xlist\/}. These are ordered sequences of objects which individually can be
Xof any mode. {\sl lists\/} are known as `recursive' rather than atomic
Xstructures since their components can themselves be lists in their own
Xright.
X
XThe other recursive structures are those of mode {\sl function\/} and {\sl
Xexpression}. {\sl Functions} are the functions that form part of the
X\splus. system along with similar user written functions, which we discuss
Xin some detail later in these notes. {\sl Expressions\/} as objects form
Xan advanced part of \splus. which will not be discussed in these notes,
Xexcept indirectly when we discuss {\sl formul\ae} with we discuss modelling
Xin \splus..
X
X
XBy the {\sl mode\/} of an object we mean the basic type of its fundamental
Xconstituents. This is a special case of an {\sl attribute\/} of an object.
XThe {\sl attributes\/} of an object provide specific information about the
Xobject itself. Another attribute of every object is its {\sl length\/}.
XThe functions {\tt mode({\sl object\/})} and {\tt length({\sl object\/})}
Xcan be used to find out the mode and length of any defined structure.
X%
X%
X% More
X% importantly these functions can be used on the left hand side of an
X% assignment to change the attributes of an object; when this change is one
X% of mode only, the process is known as {\sl coercion\/}.
X
XFor example, if {\tt z} is complex vector of length 100, then in an
Xexpression {\tt mode(z)} is the character string {\tt"complex"} and {\tt
Xlength(z)} is {\tt 100}.
X
X% Also the assignment
X%
X% \Sprompt mode(z) <- "numeric"
X%
X% coerces the vector to be numeric by discarding the complex parts and
X% retaining the real parts. The further assignment
X%
X% \Sprompt length(z) <- 10
X%
X% truncates it down to the first ten values, and then
X%
X% \Sprompt length(z) <- 100
X%
X% lengthens it to a structure of 100 values again by padding it out with
X% {\tt NA}s. A final assignment
X%
X% \Sprompt mode(z) <- "character"
X%
X% coerces it into a vector, not of numbers, but of character strings with the
X% values of the numbers as if they were to be printed. (The values {\tt NA}
X% are converted to the character string {\tt "NA"}.)
X
X\splus. caters for changes of mode almost anywhere it could be considered
Xsensible to do so, (and a few where it might not be). For example with
X
X\Sprompt z <- 0:9
X
Xwe could put
X
X\Sprompt digits <- as.character(z)
X
Xafter which {\tt digits} is the character vector {\tt ("0", "1", "2",
X\ldots, "9")}. A further {\sl coercion}, or change of mode, reconstructs
Xthe numerical vector again:
X
X\Sprompt d <- as.numeric(digits)
X
XNow {\tt d} and {\tt z} are the same.\footnote{In general coercion from
Xnumeric to character and back again will not be exactly reversible, because
Xof roundoff errors in the character representation.} There is a large
Xcollection of functions of the form {\tt as.something()} for either
Xcoercion from one mode to another, or for investing an object with some
Xother attribute it may not already posses. The reader should consult the
Xhelp file to become familiar with them.
X
X\subsection{Changing the length of an object}
X
XAn ``empty'' object may still have a mode. For example
X
X\Sprompt e <- numeric()
X
Xmakes {\tt e} an empty vector structure of mode numeric. Similarly {\tt
Xcharacter()} is a empty character vector, and so on. Once an object of any
Xsize has been created, new components may be added to it simply by giving
Xit an index value outside its previous range. Thus
X
X\Sprompt e[3] <- 17
X
Xnow makes {\tt e} a vector of length 3, (the first two components of which
Xare at this point both {\tt NA}). This applies to any structure at all,
Xprovided the mode of the additional component(s) agrees with the mode of
Xthe object in the first place.
X
XThis automatic adjustment of lengths of an object is used often, for
Xexample in the {\tt scan()} function for input.
X
XConversely to truncate the size of an object requires only an assignment to
Xdo so. Hence if {\tt alpha} is a structure of length 10, then
X
X\Sprompt alpha <- alpha[2 * 1:5]
X
Xmakes it an object of length 5 consisting of just the former components
Xwith even index. The old indices are not retained, of course.
X%
X% If you give a numeric or complex vector a {\sl dim\/} attribute, you
X% convert it into a multi-way array, as we shall see later.
X
X\subsection{{\tt attributes()} and {\tt attr()}}
X
XThe function {\tt attributes({\sl object\/})} gives a list of all the
Xnon-intrinsic attributes currently defined for that object. The function
X{\tt attr({\sl object},{\sl name\/})} can be used to select a specific
Xattribute. These functions are rarely used, except in rather special
Xcircumstances when some new attribute is being created for some particular
Xpurpose, for example to associate a creation date or an operator with an
X\splus. object. The concept, however, is very important.
X
X% When it is used on the left hand side of an assignment it can
X% be used either to associate a new attribute with {\tt {\sl object\/}} or to
X% change an existing one. For example
X%
X% \Sprompt attr(z,"dim") <- c(10,10)
X%
X% allows \splus. to treat {\tt z} as if it were a $10\times10$ matrix.
X
X\subsection{The {\sl class} of an object}
X
XA special attribute known as the {\sl class\/} of the object has been
Xintroduced in the August~1991 release of \s. and \splus. to allow for an
Xobject oriented style of programming in \splus..
X
XFor example if an object has class {\tt data.frame}, it will be printed in
Xa certain way, the {\tt plot()} function will display it graphically in a
Xcertain way, and other generic functions such as {\tt summary()} will react
Xto it as an argument in a way sensitive to its class.
X
XTo remove temporarily the effects of class, use the function {\tt
Xunclass()}. For example if {\tt winter} has the class {\tt data.frame}
Xthen
X
X\Sprompt winter
X
Xwill print it in data frame form, which is rather like a matrix, whereas
X
X\Sprompt unclass(winter)
X
Xwill print it as an ordinary list. Only in rather special situations do
Xyou need to use this facility, but one is when you are learning to come to
Xterms with the idea of class and generic functions.
X
XGeneric functions and classes will be discussed further in \S\ref{oops},
Xbut only briefly.
X
X
END_OF_FILE
if test 7546 -ne `wc -c <'SplusDS/objects.tex'`; then
echo shar: \"'SplusDS/objects.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/objects.tex'
fi
if test -f 'SplusDS/parfig.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/parfig.tex'\"
else
echo shar: Extracting \"'SplusDS/parfig.tex'\" \(2489 characters\)
sed "s/^X//" >'SplusDS/parfig.tex' <<'END_OF_FILE'
X\setlength{\unitlength}{0.0125in}%
X\begin{picture}(380,355)(60,400)
X\thicklines
X\put(160,639){\line(-1, 0){ 10}}
X\put(159,579){\line(-1, 0){ 8}}
X\put(159,520){\line(-1, 0){ 8}}
X\put(159,460){\line(-1, 0){ 8}}
X\put(361,439){\line( 0,-1){ 7}}
X\put(301,439){\line( 0,-1){ 6}}
X\put(241,439){\line( 0,-1){ 7}}
X\put(181,439){\line( 0,-1){ 7}}
X\put(257,438){\vector( 0, 1){ 0}}
X\put(257,438){\vector( 0,-1){ 36}}
X\put(160,440){\vector( 0, 1){237}}
X\put(121,739){\vector(-1, 0){ 0}}
X\put(121,739){\vector( 1, 0){319}}
X\put(100,679){\vector( 0, 1){ 0}}
X\put(100,679){\vector( 0,-1){240}}
X\multiput(202,690)(8.15385,0.00000){20}{\line( 1, 0){ 4.077}}
X\multiput(202,710)(8.15385,0.00000){20}{\line( 1, 0){ 4.077}}
X\multiput(203,700)(8.10256,0.00000){20}{\line( 1, 0){ 4.051}}
X\put(120,400){\framebox(320,320){}}
X\put(121,445){\vector(-1, 0){ 0}}
X\put(121,445){\vector( 1, 0){ 39}}
X\put(161,440){\vector( 1, 0){239}}
X\multiput(160,680)(8.88889,0.00000){28}{\makebox(0.4444,0.6667){\tenrm .}}
X\multiput(400,680)(0.00000,-8.88889){28}{\makebox(0.4444,0.6667){\tenrm .}}
X\put( 60,563){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\elvtt pin[2]}}}
X\put(268,746){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\elvtt fin[1]}}}
X\put(122,428){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\elvtt mai[2]}}}
X\put(371,696){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\elvtt mar[3]}}}
X\put(220,550){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(245,560){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(200,490){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(300,605){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(285,575){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(350,610){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(350,650){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(225,520){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(180,465){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(215,490){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(265,590){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(325,620){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(380,660){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(140,560){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlsf y}}}
X\put(210,415){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\elvtt mai[1]}}}
X\put(280,420){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlsf x}}}
X\end{picture}
END_OF_FILE
if test 2489 -ne `wc -c <'SplusDS/parfig.tex'`; then
echo shar: \"'SplusDS/parfig.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/parfig.tex'
fi
if test -f 'SplusDS/parfig2.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/parfig2.aux'\"
else
echo shar: Extracting \"'SplusDS/parfig2.aux'\" \(434 characters\)
sed "s/^X//" >'SplusDS/parfig2.aux' <<'END_OF_FILE'
X\relax
X\global\@namedef{cp@parfig2}{
X\setcounter{page}{56}
X\setcounter{equation}{1}
X\setcounter{enumi}{6}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{7}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{11}
X\setcounter{subsection}{5}
X\setcounter{subsubsection}{3}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{9}
X\setcounter{table}{4}
X}
END_OF_FILE
if test 434 -ne `wc -c <'SplusDS/parfig2.aux'`; then
echo shar: \"'SplusDS/parfig2.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/parfig2.aux'
fi
if test -f 'SplusDS/parfig2.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/parfig2.tex'\"
else
echo shar: Extracting \"'SplusDS/parfig2.tex'\" \(2355 characters\)
sed "s/^X//" >'SplusDS/parfig2.tex' <<'END_OF_FILE'
X\setlength{\unitlength}{0.0125in}%
X\begin{picture}(320,320)(120,400)
X\thicklines
X\put(160,639){\line(-1, 0){ 10}}
X\put(159,579){\line(-1, 0){ 8}}
X\put(159,520){\line(-1, 0){ 8}}
X\put(159,460){\line(-1, 0){ 8}}
X\put(361,439){\line( 0,-1){ 7}}
X\put(301,439){\line( 0,-1){ 6}}
X\put(241,439){\line( 0,-1){ 7}}
X\put(181,439){\line( 0,-1){ 7}}
X\put(257,438){\vector( 0, 1){ 0}}
X\put(257,438){\vector( 0,-1){ 36}}
X\put(160,440){\vector( 0, 1){237}}
X\multiput(202,690)(8.15385,0.00000){20}{\line( 1, 0){ 4.077}}
X\multiput(202,710)(8.15385,0.00000){20}{\line( 1, 0){ 4.077}}
X\multiput(203,700)(8.10256,0.00000){20}{\line( 1, 0){ 4.051}}
X\put(120,400){\framebox(320,320){}}
X\put(121,445){\vector(-1, 0){ 0}}
X\put(121,445){\vector( 1, 0){ 39}}
X\put(161,440){\vector( 1, 0){239}}
X\multiput(160,680)(8.88889,0.00000){28}{\makebox(0.4444,0.6667){\tenrm .}}
X\multiput(400,680)(0.00000,-8.88889){28}{\makebox(0.4444,0.6667){\tenrm .}}
X\put(122,428){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\elvtt mai[2]}}}
X\put(371,696){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\elvtt mar[3]}}}
X\put(220,550){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(245,560){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(200,490){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(300,605){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(285,575){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(350,610){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(350,650){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(225,520){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(180,465){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(215,490){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(265,590){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(325,620){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(380,660){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\tentt *}}}
X\put(140,560){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlsf y}}}
X\put(210,415){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\elvtt mai[1]}}}
X\put(280,420){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlsf x}}}
X\put(175,655){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm Plot region}}}
X\put(390,415){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm Margin}}}
X\end{picture}
END_OF_FILE
if test 2355 -ne `wc -c <'SplusDS/parfig2.tex'`; then
echo shar: \"'SplusDS/parfig2.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/parfig2.tex'
fi
if test -f 'SplusDS/parskip.sty' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/parskip.sty'\"
else
echo shar: Extracting \"'SplusDS/parskip.sty'\" \(1208 characters\)
sed "s/^X//" >'SplusDS/parskip.sty' <<'END_OF_FILE'
X% This is PARSKIP.STY by H.Partl, TU Wien, as of 19 Jan 1989.
X% Document Style Option to be used with any style and with any size.
X% It produces the following Paragraph Layout:
X% Zero Parindent and non-zero Parskip. The stretchable glue in \parskip
X% helps LaTeX in finding the best place for page breaks.
X
X\parskip=0.5\baselineskip \advance\parskip by 0pt plus 2pt
X\parindent=\z@
X
X% To accompany this, the vertical spacing in the list environments is changed
X% to use the same as \parskip in all relevant places (for normalsize only):
X% \parsep = \parskip
X% \itemsep = \z@ % add nothing to \parskip between items
X% \topsep = \z@ % add nothing to \parskip before first item
X
X\def\@listI{\leftmargin\leftmargini
X \topsep\z@ \parsep\parskip \itemsep\z@}
X\let\@listi\@listI
X\@listi
X
X\def\@listii{\leftmargin\leftmarginii
X \labelwidth\leftmarginii\advance\labelwidth-\labelsep
X \topsep\z@ \parsep\parskip \itemsep\z@}
X
X\def\@listiii{\leftmargin\leftmarginiii
X \labelwidth\leftmarginiii\advance\labelwidth-\labelsep
X \topsep\z@ \parsep\parskip \itemsep\z@}
X
X% Note that listiv, listv and listvi don't change vertical parameters.
X
X\endinput
X
X
END_OF_FILE
if test 1208 -ne `wc -c <'SplusDS/parskip.sty'`; then
echo shar: \"'SplusDS/parskip.sty'\" unpacked with wrong size!
fi
# end of 'SplusDS/parskip.sty'
fi
if test -f 'SplusDS/preface.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/preface.aux'\"
else
echo shar: Extracting \"'SplusDS/preface.aux'\" \(499 characters\)
sed "s/^X//" >'SplusDS/preface.aux' <<'END_OF_FILE'
X\relax
X\@writefile{toc}{\string\contentsline\space {section}{Preface}{i}}
X\global\@namedef{cp@preface}{
X\setcounter{page}{6}
X\setcounter{equation}{0}
X\setcounter{enumi}{0}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{0}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{0}
X\setcounter{subsection}{0}
X\setcounter{subsubsection}{0}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{0}
X\setcounter{table}{0}
X}
END_OF_FILE
if test 499 -ne `wc -c <'SplusDS/preface.aux'`; then
echo shar: \"'SplusDS/preface.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/preface.aux'
fi
if test -f 'SplusDS/preface.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/preface.tex'\"
else
echo shar: Extracting \"'SplusDS/preface.tex'\" \(3713 characters\)
sed "s/^X//" >'SplusDS/preface.tex' <<'END_OF_FILE'
X% -*-latex-*-
X% Document name: Splus.tex
X%
X% Version 2.0, March, 1992
X%
X\maketitle
X\centerline{\huge\bf Preface}
X\addcontentsline{toc}{section}{Preface}
X\lhead[\fancyplain{}{}]{}
X\rhead[\fancyplain{}{}]{}
X\bigskip
XThese notes were originally intended only for local consumption at the
XUniversity of Adelaide, South Australia. After some encouraging comments
Xfrom students, the author decided to release them to a larger readership in
Xthe hope that in some small way they promote good data analysis. \s. (or
X\splus.) is no panacea, of course, but in offering simply a coherent suite
Xof general and flexible tools to devise precisely the right kind of
Xanalysis, rather than a collection of packaged standard analyses, in my
Xview it represents the single complete environment most conducive to good
Xdata analysis so far available.
X
XSome evidence of the local origins of these notes is still awkwardly
Xapparent. For example they use the Tektronics graphics emulations on
Xterminals and workstations, which at the time of writing is still the only
Xone available to the author. The {\sf X11} windowing system, which allows
Xseparate windows for characters and graphics simultaneously to be
Xdisplayed, is much to be preferred and it will be used in later versions.
XAlso the local audience would be very familiar with {\sf MINITAB}, {\sf
XMATLAB}, {\sf Glim} and {\sf Genstat}, and various echoes of these persist.
XAt one point some passing acquaintance with the Australian States is
Xassumed, but the elementary facts are given in a footnote for foreign
Xreaders.
X
XComments and corrections are always welcome. Please address email
Xcorrespondence to the author at {\tt wvenable@stats.adelaide.edu.au}.
X
XThe author is indebted to many people for useful contributions, but in
Xparticular Lucien W.~Van~Elsen, who did the basic \TeX{} to \LaTeX{}
Xconversion and Rick Becker who offered an authoritative and extended
Xcritique on an earlier version. Responsibility for this version, however,
Xremains entirely with the author, and the notes continue to enjoy a fully
Xunofficial and unencumbered status.
X
XThese notes may be freely copied and redistributed for any educational
Xpurpose provided the copyright notice remains intact. Where appropriate, a
Xsmall charge to cover the costs of production and distribution, only, may
Xbe made.
X
X\bigskip
X\rightline{\vbox{\hbox{Bill Venables,}
X \hbox{University of Adelaide,}
X \hbox{16th December, 1990.}}}
X\bigskip
X\centerline{\Large\bf Addendum: Version 2.0, April 1992}
X\bigskip
X
XAs foreshadowed above the present version of the notes contains references
Xto the use of \s. in a workstation environment, although I hope they remain
Xuseful to the user on an ordinary graphics terminal. Of much greater
Ximportance, however, are the language developments that have taken place in
X\s. itself in the August~1991 release. These are only partially addressed
Xin this version of the notes, as a complete coverage would require a
Xdocument of much greater length than was ever intended. I trust however
Xthat the sketches given here are useful and a spur to the reader to seek
Xfurther enlightenment in the standard reference materials.
X
XThe present notes are also centred around \splus. rather than plain vanilla
X\s.. This simply reflects a change in the implementation of \s. made
Xavailable to my students and me by my employer. It should not be read as
Xany sort of endorsement one way or another.
X
XMy sincere thanks to David Smith, James Pearce and Ron Baxter for many
Xuseful suggestions.
X
X\bigskip
X\rightline{\vbox{\hbox{Bill Venables,}
X \hbox{University of Adelaide,}
X \hbox{13th April, 1992.}}}
X
X
X
X
X\newpage
X\tableofcontents
X
END_OF_FILE
if test 3713 -ne `wc -c <'SplusDS/preface.tex'`; then
echo shar: \"'SplusDS/preface.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/preface.tex'
fi
if test -f 'SplusDS/reading.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/reading.aux'\"
else
echo shar: Extracting \"'SplusDS/reading.aux'\" \(1310 characters\)
sed "s/^X//" >'SplusDS/reading.aux' <<'END_OF_FILE'
X\relax
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {7}Reading data from files}{28}}
X\newlabel{reading}{{7}{28}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.1}The {\string\ptt\space scan()} function}{28}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.2}The {\string\ptt\space read.table()} function}{28}}
X\@writefile{lof}{\string\contentsline\space {figure}{\string\numberline\space {2}{\ignorespaces Input file form with names and row labels}}{29}}
X\newlabel{rowlab}{{2}{29}}
X\@writefile{lof}{\string\contentsline\space {figure}{\string\numberline\space {3}{\ignorespaces Input file form without row labels}}{29}}
X\newlabel{norowlab}{{3}{29}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.3}Other facilities; editing data}{29}}
X\global\@namedef{cp@reading}{
X\setcounter{page}{30}
X\setcounter{equation}{0}
X\setcounter{enumi}{6}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{6}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{7}
X\setcounter{subsection}{3}
X\setcounter{subsubsection}{0}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{3}
X\setcounter{table}{0}
X}
END_OF_FILE
if test 1310 -ne `wc -c <'SplusDS/reading.aux'`; then
echo shar: \"'SplusDS/reading.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/reading.aux'
fi
if test -f 'SplusDS/reading.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/reading.tex'\"
else
echo shar: Extracting \"'SplusDS/reading.tex'\" \(5594 characters\)
sed "s/^X//" >'SplusDS/reading.tex' <<'END_OF_FILE'
X% -*-latex-*-
X% Document name: Splus.tex
X%
X% Version 2.0, March, 1992
X%
X\section{Reading data from files}
X\label{reading}
X
XLarge data objects will usually be read as values from external files
Xrather than entered during an \splus. session at the keyboard. This is
Xdone most conveniently with the {\tt scan()} function for simple data
Xitems, and the {\tt read.table()} function for reading entire data
Xframes directly.
X
X\subsection{The {\tt scan()} function}
X
XSuppose the data vectors are of equal length and are to be read in in
Xparallel. Further suppose that there are three vectors, the first of mode
Xcharacter and the remaining two of mode numeric, and the file is {\tt
Xinput.dat}. The first step is to use {\tt scan()} to read in the
Xthree vectors as a list, as follows
X
X\Sprompt in <- scan("input.dat", list("",0,0))
X
XThe second argument is a dummy list structure that establishes
Xthe mode of the three vectors to be read. The result, held in {\tt in}, is
Xa list whose components are the three vectors read in. To separate the
Xdata items into three separate vectors, use assignments like
X
X\Sprompt label <- in[[1]]; x <- in[[2]]; y <- in[[3]]
X
XMore conveniently, the dummy list can have named components, in which case
Xthe names can be used to access the vectors read in. For example
X
X\Sprompt in <- scan("input.dat", list(id="", x=0, y=0))
X
XIf you wish to access the variables separately they may either be
Xre-assigned to variables in the working frame:
X
X\Sprompt label <- in\$id; x <- in\$x; y <- in\$y
X
Xor the list may be attached at position~2 of the search list, (see
X\S\ref{atlist}).
X
XIf the second argument is a single value and not a list, a single vector is
Xread in, all components of which must be of the same mode as the dummy
Xvalue.
X
X\Sprompt X <- matrix(scan("light.dat", 0), ncol=5, byrow=T)
X
XThere are more elaborate input facilities available and these are detailed
Xin the manual.
X
X\subsection{The {\tt read.table()} function}
X
XTo read an entire data frame directly, the external file must have a
Xspecial form.
X\begin{itemize}
X\item The first line of the file should have have a {\sl name\/} for each
Xvariable in the data frame.
X
X\item Each additional line of the file has its first item a {\sl row
Xlabel\/} and the values for each variable.
X\end{itemize}
XIf the file has one fewer item in its first line than in its second, this
Xarrangement is presumed to be in force. So the first few lines of a file
Xto be read as a data frame might look as in Figure~\ref{rowlab}.
X\begin{figure}[ht]
X\hrule\medskip
X\begin{verbatim}
X Price Floor Area Rooms Age Cent.heat
X01 52.00 111.0 830 5 6.2 no
X02 54.75 128.0 710 5 7.5 no
X03 57.50 101.0 1000 5 4.2 no
X04 57.50 131.0 690 6 8.8 no
X05 59.75 93.0 900 5 1.9 yes
X...
X\end{verbatim}
X\caption{\label{rowlab} Input file form with names and row labels}
X\medskip\hrule
X\end{figure}
XBy default numeric items (except row labels) are read as numeric variables
Xand non-numeric variables, such as {\tt Cent.heat} in the example, as
Xfactors. This can be changed if necessary.
X
XThe function {\tt read.table()} can then be used to read the data
Xframe directly
X
X\Sprompt HousePrice <- read.table("houses.data")
X
XOften you will want to omit including the row labels directly and use the
Xdefault labels. In this case the file may omit the row label column as in
XFigure~\ref{norowlab}
X\begin{figure}[ht]
X\hrule\medskip
X\begin{verbatim}
X Price Floor Area Rooms Age Cent.heat
X 52.00 111.0 830 5 6.2 no
X 54.75 128.0 710 5 7.5 no
X 57.50 101.0 1000 5 4.2 no
X 57.50 131.0 690 6 8.8 no
X 59.75 93.0 900 5 1.9 yes
X...
X\end{verbatim}
X\caption{\label{norowlab} Input file form without row labels}
X\medskip\hrule
X\end{figure}
XThe data frame may then be read as
X
X\Sprompt HousePrice <- read.table("houses.data", header=T)
X
Xwhere the {\tt heading=T} option specifies that the first line is a line of
Xheadings, and hence, by implication from the form of the file, that no
Xexplicit row labels are given.
X
X\subsection{Other facilities; editing data}
X
X\splus. input facilities are simple and their requirements are fairly strict.
XThere is a clear presumption that rather than use \splus. to accommodate a
Xsubtle variety of input, (and more so output), protocols you will be able
Xto modify your input files using other tools, such file editors and the
X{\sf UNIX} utilities {\tt sed} and {\tt awk} to fit in with the
Xrequirements of \splus. Generally this very simple.
X
XThere is, however, a function {\tt make.fields()} that can be used to
Xconvert a file with fixed width, non separated, input fields into a file
Xwith separated fields. There is also a facility {\tt count.fields()}
Xthat will count the number of fields on each line of such a file.
XOccasionally for very simple conversion and checking problems these may be
Xadequate to the task, but in most cases it is better to do the preliminary
Xspade work before the \splus. session begins.
X
XOnce a data set has been read, there is an {\sf X--}window based facility
Xin \splus. for making small changes. The command
X
X\Sprompt xnew <- data.ed(xold)
X
Xwill allow you to edit your data set {\tt xold} using a spread\-sheet-like
Xenvironment in a separate editing window, and on completion the changed
Xobject is assigned to {\tt xnew}. {\tt xold}, and hence {\tt xnew}, can be
Xany matrix, vector, data frame, or atomic data object.
X
END_OF_FILE
if test 5594 -ne `wc -c <'SplusDS/reading.tex'`; then
echo shar: \"'SplusDS/reading.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/reading.tex'
fi
if test -f 'SplusDS/session.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/session.aux'\"
else
echo shar: Extracting \"'SplusDS/session.aux'\" \(600 characters\)
sed "s/^X//" >'SplusDS/session.aux' <<'END_OF_FILE'
X\relax
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {A}{\string\psf\space S-PLUS}: An Introductory Session}{61}}
X\newlabel{intro}{{A}{61}}
X\global\@namedef{cp@session}{
X\setcounter{page}{64}
X\setcounter{equation}{1}
X\setcounter{enumi}{6}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{8}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{1}
X\setcounter{subsection}{0}
X\setcounter{subsubsection}{2}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{11}
X\setcounter{table}{4}
X}
END_OF_FILE
if test 600 -ne `wc -c <'SplusDS/session.aux'`; then
echo shar: \"'SplusDS/session.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/session.aux'
fi
if test -f 'SplusDS/session.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/session.tex'\"
else
echo shar: Extracting \"'SplusDS/session.tex'\" \(7935 characters\)
sed "s/^X//" >'SplusDS/session.tex' <<'END_OF_FILE'
X% -*-latex-*-
X% Document name: Splus.tex
X%
X% Version 2.0, March, 1992
X%
X%
X% \addcontentsline{toc}{section}{APPENDIX: A List of \s. Functions}
X% \lhead[\fancyplain{}{\small\sf\thepage}]{\fancyplain{}{\small\sf A List of
X% \s. Functions}}
X% \rhead[\fancyplain{}{\small\sf A List of \s.
X% Functions}]{\fancyplain{}{\small\sf\thepage}}
X{
X% Various TeX muckings around. Dammit.
X\def\strutt{\vrule height 3ex depth 0ex width 0em}
X\def\separate{\noalign{\goodbreak\medskip\hrule\medskip}}
X\def\splus.{{\sf S-PLUS}}
X\newdimen\leftdim
X\leftdim=2truein
X\newdimen\rightdim
X\rightdim=\hsize
X\advance\rightdim by -\leftdim
X\advance\rightdim by -8pt
X
X\section{\splus.: An Introductory Session}
X\label{intro}
XThe following session is intended to introduce to you some features of the
X\splus. environment by using them. Many features of the system will be
Xunfamiliar and puzzling at first, but this will soon disappear.
X
X{\raggedbottom
X\tabskip=0pt
X\halign to \hsize{\vtop{\hsize=\leftdim \parindent=0pt\parskip=0pt\tt
X\obeylines\strutt#}\tabskip=50pt plus 50pt minus 50pt
X&\vtop{%\raggedright
X\hsize=\rightdim\parindent=0pt#}\tabskip=0pt\cr
X\separate
Xlogin:
X\ldots
X> ls -a
X> ls -a .Data
X&
XLogin, start your windowing system (ask a demonstrator if you need help),
Xand check that your working directory has a subdirectory {\tt .Data},
Xwhich in turn contains the files {\tt .First}, {\tt .Last} and possibly
X{\tt .Audit}.\par
XYou should also have the file {\tt morley.data} in your
Xworking directory. If not, see a demonstrator. If you have, proceed.
X\cr
X> Splus -e
X&
XStart {\tt Splus\/} with the inbuilt command line editor enabled.
X\cr
X\separate
X&
XThe \splus. program begins, with a banner.
X
X{\small (Within \splus. the prompt on the left hand side will not be shown
Xto avoid confusion.)}
X\cr
Xhelp.findsum(".Data")
X&
XSet things up for the {\tt help} facility. (Need only be done once for
Xthis directory.)
X\cr
Xhelp.start()
X&
XStart the help facility. You should briefly explore the features of this
Xfacility with the mouse. Standard $X-$window conventions apply.
X
XIconify
Xthe help window and move on to the next part.
X\cr
Xmotif()
X&
XTurn on the graphics window. You may need to re-position and re-size to
Xmake it convenient to work with both windows.
X\cr
X\separate
Xx <- rnorm(50)
Xy <- rnorm(x)
X&
XGenerate two pseudo random normal vectors of $x-$ and $y-$co\-ord\-in\-ates.
X\cr
Xhull <- chull(x, y)
X&
XFind their convex hull in the plane.
X\cr
Xplot(x, y)
Xpolygon(x[hull], y[hull],
X\quad dens=15)
X&
XPlot the points in the plane, and mark in their convex hull.
X\cr
Xobjects()
X&
XSee which \splus. objects are now in the {\tt .Data} directory.
X\cr
Xrm(x,y,hull)
X&
XRemove objects no longer needed. (cleanup).
X\cr
X\separate
Xx <- 1:20
X&
XMake $x = (1,2,\ldots,20)$
X\cr
Xw <- 1 + sqrt(x)/2
X&
XA `weight' vector of standard deviations.
X\cr
Xdummy <- data.frame(x=x,
X\quad y= x + rnorm(x)*w)
Xdummy
X&
XMake a {\it data frame\/} of two columns, $x$ and $y$, and look at it.
X\cr
Xfm <- lm(y\~{}x, data=dummy)
Xsummary(fm)
X&
XFit a simple linear regression of $y$ on $x$ and look at the analysis.
X\cr
Xfm1 <- lm(y\~x, data=dummy,
X\quad weight=1/w\**2)
Xsummary(fm1)
X&
XSince we know the standard deviations, we can do a weighted regression.
X\cr
Xlrf <- loess(y\~{}x, dummy)
X&
XMake a nonparametric local regression function.
X\cr
Xattach(dummy)
X&
XMake the columns in the data frame visible as variables.
X\cr
Xplot(x, y)
X&
XStandard point plot.
X\cr
Xlines(x, fitted(lrf))
X&
XAdd in the local regression.
X\cr
Xabline(0, 1, lty=3)
X&
XThe true regression line: (intercept 0, slope 1).
X\cr
Xabline(coef(fm))
X&
XUnweighted regression line.
X\cr
Xabline(coef(fm1),lty=4)
X&
XWeighted regression line.
X\cr
X&
XAt any time you can make a hardcopy of the graphics window by clicking on
Xthe {\tt Graph} section of the window and selecting the {\tt Print} option.
X\cr
Xdetach()
X&
XRemove data frame from the search list.
X\cr
Xplot(fitted(fm),
X\quad resid(fm),
X\quad xlab="Fitted values",
X\quad ylab="Residuals", main=
X\quad "Residuals vs Fitted")
X&
XA standard regression diagnostic plot to check for heteroscedasticity. Can
Xyou see it?
X\cr
Xqqnorm(resid(fm), main=
X\quad "Residuals Rankit Plot")
X&
XA normal scores plot to check for skewness, kurtosis and outliers. (Not
Xvery useful here.)
X\cr
Xrm(fm,fm1,lrf,x,dummy)
X&
XClean up again.
X\cr
X\separate
X&
XThe next section will look at data from the classical experiment of
XMichaelson and Morley to measure the speed of light.
X\cr
X!more morley.data
X&
XOptional. Temporarily interrupt \splus. and look at the file. This is
Xa standard way to escape to the operating system.
X\cr
Xmm <-
X read.table("morley.data")
Xmm
X&
XRead in the MM data as a data frame, and look at it. There are five
Xexperiments (col.\ {\tt Expt}) and each has 20 runs (col.\ {\tt Run}) and {\tt
Xsl} is the recorded speed of light, suitably coded.
X\cr
Xattach(mm, 1)
Xobjects()
X&
XPlace {\tt mm} on the top of the search list, (position 1).
X\cr
XExpt <- factor(Expt)
XRun <- factor(Run)
X&
XChange {\tt Expt} and {\tt Run} into factors.
X\cr
Xdetach(1, save="mm")
Xattach(mm)
X&
XSave the changes and
Xmake the data frame visible at position 2 (the default).
X\cr
Xplot(Expt,Speed, main=
X "Michaelson Morley Data",
X xlab="Experiment No.")
X&
XCompare the five experiments with simple boxplots.
X\cr
Xfm <- aov(Speed\~Run+Expt,
X\quad data=mm)
Xsummary(fm)
X&
XAnalyse as a randomized block, with `runs' and `experiments' as factors.
X\cr
Xfm0 <- update(fm,
X\quad .\~.-Run)
Xanova(fm0,fm)
X&
XFit the sub-model omitting `runs', and compare using a formal analysis of
Xvariance.
X\cr
Xdetach()
Xrm(fm, fm0)
X&
XCleanup before moving on.
X\cr
X\separate
X&
XWe now look at some more graphical features: contour and
X$3-$dimensional perspective plots.
X\cr
Xx <- seq(-pi, pi, len=50)
Xy <- x
X&
X$x$ is a vector of 50 equally spaced values in $-\pi\leq x \leq \pi$. $y$
Xis the same.
X\cr
Xf <- outer(x, y,
X\quad function(x,y)
X\qquad cos(y)/(1+x\**2))
X&
X$f$ is a square matrix, with rows and columns indexed by $x$ and $y$
Xrespectively, of values of the function $\cos(y)/(1+x^2)$.
X\cr
Xoldpar <- par()
Xpar(pty="s")
X&
XSave the plotting parameters and set the plotting region to ``square''.
X\cr
Xcontour(x, y, f)
Xcontour(x, y, f,
X\quad nint=15, add=T)
X&
XMake a contour map of $f$; add in more lines for more detail.
X\cr
Xfa <- (f-t(f))/2
X&{\tt fa} is the ``asymmetric part'' of $f$. ({\tt t()} is transpose).
X\cr
Xcontour(x, y, fa, nint=15)
X&
XMake a contour, and
X\cr
Xpar(oldpar)
X&
Xrestore the old graphics parameters.
X\cr
Xpersp(x, y, f)
Xpersp(x, y, fa)
Ximage(x, y, f)
Ximage(x, y, fa)
X&
XMake some pretty perspective and high density image plots, (of which you
Xcan get hardcopies if you wish)
X\cr
Xobjects(); rm(x,y,f,fa)
X&
Xand clean up before moving on.
X\cr
X\separate
Xth <- seq(-pi, pi,
X\quad len=100)
Xz <- exp(1i*th)
X&
X\splus. can do complex arithmetic, also. {\tt 1i} is used for the
Xcomplex number $i$
X\cr
Xpar(pty="s")
Xplot(z, type="l")
X&
XPlotting complex arguments means plot imaginary versus real parts. This
Xshould be a circle.
X\cr
Xw <- rnorm(100) +
X\qquad rnorm(100)*1i
X&
XSuppose we want to sample points within the unit circle. One method would
Xbe to take complex numbers with standard normal real and imaginary parts --
X\cr
Xw <- ifelse(Mod(w) > 1,
X\quad 1/w, w)
X&
Xand to map any outside the circle onto their reciprocal.
X\cr
Xplot(w, xlim=c(-1,1),
X\quad ylim=c(-1,1), pch="+",
X\quad xlab="x", ylab="y")
Xlines(z)
X&
XAll points are inside the unit circle, but the distribution is not uniform.
X\cr
Xw <- sqrt(runif(100))*
X\quad exp(2*pi*runif(100)*1i)
Xplot(w, xlim=c(-1,1),
Xylim=c(-1,1), pch="+",
Xxlab="x", ylab="y")
Xlines(z)
X&
XThe second method uses the uniform distribution. The points should now
Xlook more evenly spaced over the disc.
X\cr
Xrm(th,w,z)
X&
XCleanup again.
X\cr
X\separate
Xpar(oldpar)
X&
XRestore standard graphics parameters.
X\cr
Xbutterfly()
X&
XAn old favourite. Take a hardcopy if you wish.
X\cr
Xrm(oldpar)
X&
XCleanup again.
X\cr
Xq()
X&
XQuit the {\splus.} program.
X\cr
X>
X&
Xand return to {\tt Unix}.
X\cr
X\separate}}
X
X }
END_OF_FILE
if test 7935 -ne `wc -c <'SplusDS/session.tex'`; then
echo shar: \"'SplusDS/session.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/session.tex'
fi
if test -f 'SplusDS/simple.aux' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/simple.aux'\"
else
echo shar: Extracting \"'SplusDS/simple.aux'\" \(1398 characters\)
sed "s/^X//" >'SplusDS/simple.aux' <<'END_OF_FILE'
X\relax
X\@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {2}Simple manipulations; numbers and vectors}{6}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.1}Vectors}{6}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.2}Vector arithmetic}{6}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.3}Generating regular sequences}{7}}
X\newlabel{regseq}{{2.3}{7}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.4}Logical vectors}{8}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.5}Missing values}{8}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.6}Character vectors}{8}}
X\@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.7}Index vectors. Selecting and modifying subsets of a data set}{9}}
X\global\@namedef{cp@simple}{
X\setcounter{page}{11}
X\setcounter{equation}{0}
X\setcounter{enumi}{6}
X\setcounter{enumii}{0}
X\setcounter{enumiii}{0}
X\setcounter{enumiv}{0}
X\setcounter{footnote}{2}
X\setcounter{mpfootnote}{0}
X\setcounter{part}{0}
X\setcounter{section}{2}
X\setcounter{subsection}{7}
X\setcounter{subsubsection}{0}
X\setcounter{paragraph}{0}
X\setcounter{subparagraph}{0}
X\setcounter{figure}{0}
X\setcounter{table}{0}
X}
END_OF_FILE
if test 1398 -ne `wc -c <'SplusDS/simple.aux'`; then
echo shar: \"'SplusDS/simple.aux'\" unpacked with wrong size!
fi
# end of 'SplusDS/simple.aux'
fi
if test -f 'SplusDS/simple.tex' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/simple.tex'\"
else
echo shar: Extracting \"'SplusDS/simple.tex'\" \(13215 characters\)
sed "s/^X//" >'SplusDS/simple.tex' <<'END_OF_FILE'
X% -*-latex-*-
X% Document name: Splus.tex
X%
X% Version 2.0, March, 1992
X%
X\section{Simple manipulations; numbers and vectors}
X
X\subsection{Vectors}
X
X\splus. operates on named {\sl data structures\/}. The simplest such structure
Xis the {\sl vector\/}, which is a single entity consisting of an ordered
Xcollection of numbers. To set up a vector named {\tt x}, say, consisting
Xof five numbers, namely $10.4$, $5.6$, $3.1$, $6.4$ and $21.7$, use the \splus.
Xcommand
X
X\Sprompt x <- c(10.4, 5.6, 3.1, 6.4, 21.7)
X
XThis is an {\sl assignment\/} statement using the {\sl function\/} {\tt
Xc()} which in this context can take an arbitrary number of vector
X{\sl arguments\/} and whose value is a vector got by concatenating its
Xarguments end to end.\footnote{With other than vector types of argument,
Xsuch as {\tt list} mode arguments, the action of {\tt c()} is at first
Xsight rather different. See \S\ref{cwithlists}.}
X
XA number occurring by itself in an expression is taken as a vector of
Xlength one.
X
XNotice that the assignment operator is {\bf not} the usual {\tt =}
Xoperator, which is reserved for another purpose. It consists of the two
Xcharacters {\tt<} (`less than') and {\tt-} (`minus') occurring strictly
Xside-by-side and it `points' to the structure receiving the value of the
Xexpression. Assignments can also be made in the other direction, using the
Xobvious change in the assignment operator. So the same assignment could be
Xmade using
X
X\Sprompt c(10.4, 5.6, 3.1, 6.4, 21.7) -> x
X
XIf an expression is used as a complete command, the value is printed {\sl
Xand lost\/}. So now if we were to use the command
X
X\Sprompt 1/x
X
Xthe reciprocals of the five values would be printed at the
Xterminal (and the value of {\tt x}, of course, unchanged).
X
XThe further assignment
X
X\Sprompt y <- c(x, 0, x)
X
Xwould create a vector {\tt y} with $11$ entries consisting of two
Xcopies of {\tt x} with a zero in the middle place.
X
X\subsection{Vector arithmetic}
X
XVectors can be used in arithmetic expressions, in which case the operations
Xare performed element by element. Vectors occurring in the same expression
Xneed not all be of the same length. If they are not, the value of the
Xexpression is a vector with the same length as the longest vector which
Xoccurs in the expression. Shorter vectors in the expression are {\sl
Xrecycled\/} as often as need be (perhaps fractionally) until they match the
Xlength of the longest vector. In particular a constant is simply repeated.
XSo with the above assignments the command
X
X\Sprompt v <- 2*x + y + 1
X
Xgenerates a new vector {\tt v} of length $11$ constructed by
Xadding together, element by element, {\tt 2*x} repeated $2.2$ times, {\tt
Xy} repeated just once, and {\tt 1} repeated $11$ times.
X
XThe elementary arithmetic operators are the usual {\tt+}, {\tt-}, {\tt*},
X{\tt/} and {\tt\^} for raising to a power. In addition all of the common
Xarithmetic functions are available. {\tt log}, {\tt exp}, {\tt sin}, {\tt
Xcos}, {\tt tan}, {\tt sqrt}, and so on, all have their usual meaning. {\tt
Xmax} and {\tt min} select the largest and smallest elements of an vector
Xrespectively. {\tt range} is a function whose value is a vector of length
Xtwo, namely {\tt c(min(x), max(x))}. {\tt length(x)} is the number of
Xelements in {\tt x}, {\tt sum(x)} gives the total of the elements in {\tt
Xx} and {\tt prod(x)} their product.
X
XTwo statistical functions are {\tt mean(x)} which calculates the sample
Xmean, which is the same as {\tt sum(x)/length(x)}, and {\tt var(x)} which
Xgives
X\begin{center}
X{\tt sum((x-mean(x))\^2)/(length(x)-1)}
X\end{center}
Xor sample variance. If the argument to {\tt var()} is an $n\times p$
Xmatrix the value is a $p\times p$ sample covariance matrix got by regarding
Xthe rows as independent $p-$variate sample vectors.
X
X{\tt sort(x)} returns a vector of the same size as {\tt x} with the
Xelements arranged in increasing order; however there are other more
Xflexible sorting facilities available (see {\tt order()} or {\tt
Xsort.list()} which produce a permutation to do the sorting).
X
X{\tt rnorm(x)} is a function which generates a vector (or more generally an
Xarray) of pseudo-random standard normal deviates, of the same size as {\tt
Xx}.
X
X\subsection{Generating regular sequences}
X\label{regseq}
X\splus. has a number of facilities for generating commonly used sequences of
Xnumbers. For example {\tt 1:30} is the vector {\tt c(1,2, \ldots,29,30)}.
XThe colon operator has highest priority within an expression, so, for
Xexample {\tt 2*1:15} is the vector {\tt c(2,4,6, \ldots,28,30)}. Put {\tt n
X<- 10} and compare the sequences \quad {\tt 1:n-1} \quad and \quad {\tt
X1:(n-1)}.
X
XThe construction {\tt 30:1} may be used to generate a sequence backwards.
X
XThe function {\tt seq()} is a more general facility for generating
Xsequences. It has five arguments, only some of which may be specified in
Xany one call. The first two arguments, if given, specify the beginning and
Xend of the sequence, and if these are the only two arguments given the
Xresult is the same as the colon operator. That is {\tt seq(2,10)} is the
Xsame vector as {\tt 2:10}.
X
XParameters to {\tt seq()}, and to many other \splus. functions, can also
Xbe given in named form, in which case the order in which they appear is
Xirrelevant. The first two parameters may be named {\tt from={\sl value}}
Xand {\tt to={\sl value}}; thus {\tt seq(1,30)}, {\tt seq(from=1, to=30)} and
X{\tt seq(to=30, from=1)} are all the same as {\tt 1:30}. The next two
Xparameters to {\tt seq()} may be named {\tt by={\sl value}} and {\tt
Xlength={\sl value}}, which specify a step size and a length for the
Xsequence respectively. If neither of these is given, the default {\tt
Xby=1} is assumed.
X
XFor example
X
X\Sprompt seq(-5, 5, by=.2) -> s3
X
Xgenerates in {\tt s3} the vector {\tt c(-5.0, -4.8, -4.6, \ldots, 4.6, 4.8,
X5.0)}. Similarly
X
X\Sprompt s4 <- seq(length=51, from=-5, by=.2)
X
Xgenerates the same vector in {\tt s4}.
X
XThe fifth parameter may be named {\tt along={\sl vector}}, which if used
Xmust be the only parameter, and creates a sequence {\tt 1, 2, \ldots,
Xlength({\sl vector\/})}, or the empty sequence if the vector is empty (as
Xit can be).
X
XA related function is {\tt rep()} which can be used for replicating a
Xstructure in various complicated ways. The simplest form is
X
X\Sprompt s5 <- rep(x, times=5)
X
Xwhich will put five copies of {\tt x} end-to-end in {\tt s5}.
X
X\subsection{Logical vectors}
X
XAs well as numerical vectors, \splus. allows manipulation of logical
Xquantities. The elements of a logical vectors have just two possible
Xvalues, represented formally as {\tt F} (for `false') and {\tt T} (for
X`true').
X
XLogical vectors are generated by {\sl conditions\/}. For example
X
X\Sprompt temp <- x>13
X
Xsets {\tt temp} as a vector of the same length as {\tt x} with
Xvalues {\tt F} corresponding to elements of {\tt x} where the condition is
X{\sl not\/} met and {\tt T} where it is.
X
XThe logical operators are {\tt <}, {\tt <=}, {\tt >}, {\tt >=}, {\tt ==}
Xfor exact equality and {\tt !=} for inequality. In addition if {\tt c1}
Xand {\tt c2} are logical expressions, then {\tt c1$\,$\&$\,$c1} is their
Xintersection, {\tt c1$\,$|$\,$c2} is their union and {\tt !$\,$c1} is the
Xnegation of {\tt c1}.
X
XLogical vectors may be used in ordinary arithmetic, in which case they are
X{\sl coerced\/} into numeric vectors, {\tt F} becoming {\tt 0} and {\tt T}
Xbecoming {\tt 1}. However there are situations where logical vectors and
Xtheir coerced numeric counterparts are not equivalent, for example see the
Xnext subsection.
X
X\subsection{Missing values}
XIn some cases the components of a vector may not be completely known. When
Xan element or value is ``not available'' or a ``missing value'' in the
Xstatistical sense, a place within a vector may be reserved for it by
Xassigning it the special value {\tt NA}. In general any operation on an
X{\tt NA} becomes an {\tt NA}. The motivation for this rule is simply that
Xif the specification of an operation is incomplete, the result cannot be
Xknown and hence is not available.
X
XThe function {\tt is.na(x)} gives a logical vector of the same size as {\tt
Xx} with value {\tt T} if and only if the corresponding element in {\tt x}
Xis {\tt NA}.
X
X\Sprompt ind <- is.na(z)
X
XNotice that the logical expression {\tt x == NA} is quite different from
X{\tt is.na(x)} since {\tt NA} is not really a value but a marker for a
Xquantity that is not available. Thus {\tt x == NA} is a vector of the same
Xlength as {\tt x} {\sl all\/} of whose values are {\tt NA} as the logical
Xexpression itself is incomplete and hence undecidable.
X
X\subsection{Character vectors}
X
XCharacter quantities and character vectors are used frequently in \splus., for
Xexample as plot labels. Where needed they are denoted by a sequence of
Xcharacters delimited by the double quote character. E. g. {\tt
X"x-values"}, {\tt "New iteration results"}.
X
XCharacter vectors may be concatenated into a vector by the {\tt c()}
Xfunction; examples of their use will emerge frequently.
X
XThe {\tt paste()} function takes an arbitrary number of arguments and
Xconcatenates them into a single character string. Any numbers given among
Xthe arguments are coerced into character strings in the evident way, that
Xis, in the same way they would be if they were printed. The arguments are
Xby default separated in the result by a single blank character, but this
Xcan be changed by the named parameter, {\tt sep={\sl string\/}}, which
Xchanges it to {\tt {\sl string\/}}, possibly empty.
X
XFor example
X
X\Sprompt labs <- paste(c("X","Y"), 1:10, sep="")
X
Xmakes {\tt labs} into the character vector
X\begin{center}
X{\tt ("X1", "Y2", "X3", "Y4", "X5", "Y6", "X7", "Y8", "X9", "Y10")}
X\end{center}
XNote particularly that recycling of short lists takes place here too; thus
X{\tt c("X", "Y")} is repeated $5$ times to match the sequence {\tt 1:10}.
X
X\subsection{Index vectors. Selecting and modifying subsets of a data set}
X
XSubsets of the elements of a vector may be selected by appending to the
Xname of the vector an {\sl index vector\/} in square brackets. More
Xgenerally any expression that evaluates to a vector may have subsets of its
Xelements similarly selected be appending an index vector in square brackets
Ximmediately after the expression.
X
XSuch index vectors can be any of four distinct types.
X
X\begin{description}
X
X\item[1. A logical vector.] In this case the index vector must be of the
Xsame length as the vector from which elements are to be selected. Values
Xcorresponding to {\tt T} in the index vector are selected and those
Xcorresponding to {\tt F} omitted. For example
X
X\Sprompt y <- x[!is.na(x)]
X
Xcreates (or re-creates) an object {\tt y} which will contain the
Xnon-missing values of {\tt x}, in the same order. Note that if {\tt x} has
Xmissing values, {\tt y} will be shorter than {\tt x}. Also
X
X\Sprompt (x+1)[(!is.na(x)) \& x>0] -> z
X
Xcreates an object {\tt z} and places in it the values of the vector {\tt
Xx+1} for which the corresponding value in {\tt x} was both non-missing and
Xpositive.
X
X\item[2. A vector of positive integral quantities.] In this case the
Xvalues in the index vector must lie in the the set $\lbrac${\tt 1, 2, \ldots,
Xlength(x)}$\rbrac$. The corresponding elements of the vector are selected and
Xconcatenated, {\sl in that order\/}, in the result. The index vector can
Xbe of any length and the result is of the same length as the index vector.
XFor example {\tt x[6]} is the sixth component of {\tt x} and
X
X\Sprompt x[1:10]
X
Xselects the first 10 elements of {\tt x}, (assuming {\tt length(x)}
X$\geq$ {\tt 10}). Also
X
X\Sprompt c("x","y")[rep(c(1,2,2,1), times=4)]
X
X(an admittedly unlikely thing to do) produces a character vector of
Xlength 16 consisting of {\tt "x", "y", "y", "x"} repeated four times.
X
X\item[3. A vector of negative integral quantities.] Such an
Xindex vector specifies the values to be {\sl excluded\/} rather than
Xincluded. Thus
X
X\Sprompt y <- x[-(1:5)]
X
Xgives {\tt y} all but the first five elements of {\tt x}.
X
X\item[4. A vector of character strings.] This possibility only applies
Xwhere an object has a {\tt names} attribute to identify its components. In
Xthis case a subvector of the names vector may be used in the same way as
Xthe positive integral labels in 2.\ above.
X
X\Sprompt lunch <- fruit[c("apple","orange")]
X
XThis option is particularly useful in connection with data frames, as we
Xshall see later.
X\end{description}
X
XAn indexed expression can also appear on the receiving end of an
Xassignment, in which case the assignment operation is performed {\sl only
Xon those elements of the vector\/}. The expression must be of the form
X{\tt vector[{\sl index\_vector\/}]} as having an arbitrary expression in
Xplace of the vector name does not make much sense here.
X
XThe vector assigned must match the length of the index vector, and in the
Xcase of a logical index vector it must again be the same length as the
Xvector it is indexing.
X
XFor example
X
X\Sprompt x[is.na(x)] <- 0
X
Xreplaces any missing values in {\tt x} by zeros and
X
X\Sprompt y[y<0] <- -y[y<0]
X
Xhas the same effect as
X
X\Sprompt y <- abs(y)\footnote{Note that {\tt abs()} does not work as
Xexpected with complex arguments. The appropriate function for the complex
Xmodulus is {\tt Mod()}.}\par
X
END_OF_FILE
if test 13215 -ne `wc -c <'SplusDS/simple.tex'`; then
echo shar: \"'SplusDS/simple.tex'\" unpacked with wrong size!
fi
# end of 'SplusDS/simple.tex'
fi
if test -f 'SplusDS/titlepage.sty' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'SplusDS/titlepage.sty'\"
else
echo shar: Extracting \"'SplusDS/titlepage.sty'\" \(601 characters\)
sed "s/^X//" >'SplusDS/titlepage.sty' <<'END_OF_FILE'
X% titlepage.sty 27 Jan 85
X\def\maketitle{\begin{titlepage}
X\let\footnotesize\small \let\footnoterule\relax \setcounter{page}{0}
X\null
X\vfil
X\vskip 60pt \begin{center}
X{\LARGE \@title \par} \vskip 3em {\large \lineskip .75em
X\begin{tabular}[t]{c}\@author
X\end{tabular}\par}
X\vskip 1.5em {\large \@date \par} \end{center} \par
X\@thanks
X\vfil
X\null
X\end{titlepage}
X\setcounter{footnote}{0} \let\thanks\relax
X\gdef\@thanks{}\gdef\@author{}\gdef\@title{}\let\maketitle\relax}
X\def\abstract{\titlepage
X\null\vfil
X\begin{center}
X{\bf Abstract}
X\end{center}}
X\def\endabstract{\par\vfil\null\endtitlepage}
END_OF_FILE
if test 601 -ne `wc -c <'SplusDS/titlepage.sty'`; then
echo shar: \"'SplusDS/titlepage.sty'\" unpacked with wrong size!
fi
# end of 'SplusDS/titlepage.sty'
fi
echo shar: End of shell archive.
exit 0