WSL Course Introduction to Statistics Software, Installation and Use Christian W. Hoffmann Swiss Federal esearch Institute WSL 2009-12-06, 14:03:31 Contents 1 Documents and Programs needed, and where to get them 2 2 Editors 3 3 Hints for installation 3 4 Install the Course Material 4 4.1 Get the Course Data.................................. 4 4.2 Starting for the first time.............................. 4 4.3 Create the working file................................. 5 4.4 Quitting........................................ 5 5 Working with the files 5 5.1 If the html help does not appear........................... 5 5.2 Editing files....................................... 5 5.3 unning scripts in.................................. 5 5.4 esults.......................................... 5 5.5 Improvements...................................... 5 6 Automatic Generation of.pdf files 6 6.1 Sweave.sty........................................ 6 6.2 Sweave, LATEX, Acrobat................................ 6 7 Information flow and internal programming 7 1
Contact: christian.hoffmann@wsl.ch, most reachable here. Office: WSL HP D60 Tel intern: 277, with answering machine Conventions: > means Item in Menu or Link to (Double-) Click The Prompt of will also be marked by >; it will be mentioned in the first few examples, and must never be typed. After text input <T> must be pressed. 1 Documents and Programs needed, and where to get them According to one s needs the course material can be worked on at different levels. The diagram of the structure of data and programs can help to understand better this document, see Fig. 1 on p. 7. All further material is available through http://www.wsl.ch/forschung/forschungsunits/wald/infomanagement/courses/statistics/ index_en (English), and http://www.wsl.ch/forschung/forschungsunits/wald/infomanagement/courses/statistics/ index_de (German). These directories will be referred to in the following text. 1. Walk through the course manuscript Crs.pdf (see index_en), an Adobe Acrobat eader is needed (newer version!). 2. Working on the programming code Crs. (see index_en) using the statistical programming software package : a) Create (on the Desktop, preferably) your Working Directory ( WD ) StatsCrs (as you may call it), b) Installation of the software package in the newest version -xxx, where at the moment xxx = 2.10.0, by downloading and following the directions in (or: r-project.org -> FAQ -> Basics -> How Can be Installed -> Choose your OS) Windows: http://cran.r-project.org/ > Windows > base > -xxx-win32.exe and EADME.-xxx, Mac OSX: http://cran.r-project.org/ > MacOSX > -xxx.dmg and NEWS (the latter will show up as The Comprehensive Archive Network.html and as a directory of the same name), c) Copying of Crs. (see index_en) (and Crs.eadme.pdf) to the WD, generation of the subdirectory fig in the WD. d) Downloading of Crs.zip (see index_en) and unpacking to the WD. If you are more interested, also download AdditionalZusatz.zip. e) The file Crs.profile determines the starting process of and the loading of additional packages needed, see 4.2. 2
f) Execution of > source("crs."). All variables and figures of the course. From now on any parts of the code can be executed in any order without fear of being stuck with missing variables. 3. Modification of individual chapters or generation of an own manuscript: a) Installation of editors (see Chap. 2) and of a LATEX system: Windows: TexLive from http://www.tug.org/texlive/acquire.html Mac OSX: TexShop.dmg from http://www.tug.org/mactex/ > MacTeX.mpkg. zip. b) Using the editors (e.g. Tinn- and Aquamacs) on data of type.nw, c) Treating of..nw with executing > Sweave("..nw"), resulting in files..tex, d) Type setting of..tex executing pdflatex or TexShop, resulting in files..pdf. In the following chapters some of these points will be clarified some more. 2 Editors Windows: Tinn- from http://www.sciviews.org/tinn-/ TextPad from http://www.textpad.com/ NotePad2 from http://www.flos-freeware.ch/notepad2.html Crimson Editor from http://www.crimsoneditor.com/ Mac OSX: Aquamacs.dmg from http://www.cognitiones.de/doku.php/aquamacs TexShop.dmg from http://www.tug.org/mactex/ Alpha from http://www.kelehers.org/alpha/ TotalEdits from http://totaledit.softonic.de/ The editors mentioned can be tuned to show pairs of brackes and braces, key words of the syntax, and thus assist substantially to write correct programs. Some offer the possibility to send code lines and whole regions directly to the process. At any rate, the pedestrian way of Copy/Paste from the editor to the command line of. 3 Hints for installation 1. Windows: Create a shortcut of the programm C:\ProgramFiles\\-xxx\bin\gui. exe and specify the Working directory in Properties as the ( WD ) of Ch.1. This is very important!, if you want to start via this shortcut. 2. Mac OSX: At the start of there will pop up the question for the starting directory. If not an explicit setwd(wd}) (like setwd("/users/own_usename/desktop/statscrs")) will bring us to the working directory. 3. There is a way to test for the working directory of the present process, namely getwd(). 3
4 Install the Course Material 4.1 Get the Course Data Unpack the course files from Crs.zip (see Ch.1) into the WD StatsCrs. Take care that the subdirectory fig exists, otherwise create it. Important: It may happen when unpacking, that an additional StatsCrs inside of ( below ) WD StatsCrs is created which then contains all files (and subdirectories) of the course. In order to establish the correct hierarchy all these files will have to be moved up into WD StatsCrs. The emptied and now superfluous StatsCrs should be deleted. Again: Instead of.../desktop/statscrs/statscrs/<course files> now correctly.../desktop/statscrs/<course files> und deletion of.../desktop/statscrs/statscrs/. 4.2 Starting for the first time 1. Windows: Doubleclick the icon on the desktop, and Gui opens. Navigate File > Change directory > choose..desktop/statscrs. 2. Mac OSX: Programs > start Aquamacs.app, Press consecutively the keys Esc, x and <T>, or open the file Crs. (in WD), press the icon in the menu bar. In a frame of Aquamacs the process will now be started. The question for the starting directory will show (and may be correctly suggested as WD), or do explicitly > setwd("/users/own_usename/desktop/statscrs"). 3. To adjust the starting process > source("crs.profile") has to be executed, then >.First(). When a list of source locations is shown, choose Switzerland and acknowledge with OK. Expand the window to full screen to show the OK-Button! The required packages are loaded. 4. At the start of, in the browser a window there should appear file:/..././doc/html/ index.html (or similar) showing: Statistical Data Analysis (-Logo) Manuals An Introduction to The Language Definition Writing Extensions Installation and Administration Data Import/Export Internals eference Packages Search Engine & Keywords Miscellaneous Material About Authors esources License Frequently Asked Questions Thanks Checking the version of can be done with >.Version(). Error messages showing up in the Console must be taken serously. They help to configure the startup process correctly. Call for help, if necessary. In Aquamacs the colour of the text in the prompt may not be as desired. Try with > \\`'. 4
4.3 Create the working file Use the file Crs. as supplied, or create it using > Stangle("Crs.nw"). 4.4 Quitting > q(), answer Save Workspace: by typing y. 5 Working with the files 5.1 If the html help does not appear At the start of the -help should appear in the browser, see Ch. 4.2. If this ist not the case or if one has killed this browser window inadvertantly, one can get it back by executing > help.start(). 5.2 Editing files Use one of the editors Tinn-, TextPad, Aquamacs, or TexShop. TexShop offers excellent help and even some courses on writing in LATEX. 1. Windows: If you do not want to use Tinn-, go to the console > File > Open Script > e.g. Crs.. This editor internal to does not offer syntax highlighting. Alternative editors are mentioned in Chap. 2. 2. Mac OSX: Aquamacs is an integral working environment, one can work with seamlessly. It offers good syntax highlighting, data comparison, etc., but you will have to get used to it (it is Emacs after all). TexShop can also edit files, and will be used for type setting, i.e. it produces.pdf files from LATEX s.tex files. 5.3 unning scripts in Execute > source("crs."), or copy lines from Crs.pdf to the command line of and execute there. esults of computations and error messages are shown in the Console at the prompt. When graphic plots are generated, they will be shown in a window titled Graphics... 5.4 esults esults of computations can be copied from the Console to an own file and then be saved. Whole sessions can be saved by a special command, in Aquamcs use File > Save Buffer as on the buffer. The window with a plot inside can be saved from its menu, under a suitable name, e.g. in the subdirectory fig of the WD. 5.5 Improvements epeat the steps of this chapter... 5
6 Automatic Generation of.pdf files 6.1 Sweave.sty A file Sweave.sty is supplied, it should also go in the WD. It is used in > Sweave(). 6.2 Sweave, L A TEX, Acrobat 1. Execute > Sweave("Crs.nw") and wait for the message You can now.... 2. Windows: > system("pdflatex Crs") (execute twice!), this will create Crs.pdf which can be opened with the Adobe Acrobat eader. Do not forget to get the newest version of the eader! 3. Mac OSX: In TexShop do > Ablage > "Offnen oder Zuletzt benutzte Dokumente > Crs.tex, Command-T (execute twice!), this will create Crs.pdf and open it. Executing the given commands twice will resolve forward references in the manuscript. 6
7 Information flow and internal programming Crs.nw > Stangle( + ) > Sweave( * ) \SweaveInput( ) Crs.hdr Crs.Ch1.nw Crs.Ch2.nw Crs.Ch3.nw Crs. -Console > Stangle ( Crs.nw ) + > source ( Crs. ) > [Copy Paste] > [esults] > Sweave ( Crs.nw )* > system( pdflatex Crs.tex ) Crs.tex > pdflatex Crs L Crs.pdf Mywork. \fig\fig-01.pdf \fig\fig-02.pdf \fig\fig-03.pdf \fig\fig-04.pdf Acrobat eader L Errors in chunk Errors in Latex C.W.Hoffmann, 2009-12-03 Figure 1: Files and programs, information flow in the system, LaTeX, Acrobat. For Mac OSX we have TexShop, Command-T instead of pdflatex Crs. 7