Introduction to Lab 1


The purpose of this first lab is to get you acquainted with S and help you learn how to use it to produce a lab report, so that you will be able to complete all your labs for the course using the same format. For this lab, you will be using S to illustrate some of the concepts from Chapter 1, namely distribution functions, quantiles, and densities.

To get started in S read Chapter 2 of the S manual (The New S Language). It gives you an introduction to S and a short overview. You will be told everything that is necessary to start, run and end a computer session. You may choose to read this short chapter first at home and then come to the computer and play around a bit with the easy examples given there. More detailed information is given in the chapters 3,4,5 and 6. You may look at these chapters if you need something specific in the course of the semester. The most important part of the manual, however, is the S Function Documentation in appendix 1. There, the functions, that do all the work for you, are explained one by one. To use this part proceed as follows: Once you are confronted with the need to have the computer do a certain function for you (e.g. linear regression), look in the index at the end of the manual or listen to the word of mouth that goes around among your classmates about the appropriate function to be found in the documentation. Then look there to see how to use it. Most S users take this approach in learning S, rather than being drawn too deeply in the lengthy chapters 3 to 6.

Before invoking S for the first time you need to create a directory called .Data. You could create it by typing mkdir .Data and hitting the 'return' key. For the rest of the labs you don't have to do this. Now you can invoke S by typing Splus at the Unix prompt.

After each lab you need to produce a lab report that gives all the S instructions you used to get your results. Of course you are only to report your final and hopefully correct steps. To produce such a lab report do the following:

While you are still in UNIX, immediately after logging into your account, type script. Then, whatever you type and see on the screen will be written in the file typescript. So after typing script you go on as usual by typing 'Splus' to start your S-session. After completing all the necessary steps in S, type q() to get out of S; then at the Unix prompt type exit. The script will stop here. Type clean typescript to clear your script from delete-commands etc. and then edit your file with the vi-editor to get rid of unwanted material like unsuccessful commands. Inside vi you must erase the coded screen output that was created by your graphics command during your session. Also you may add comments here to make your report more readable and easy to follow. Then send it to the printer by typing lpr -Plw4 typescript. (Note: lw4 is the printer name, you may use other printers)

During the course of time you will have to do a number of plots for the labs. But before you print out plots it is a good idea to see how they look. To see graphs on your terminal you must open graphic window in S by typing the command motif(). Use the mouse to toggle between the graphic window and the interactive S session. To save your graphs into a file called file.ps, you must type the command postscript(``file.ps'') before you type your plot command/commands. This will create a file named file.ps in your unix directory that you can send to the printer after going back to UNIX. (Again this can be done by typing lpr -Plw4 file.ps at the UNIX prompt after you get out of S). Alternativlely, you may send plots to the printer directly form the graphic window (if you use motif).

Caution: Don't try to print out your plots unless you've typed exit after your S session. You could put multiple plots into the same file by doing one plot command after the other after typing postscript(``file.ps'') and then if you send this file to the printer you will get more than one page of plots.

It should be stressed that while you are responsible for performing all the tasks specified in the lab, the most important parts of your report are the comments you include explaining what you have done and demonstrating your understanding of the various results.