[IPSUR-commits] r107 - pkg/IPSUR/inst/doc
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Dec 28 19:21:20 CET 2009
Author: gkerns
Date: 2009-12-28 19:21:19 +0100 (Mon, 28 Dec 2009)
New Revision: 107
Modified:
pkg/IPSUR/inst/doc/IPSUR.Rnw
Log:
a lot
Modified: pkg/IPSUR/inst/doc/IPSUR.Rnw
===================================================================
--- pkg/IPSUR/inst/doc/IPSUR.Rnw 2009-12-27 13:47:51 UTC (rev 106)
+++ pkg/IPSUR/inst/doc/IPSUR.Rnw 2009-12-28 18:21:19 UTC (rev 107)
@@ -23,6 +23,7 @@
\usepackage{url}
\usepackage{amsthm}
\usepackage{amsmath}
+\makeindex
\usepackage{setspace}
\usepackage{amssymb}
\setstretch{1.2}
@@ -477,7 +478,13 @@
and Statistical Inference} by Hogg and Tanis, \emph{Statistical Inference}
by Casella and Berger, and \emph{Theory of Point Estimation/Testing
Statistical Hypotheses} by Lehmann. I highly recommend each of those
-books to every reader of this one.
+books to every reader of this one. Some \textsf{R} books with {}``introductory''
+in the title that I recommend are \emph{Introductory Statistics with
+}\textsf{\emph{R}} by Dalgaard and \emph{Using }\textsf{\emph{R}}\emph{
+for Introductory Statistics} by Verzani. Surely there are many, many
+other good introductory books about \textsf{R}, but frankly, I have
+tried to steer clear of them for the past year or so to avoid any
+undue influence on my own writing.
Please bear in mind that the title of this book is {}``Introduction
to Probability and Statistics Using \textsf{R}'', and not {}``Introduction
@@ -497,7 +504,7 @@
\begin{description}
\item [{Better~data:}] the data analyzed in this book are almost entirely
from the \inputencoding{latin9}\lstinline[showstringspaces=false]!datasets!\inputencoding{utf8}
-package in base \textsf{R}. Here is why:
+package in base \textsf{R}, and here is why:
\begin{enumerate}
\item I made a conscious effort to minimize dependence on contributed packages,
@@ -643,25 +650,23 @@
These are extra materials that accompany \IPSUR.
\begin{description}
\item [{\texttt{IPSUR.RData}}] is a saved image of the \textsf{R} workspace
-at the completion of the Sweave processing of \IPSUR. This can be
-loaded into memory with \textsf{File} $\triangleright$ \textsf{Load
-Workspace} or with the command \inputencoding{latin9}\lstinline[showstringspaces=false]!load("/path/to/IPSUR.Rdata")!\inputencoding{utf8}.
-Loading it into \textsf{R} will make every single object in the \textsf{R}
-workspace immediately available and in memory. In particular, the
-data BLANK from Exercise BLANK in Chapter BLANK on page BLANK will
-be loaded. Type BLANK at the command line to see for yourself.
+at the completion of the Sweave processing of \IPSUR. It can be loaded
+into memory with \textsf{File} $\triangleright$ \textsf{Load Workspace}
+or with the command \inputencoding{latin9}\lstinline[showstringspaces=false]!load("/path/to/IPSUR.Rdata")!\inputencoding{utf8}.
+Either method will make every single object in the file immediately
+available and in memory. In particular, the data BLANK from Exercise
+BLANK in Chapter BLANK on page BLANK will be loaded. Type BLANK at
+the command line to see for yourself.
\item [{\texttt{IPSUR.R}}] is the exported \textsf{R} code from \inputencoding{latin9}\lstinline[showstringspaces=false]!IPSUR.Rnw!\inputencoding{utf8}.
With this script, literally every \textsf{R} command from the entirety
-of \IPSUR\ can be resubmitted at the command line. Note that the
-\inputencoding{latin9}\lstinline[showstringspaces=false]!set.seed!\inputencoding{utf8}
-line at the top should be deleted before distributing to students.
+of \IPSUR\ can be resubmitted at the command line.
\end{description}
\section*{Notation}
We use the notation \inputencoding{latin9}\lstinline[showstringspaces=false]!x!\inputencoding{utf8}
-for simple objects, and use \inputencoding{latin9}\lstinline[showstringspaces=false]!stem.leaf!\inputencoding{utf8}
-notation to denote functions. The sequence {}``\textsf{Statistics}
+or \inputencoding{latin9}\lstinline[showstringspaces=false]!stem.leaf!\inputencoding{utf8}
+notation to denote objects, functions, \emph{etc}. The sequence {}``\textsf{Statistics}
\textsf{$\triangleright$} \textsf{Summaries} \textsf{$\triangleright$}
\textsf{Active Dataset}'' means to click the \textsf{Statistics}
menu item, next click the \textsf{Summaries} submenu item, and finally
@@ -767,9 +772,7 @@
\chapter{An Introduction to \textsf{R}}
This chapter is designed to help a person to begin to get to know
-the \textsf{R} statistical computing environment. It paraphrases and
-summarizes information gleaned from materials listed in the \textbf{References}.
-Please refer to them for a more complete treatment.
+the \textsf{R} statistical computing environment.
\paragraph*{What do I want them to know?}
@@ -777,18 +780,8 @@
\item don't forget to mention rounding issues
\item basic information about how to install, start up, and interact with\textsf{
R}
-
-\begin{itemize}
-\item different platforms, the console, the terminal
-\item external programs such as Tinn-R, Emacs, or Eclipse
-\end{itemize}
\item how to use \textsf{R} like a calculator (essentially arithmetic with
\textsf{R})
-
-\begin{itemize}
-\item basic mathematical functions
-\item would like to mention complex arithmetic
-\end{itemize}
\item what variables are and how to name them
\item about vectors
@@ -798,7 +791,7 @@
\end{itemize}
\item how to type in data, with c() and scan() enter data,
\item how to import data frames from packages, and how to import data from
-elsewhere ? (this last one)
+elsewhere?
\item need to know about vectors and (data frames) the different types of
vectors (numeric, character, logical)
\item how to get help
@@ -839,11 +832,11 @@
\item [{MacOS:}] \url{http://cran.r-project/bin/macosx}
\item [{Linux:}] \url{http://cran.r-project/bin/linux}
\end{description}
-On MS-Windows, click the \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!.exe!\inputencoding{utf8}
+On MS-Windows, click the \inputencoding{latin9}\lstinline[showstringspaces=false]!.exe!\inputencoding{utf8}
program file to start installation. When it asks for \textquotedbl{}Customized
startup options\textquotedbl{}, specify \textsf{Yes}. In the next
window, be sure to select the SDI (single-window) option; this is
-useful later when we discuss three dimensional plots with the \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!rgl!\inputencoding{utf8}
+useful later when we discuss three dimensional plots with the \inputencoding{latin9}\lstinline[showstringspaces=false]!rgl!\inputencoding{utf8}
package.
@@ -862,7 +855,7 @@
called {}``\textsf{R} Core''. In addition to the base packages,
there are literally thousands of additional contributed packages written
by individuals all over the world. These are stored worldwide on mirrors
-of the Comprehensive \textsf{R} Archive Network, or \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!CRAN!\inputencoding{utf8}
+of the Comprehensive \textsf{R} Archive Network, or \inputencoding{latin9}\lstinline[showstringspaces=false]!CRAN!\inputencoding{utf8}
for short. Given an active Internet connection, anybody is free to
download and install these packages and even inspect the source code.
@@ -885,7 +878,7 @@
until the command \inputencoding{latin9}\lstinline[showstringspaces=false]!library(foreign)!\inputencoding{utf8}
is issued.
-Simply type \inputencoding{latin9}\lstinline[showstringspaces=false]!library()!\inputencoding{utf8}
+Type \inputencoding{latin9}\lstinline[showstringspaces=false]!library()!\inputencoding{utf8}
at the command prompt (described below) to see a list of all available
packages in your library.
@@ -896,112 +889,13 @@
\section{Communicating with \textsf{R}}
-There are three basic methods for communicating with \textsf{R}.
-\begin{enumerate}
-\item At the command prompt (\texttt{>}).
+\paragraph*{One line at a time}
-This is the most basic way to complete simple, one-line commands.
-\textsf{R} will evaluate what is typed there and output the results
-in the Console Window.
-
-\item Copy \& Paste from a text file.
-
-
-Another way is to open a text file with a text editor (say, NotePad
-or Microsoft$\circledR$ Word). The user writes code in the text file,
-then when satisfied, (s)he copy-pastes it at the command prompt in
-\textsf{R}. Then \textsf{R} will run all of the code at once and give
-output in the Console Window.
-
-A disadvantage to this method is that all of the code is written in
-the same way with the same font. It can become confusing with longer
-scripts, and it is more difficult to efficiently identify mistakes
-in the code. To address this problem, software developers have designed
-powerful \emph{script editors}.
-
-\item Graphical User Interfaces (GUIs): These are actually much more general
-than discussed here.
-
+This is the most basic method and is the first one that beginners
+will use.
\begin{enumerate}
-\item \textsf{R} Gui
-\item The \textsf{R} Commander
-\item PMG: Poor Man's GUI
-\item Rattle
-\item JGR (sounds like {}``jaguar'')
-\end{enumerate}
-\item IDE / Script Editors.
-
-
-These are programs specially designed to aid the communication and
-code writing process. The advantage to using Script Editors is that
-they have additional functions and options to help the user write
-code more efficiently, including \textsf{R} syntax highlighting, automatic
-code completion, delimiter matching, and dynamic help on the \textsf{R}
-functions as they are written. In addition, they typically have all
-of the text editing features of programs like Microsoft$\circledR$
-Word. Lastly, most script editors are fully customizable in the sense
-that the user can customize the appearance of the interface to choose
-what colors to display, when to display them, and how to display them.
-
-Some of the more popular script editors can be downloaded from the\textsf{
-R}-Project website at \url{http://www.sciviews.org/_rgui/}. On the
-left side of the screen (under \textbf{Projects}) there are several
-choices available.
-\begin{itemize}
-\item \textsf{\textbf{R}}\textbf{WinEdt}: This option is coordinated with
-WinEdt for \LaTeX{} and has features such as code highlighting, remote
-sourcing, and many other goodies. However, one first needs to download
-and install WinEdt, and even then it is only free for a while. Annoying
-windows will eventually pop-up asking for a registration code. This
-is nevertheless a fine choice if you are familiar with \LaTeX{} and
-own WinEdt already, or are planning to purchase WinEdt in the near
-future.
-\item \textbf{Tinn-}\textsf{\textbf{R}}: This one has the advantage of being
-completely free. It has all of the above mentioned options and lots
-more. It is simple enough to use that the user can virtually begin
-working with it immediately after installation. But this particular
-choice is only available for Microsoft$\circledR$ Windows operating
-systems. If you are on MacOS or Linux, a comparable alternative is
-Sci-Views - Komodo Edit.
-\item \textbf{Bluefish}: This open-source script editor is for Mac OSX users.
-Other alternatives for Mac users are SubEthaEdit, AlphaTk, and Eclipse.
-I have tried Eclipse only, and only briefly, so I cannot comment on
-their strengths and weaknesses. Try them out, and let me know!
-\item \textbf{Emacs} / \textbf{ESS}: Click Emacs (ESS) or Emacs (ESS/Windows).
-This will take you to download sites with sophisticated programs for
-editing, compiling, and coordinating software such as \texttt{S-Plus},
-\textsf{R}, and \texttt{SAS} simultaneously. Emacs is short for \emph{E}diting
-\emph{MAC}ro\emph{S} and ESS means \emph{E}macs \emph{S}peaks \emph{S}tatistics.
-An alternate branch of Emacs is called XEmacs. This editor is -- \emph{by
-far} -- the most powerful of the text editors, but all of the flexibility
-comes at a price. Emacs requires a level of computer-savvy that the
-others do not, and the learning curve is much more steep.
-
-\begin{itemize}
-\item Emacs is an all purpose text editor. It can do absolutely anything
-with respect to modifying, searching, editing, and manipulating, text.
-And if Emacs can't do it, then you extend Emacs by writing a program
-in the Lisp language.
-\item In particular, a team of volunteers have written an Emacs extension
-called ESS, which stands for Emacs Speaks Statistics. Using ESS, one
-can speak to \textsf{R} and do all of the tricks that the other script
-editors offer, and much, much, more.
-\item If you want to learn Emacs, and if you grew up with Microsoft$\circledR$
-Windows or Macintosh, then you are going to need to relearn everything
-you thought you knew about computers your whole life. (Or, since Emacs
-is completely customizable, you can reconfigure Emacs to behave like
-you want.)
-\end{itemize}
-\end{itemize}
-\end{enumerate}
-Communicating with\textsf{ R}
-
-
-\paragraph*{One line at a time}
-\begin{enumerate}
\item Rgui (Windows)
-\item RalphaTkGUI
\item Terminal
\item Emacs/ESS, XEmacs
\end{enumerate}
@@ -1011,11 +905,20 @@
For longer programs (called \emph{scripts}) there is too much code
to write all at once at the command prompt. Furthermore, for longer
scripts it is convenient to be able to only modify a certain piece
-of the script and run it again in \textsf{R}.
-\begin{enumerate}
-\item \textsf{R} Editor (Windows): In Microsoft$\circledR$ Windows, \textsf{R}
-provides its own built-in script editor, called \textsf{R} Editor.
-From the console window, select \textsf{File}\emph{ }\textsf{$\triangleright$}\emph{
+of the script and run it again in \textsf{R}. Programs called \emph{script
+editors} are specially designed to aid the communication and code
+writing process. They have all sorts of helpful features including
+\textsf{R} syntax highlighting, automatic code completion, delimiter
+matching, and dynamic help on the \textsf{R} functions as they are
+being written. Even more, they often have all of the text editing
+features of programs like Microsoft$\circledR$ Word. Lastly, most
+script editors are fully customizable in the sense that the user can
+customize the appearance of the interface to choose what colors to
+display, when to display them, and how to display them.
+\begin{description}
+\item [{\textsf{R~}Editor~(Windows):}] In Microsoft$\circledR$ Windows,
+\textsf{R}Gui has its own built-in script editor, called \textsf{R}
+Editor. From the console window, select \textsf{File}\emph{ }\textsf{$\triangleright$}\emph{
}\textsf{New}\textsf{\emph{ }}\textsf{Script}\emph{.} A script window
opens, and the lines of code can be written in the window. When satisfied
with the code, the user highlights all of the commands and presses
@@ -1024,51 +927,98 @@
}\textsf{$\triangleright$}\emph{ }\textsf{Save as...} in \textsf{R}
Editor. The script can be reopened later with \textsf{File}\emph{
}\textsf{$\triangleright$}\emph{ }\textsf{Open Script...} in \textsf{RGui}.
-\item Tinn-\textsf{R}/Sciviews-K
-\item Emacs/ESS:
-\item JGR (read {}``Jaguar''): based on Java, so it is cross-platform.
-\item Kate, etc.
-\end{enumerate}
+Note that \textsf{R} Editor does not have the fancy syntax highlighting
+that the others do.
+\item [{\textsf{R}WinEdt:}] This option is coordinated with WinEdt for
+\LaTeX{} and has additional features such as code highlighting, remote
+sourcing, and a ton of other things. However, one first needs to download
+and install a shareware version of another program, WinEdt, which
+is only free for a while -- pop-up windows will eventually appear
+that ask for a registration code. \textsf{R}WinEdt is nevetheless
+a very fine choice if you already own WinEdt or are planning to purchase
+it in the near future.
+\item [{Tinn-\textsf{R}/Sciviews-K:}] This one is completely free and has
+all of the above mentioned options and more. It is simple enough to
+use that the user can virtually begin working with it immediately
+after installation. But Tinn-\textsf{R} proper is only available for
+Microsoft$\circledR$ Windows operating systems. If you are on MacOS
+or Linux, a comparable alternative is Sci-Views - Komodo Edit.
+\item [{Emacs/ESS:}] Emacs is an all purpose text editor. It can do absolutely
+anything with respect to modifying, searching, editing, and manipulating,
+text. And if Emacs can't do it, then you can write a program that
+extends Emacs to do it. Once such extension is called \emph{ESS},
+which stands for \emph{E}macs \emph{S}peaks \emph{S}tatistics. With
+ESS a person can speak to \textsf{R,} do all of the tricks that the
+other script editors offer, and much, much, more.
+
+\emph{Fair warning}: if you want to try Emacs and if you grew up with
+Microsoft$\circledR$ Windows or Macintosh, then you are going to
+need to relearn everything you thought you knew about computers your
+whole life. (Or, since Emacs is completely customizable, you can reconfigure
+Emacs to behave the way you want.) I have personally experienced this
+transformation and I will never go back.
+
+\item [{JGR~(read~{}``Jaguar''):}] This one has the bells and whistles
+of \textsf{RGui} plus it is based on Java, so it works on multiple
+operating systems. It has its own script editor like \textsf{R} Editor
+but with additional features such as syntax highlighting and code-completion.
+If you do not use Microsoft$\circledR$ Windows (or even if you do)
+you definitely want to check out this one.
+\item [{Kate,~Bluefish,~\emph{etc}.}] There are literally dozens of other
+text editors available, many of them free, and each has its own (dis)advantages.
+I only have mentioned the ones with which I have had substantial personal
+experience and have enjoyed at some point. Play around, and let me
+know what you find.
+\end{description}
+
\paragraph*{Graphical User Interfaces (GUIs)}
-The usual way to interact with \textsf{R} in Microsoft$\circledR$
-Windows is with \textsf{Rgui}, mentioned above.
-\begin{enumerate}
-\item The \textsf{R} Commander (\inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!Rcmdr!\inputencoding{utf8}):
-this one provides a point-and-click interface to many basic statistical
-tasks. It is called the {}``Commander'' because every time one makes
-a selection from the menus, the code corresponding to the task is
-listed in the output window. One can take this code, copy-and-paste
-it to a text file, then re-run it again at a later time without the
-\textsf{R} Commander's assistance. It is well suited for the introductory
-level.\\
-In addition, \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!Rcmdr!\inputencoding{utf8}
-allows for user-contributed {}``Plugins'' which are separate packages
-on \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!CRAN!\inputencoding{utf8}
+By the word {}``GUI'' I mean an interface in which the user communicates
+with \textsf{R} by way of points-and-clicks in a menu of some sort.
+Again, there are many, many options and I only mention ones that I
+have used and enjoyed. Some of the other more popular script editors
+can be downloaded from the\textsf{ R}-Project website at \url{http://www.sciviews.org/_rgui/}.
+On the left side of the screen (under \textbf{Projects}) there are
+several choices available.
+\begin{description}
+\item [{The~\textsf{R~}Commander~(\inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!Rcmdr!\inputencoding{utf8})}] provides
+a point-and-click interface to many basic statistical tasks. It is
+called the {}``Commander'' because every time one makes a selection
+from the menus, the code corresponding to the task is listed in the
+output window. One can take this code, copy-and-paste it to a text
+file, then re-run it again at a later time without the \textsf{R}
+Commander's assistance. It is well suited for the introductory level.\\
+\inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!Rcmdr!\inputencoding{utf8}
+also allows for user-contributed {}``Plugins'' which are separate
+packages on \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!CRAN!\inputencoding{utf8}
that add extra functionality to the \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!Rcmdr!\inputencoding{utf8}
package. The plugins are typically named with the prefix \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!RcmdrPlugin!\inputencoding{utf8}
to make them easy to identify in the \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!CRAN!\inputencoding{utf8}
-package list.
-\item Poor Man's GUI (\inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!pmg!\inputencoding{utf8}):
-this is an alternative to the \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!Rcmdr!\inputencoding{utf8}
-which is based on GTk instead of Tcl/Tk. Benefits include drag-and-drop
-datasets for plots.
-\item Rattle (\inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!rattle!\inputencoding{utf8}):
-this GUI was specifically designed for data mining applications but
-it provides enough other general functionality to merit mention here.
-\item Others: there are many more GUIs which exist but which the author
-has tried only in passing: \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!RKward!\inputencoding{utf8},
-\inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!RPad!\inputencoding{utf8}.
-\end{enumerate}
+package list. One such plugin is \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!RcmdrPlugin.IPSUR!\inputencoding{utf8},
+which accompanies this text.
+\item [{Poor~Man's~GUI~(\inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!pmg!\inputencoding{utf8})}] is
+an alternative to the \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!Rcmdr!\inputencoding{utf8}
+which is based on GTk instead of Tcl/Tk. It has been a while since
+I used this it but I remember liking it very much when I did. One
+thing that stood out was that the user could drag-and-drop datasets
+for plots. See here for more information \url{http://wiener.math.csi.cuny.edu/pmg/}
+\item [{Rattle~(\inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!rattle!\inputencoding{utf8})}] is
+a data mining toolkit which is designed to manage/analyze very large
+data sets, but it provides enough other general functionality to merit
+mention here.
+\item [{Deducer}] is relatively new and shows promise from what I have
+seen, but I have not actually used it in the classroom yet.
+\end{description}
\section{Basic \textsf{R} Operations and Concepts}
-The \textsf{R} developers have written an introductory document entitled,
-{}``Introduction to \textsf{R}''. There is a sample session included
+The \textsf{R} developers have written an introductory document entitled
+{}``An Introduction to \textsf{R}''. There is a sample session included
which shows what basic interaction with \textsf{R} looks like. I recommend
-that all new users of \textsf{R} read this document, but there are
-concepts mentioned there which will be unfamiliar to the beginner.
+that all new users of \textsf{R} read that document, but bear in mind
+that there are concepts mentioned which will be unfamiliar to the
+beginner.
Below are some of the most basic operations that can be done with
\textsf{R}. Almost every book about \textsf{R} begins with a section
@@ -1158,9 +1108,10 @@
data type:
<<five, keep.source = TRUE>>=
-sqrt(-1) # isn't defined
-sqrt(-1+0i) # is defined
-(0 + 1i)^2 # should be -1
+sqrt(-1) # isn't defined
+sqrt(-1+0i) # is defined
+sqrt(as.complex(-1)) # same thing
+(0 + 1i)^2 # should be -1
typeof((0 + 1i)^2)
@
@@ -3539,11 +3490,11 @@
\section{Sample Spaces}
For a random experiment $E$, the set of all possible outcomes of
-$E$ is called the \emph{sample space} and is denoted by the letter
-$S$. For the coin-toss experiment, $S$ would be the results {}``Head''
-and {}``Tail'', which we may represent by $S=\left\{ H,T\right\} $.
-Formally, the performance of a random experiment is the unpredictable
-selection of an outcome in $S$.
+$E$ is called the \emph{sample space\index{sample space}} and is
+denoted by the letter $S$. For the coin-toss experiment, $S$ would
+be the results {}``Head'' and {}``Tail'', which we may represent
+by $S=\left\{ H,T\right\} $. Formally, the performance of a random
+experiment is the unpredictable selection of an outcome in $S$.
\subsection{How to do it with \textsf{R}}
@@ -3788,8 +3739,8 @@
\section{Events}
-An \emph{event} $A$ is merely a collection of outcomes, or in other
-words, a subset of the sample space%
+An \emph{event\index{event@\emph{event}}} $A$ is merely a collection
+of outcomes, or in other words, a subset of the sample space%
\footnote{This naive definition works for finite or countably infinite sample
spaces, but is inadequate for sample spaces in general. In this book,
we will not address the subtleties that arise, but will refer the
@@ -6066,8 +6017,9 @@
and standard deviation with the functions \inputencoding{latin9}\lstinline[showstringspaces=false]!E!\inputencoding{utf8},
\inputencoding{latin9}\lstinline[showstringspaces=false]!var!\inputencoding{utf8},
and \inputencoding{latin9}\lstinline[showstringspaces=false]!sd!\inputencoding{utf8}:
+FLAG
-<<keep.source = TRUE>>=
+<<eval = FALSE, keep.source = TRUE>>=
library(distrEx)
X <- DiscreteDistribution(supp = 0:3, prob = c(1,3,3,1)/8)
E(X); var(X); sd(X)
@@ -6333,8 +6285,9 @@
on and involving \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!X!\inputencoding{utf8}.
Random variables with distributions from the \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!base!\inputencoding{utf8}
package are specified by capitalizing the name of the distribution:
+FLAG
-<<keep.source = TRUE>>=
+<<eval = FALSE, keep.source = TRUE>>=
library(distr)
X <- Binom(size = 3, prob = 1/2)
X
@@ -6347,7 +6300,7 @@
function is the \inputencoding{latin9}\lstinline[showstringspaces=false]!p(X)!\inputencoding{utf8}
function. Compare the following:
-<<keep.source = TRUE>>=
+<<eval = FALSE, keep.source = TRUE>>=
d(X)(1) # pmf of X evaluated at x = 1
p(X)(2) # cdf of X evaluated at x = 2
@
@@ -6361,7 +6314,7 @@
%
\begin{figure}[H]
\begin{centering}
-<<echo = FALSE, fig=true, height = 4, width = 6>>=
+<<eval = FALSE, echo = FALSE, fig=true, height = 4, width = 6>>=
plot(X, cex = 0.2)
@
\par\end{centering}
@@ -6565,9 +6518,9 @@
package provides an expectation operator \inputencoding{latin9}\lstinline[showstringspaces=false]!E!\inputencoding{utf8}
which can be used on random variables that have been defined in the
ordinary \inputencoding{latin9}\lstinline[showstringspaces=false]!distr!\inputencoding{utf8}
-sense:
+sense: FLAG
-<<>>=
+<<eval = FALSE >>=
X <- Binom(size = 3, prob = 0.45)
library(distrEx)
E(X)
@@ -6581,9 +6534,9 @@
generating a random sample from the underlying model and next computing
a sample mean of the function of interest.
-There are methods for other population parameters:
+There are methods for other population parameters: FLAG
-<<>>=
+<<eval = FALSE >>=
var(X)
sd(X)
@
@@ -7305,10 +7258,10 @@
diff(pbinom(c(19,15), size = 31, prob = 0.447, lower.tail = FALSE))
@
-\item Give the mean of $X$, denoted $\E X$.
+\item Give the mean of $X$, denoted $\E X$. FLAG
-<<>>=
+<< eval = FALSE >>=
library(distrEx)
X = Binom(size = 31, prob = 0.447)
E(X)
@@ -7317,21 +7270,21 @@
\item Give the variance of $X$.
-<<>>=
+<<eval = FALSE >>=
var(X)
@
\item Give the standard deviation of $X$.
-<<>>=
+<<eval = FALSE>>=
sd(X)
@
\item Find $\E(4X+51.324)$
-<<>>=
+<<eval = FALSE>>=
E(4*X + 51.324)
@
@@ -7613,7 +7566,7 @@
package. The method is similar to Example BLANK in Chapter BLANK.
We define an absolutely continuous random variable:
-<<>>=
+<<eval = FALSE>>=
library(distr)
f <- function(x) 3*x^2
X <- AbscontDistribution(d = f, low1 = 0, up1 = 1)
@@ -7624,7 +7577,7 @@
try expectation with the \inputencoding{latin9}\lstinline[showstringspaces=false]!distrEx!\inputencoding{utf8}
package:
-<<>>=
+<<eval = FALSE>>=
library(distrEx)
E(X)
var(X)
@@ -7967,8 +7920,9 @@
of the standard distributions, and \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!distr!\inputencoding{utf8}
takes advantage of these in many cases. For instance, the \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!distr!\inputencoding{utf8}
package can handle the transformation in Example BLANK quite nicely:
+FLAG
-<<>>=
+<<eval = FALSE >>=
library(distr)
X <- Norm(mean = 0, sd = 1)
Y <- 4 - 3*X
@@ -7984,7 +7938,7 @@
the transformations that \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!distr!\inputencoding{utf8}
recognizes. Let us try Example BLANK:
-<<>>=
+<<eval = FALSE>>=
Z <- exp(X)
Z
@
@@ -8010,7 +7964,7 @@
associated with $X$. But if we try a crazy transformation then we
are greeted by a warning:
-<<>>=
+<<eval = FALSE>>=
W <- sin(exp(X) + 27)
W
@
@@ -8023,7 +7977,7 @@
then define $W$ again, and compute the (supposedly) same $\P(W\leq0.5)$
a few moments later.
-<<>>=
+<<eval = FALSE>>=
p(W)(0.5)
W <- sin(exp(X) + 27)
p(W)(0.5)
@@ -11753,21 +11707,21 @@
\begin{example}
\label{exa:Speed-and-Stopping}Speed and Stopping Distance of Cars
-We will use the data frame \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!cars!\inputencoding{utf8}
-from the \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!datasets!\inputencoding{utf8}
-package. It has two variables: \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!speed!\inputencoding{utf8}
-and \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!dist!\inputencoding{utf8}.
+We will use the data frame \inputencoding{latin9}\lstinline[showstringspaces=false]!cars!\inputencoding{utf8}
+from the \inputencoding{latin9}\lstinline[showstringspaces=false]!datasets!\inputencoding{utf8}
+package. It has two variables: \inputencoding{latin9}\lstinline[showstringspaces=false]!speed!\inputencoding{utf8}
+and \inputencoding{latin9}\lstinline[showstringspaces=false]!dist!\inputencoding{utf8}.
We can take a look at some of the values in the data frame:
<<>>=
head(cars)
@
-The \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!speed!\inputencoding{utf8}
+The \inputencoding{latin9}\lstinline[showstringspaces=false]!speed!\inputencoding{utf8}
represents how fast the car was going ($x$) in miles per hour and
-\inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!dist!\inputencoding{utf8}
+\inputencoding{latin9}\lstinline[showstringspaces=false]!dist!\inputencoding{utf8}
($Y$) measures how far it took the car to stop, in feet. We can make
-a simple scatterplot of the data with the command \inputencoding{latin9}\lstinline[basicstyle={\ttfamily},breaklines=true,extendedchars=true,showstringspaces=false,tabsize=2]!plot(dist ~ speed, data = cars)!\inputencoding{utf8}.
+a simple scatterplot of the data with the command \inputencoding{latin9}\lstinline[breaklines=true,showstringspaces=false,tabsize=2]!plot(dist ~ speed, data = cars)!\inputencoding{utf8}.
\begin{quotation}
%
\begin{figure}
@@ -11850,27 +11804,27 @@
\subsection*{How to do it with \textsf{R}}
Here we go. \textsf{R} will calculate the linear regression line with
-the \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!lm!\inputencoding{utf8}
+the \inputencoding{latin9}\lstinline[showstringspaces=false]!lm!\inputencoding{utf8}
function. We will store the result in an object which we will call
-\inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!cars.lm!\inputencoding{utf8}.
+\inputencoding{latin9}\lstinline[showstringspaces=false]!cars.lm!\inputencoding{utf8}.
Here is how it works:
<<>>=
cars.lm <- lm(dist ~ speed, data = cars)
@
-The first part of the input to the \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!lm!\inputencoding{utf8}
-function, \inputencoding{latin9}\lstinline[basicstyle={\ttfamily},showstringspaces=false]!dist~speed!\inputencoding{utf8},
-is a \emph{model formula}, read as {}``\inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!dist!\inputencoding{utf8}
-is described by \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!speed!\inputencoding{utf8}''.
-The \inputencoding{latin9}\lstinline[basicstyle={\ttfamily},showstringspaces=false]!data = cars!\inputencoding{utf8}
+The first part of the input to the \inputencoding{latin9}\lstinline[showstringspaces=false]!lm!\inputencoding{utf8}
+function, \inputencoding{latin9}\lstinline[showstringspaces=false]!dist~speed!\inputencoding{utf8},
+is a \emph{model formula}, read as {}``\inputencoding{latin9}\lstinline[showstringspaces=false]!dist!\inputencoding{utf8}
+is described by \inputencoding{latin9}\lstinline[showstringspaces=false]!speed!\inputencoding{utf8}''.
+The \inputencoding{latin9}\lstinline[showstringspaces=false]!data = cars!\inputencoding{utf8}
argument tells \textsf{R} where to look for the variables quoted in
-the model formula. The output object \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!cars.lm!\inputencoding{utf8}
+the model formula. The output object \inputencoding{latin9}\lstinline[showstringspaces=false]!cars.lm!\inputencoding{utf8}
contains a multitude of information. Let's first take a look at the
coefficients of the fitted regression line, which are extracted by
-the \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!coef!\inputencoding{utf8}
+the \inputencoding{latin9}\lstinline[showstringspaces=false]!coef!\inputencoding{utf8}
function%
-\footnote{Alternatively, we could just type \inputencoding{latin9}\lstinline[basicstyle={\ttfamily}]!cars.lm!\inputencoding{utf8}
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/ipsur -r 107
More information about the IPSUR-commits
mailing list