Intro to UNIX and S+

Getting Started
 

  1. Log in
  2. Experiment with moving, resizing windows.
  3. Try clicking the different mouse buttons on the background.
  4. Focus on the xterm window
  5. Change your password by typing
                                 kpasswd
    It's a good idea to use the same password as for your other umich accounts - it's easier to remember and it makes access to your ITD home directory files easier.
  1. Using either the middle button/menu or type
                                netscape &
     to start the netscape WWW browser. Click on the "Classes" button, then select Your class. Explore the links available. If you're reading this then you doing just fine!
       
  1. SET NETSCAPE DISK CACHE TO 0!!! Here how you do it:
    1. In Netscape select Edit->Preferences
    2. Click on the arrow left of "Advanced", and select "Cache"
    3. Click "Clear Disk Cache", and then answer "yes".
    4. Change size of Disk Cache to 0
    5. Click "OK"
Introduction to Unix

We can use the mouse for multiple things:

  • By holding down the control button and clicking on the right button on the mouse you can change the font size of the X-term window.
  • The middle button, when pressed on the desktop, gives you options to open other windows (I think even emacs!).
  • When highlighting with the left button, it copies the text.
  •  You can paste that text with the middle button.
In the X-term window we can type in many different commands. Some fun commands to know are:
  • xeyes (the eyes will follow your mouse everywhere)
  • xclock
  • date
  • cal 9 1996 (you may type any month or year here!)
Try them out!
  • To rename a file type: mv file1 file2. The file named file1 will now be called file2.
  • To delete a file type: rm filename. The computer will reconfirm. Type y (yes) or n (no).

  •  

     
     
     

    To quickly see what is in a file, type: more filename. The contents of the file will appear on the screen.

Introduction to Emacs

Emacs is an editor. You can create and edit files using this window. An Emacs window should already be open. If not
type: emacs & in the X-term window. Again, we need the & so we can keep working in all our windows.
The three most important commands in this window (and probably the only ones you will need this semester) are:

^x ^f
    This will try to find a file. I you type a new name here, it will create a new file for you.
^x ^s
    This will save the current file.
^k
    This will cut an entire line from the text. Handy for when you make a BIG mistake.

These and more commands are also available under the file menu.
Now create the file lab1, by typing: ^x ^f (^ means the control button) and then typing in the name lab1. Note that
we are located at the bottom of the screen! Now type in your name, major, and the reason why you are taking this class
(something more than "required") and save the file (^x ^s).
Now go back to the X-term window, by clicking on the bar at the top. Type: ls (it's an L! not a 1!). Is the file lab1
there?
 

Starting Splus

Now let's try Splus. From Start Menu select "Statistics" -> "Splus (Emacs)".  It will start Emacs with Splus running, but you have to specify your data directory.  Click Enter to be safe.   Another way to run it is by typing Splus in the xterm window (or selecting "Splus (xterm)" for the menu.  But a nicer interface can be had by hitting the F2 function key while the mouse is focussed on the Emacs window. This makes it easier to edit and save your session. (I've written more about the various interfaces to Splus on another page). Hit the return key in response to all questions. All commands should be typed at the > prompt.

Intro to Splus

In the X-term window type Splus. Splus is a statistical computing language we will use for this class (for now).

Let's type the following to see how S-plus works:

a_c(1,1,1,2,2,3)
    This command creates the variable a and assigns the vector (1,1,1,2,2,3) to it.   Note a_1 and a<-1 are identical comands.
mean(a)
    This command finds the mean of the above vector.
m_mean(a)
    This will put the mean of a in the variable m.
median(a)
    This command finds the median of the above vector.
var(a)
    Finds the variance of a.
s_sqrt(var(a))
    s will now contain the standard deviation of a. Type s to see it.
X11()
    This command opens a graphic window. You may want to reduce the size a little, using the middle button on the
    mouse.
hist(a)
    This creates a histogram of the values in a.
b_c(4,5,6,7,8,9)
    Create another vector of length 6.
cor(a,b)
    This finds the correlation between a and b.
boxplot(a,b)
    This creates a boxplot for the two variables a and b.
d_1:50
    This command creates the vector d containing the numbers 1 through 50. This will come in handy in later
    problems!
lm(a~b)
    This command gives the regression line for y=a and x=b plus some other information.
g_lm(a~b)
    Store the regression information in g.
plot(g)
    Puts the scatterplot AND the regression line in one graph!
q()
    This will quit Splus.

Getting some data

We'll be using some practice data concerning the number of species of tortoise on the various Galapagos Islands.
Download this by using the "Save as" option under the "File" menu. Now type ls in the xterm window to see what files you have and more gala.data to take a look at the file you just downloaded.

ITD provides a summary of frequently used UNIX commands.

Reading the data in

The first step is to read the data in - I've written up more details on reading data in elsewhere.

> gala <- read.table("gala.data")
> gala

The "<-" is an assignment operator which reads the data into the object gala.

Numerical Summaries

I'll let you figure out what each of these commands do by experimentation:

> summary(gala)
> mean(gala$Species)
> min(gala$Sp)
> range(gala$Sp)
> var(gala$Sp)
> median(gala$Sp)
> gala$Species
> stem(gala$Sp)
> gala$Endemics/gala$Species
> ratio <- gala$Endemics/gala$Species
> summary(ratio)
> larea <- log(gala$Area)
> larea
> stem(larea)
> var(gala)
> cor(gala)
> cor(gala[,-(1:2)])

Graphical Summaries

The first step is to open up a window:

motif()

Now see if you can figure out what these do:

> hist(gala$Sp)
> boxplot(gala$Sp)
> plot(gala$Sp,gala$En)
> plot(gala$Sp,gala$En,xlab="Species",ylab="Endemics",main="Title here")
> plot(gala$Sp,gala$En,xlab="Species",ylab="Endemics",main="Title here",type="n")
> text(gala$Sp,gala$En,row.names(gala))
> pairs(gala)
> par(mfrow=c(2,3)) Set up for 2x3 plots per page
> for(i in 2:7) boxplot(gala[,i])
> plot(gala)
> par(mfrow=c(1,1)) Set back to one plot per page

Learning more about Splus

While running Splus you can get help about a particular commands - eg - if you want help about the pairs() command just type help(pairs) (If you use the Emacs interface, it's better to use the "Inf-S" menu and select the help option and type in the name of the command you want help about.)

If you don't know what the name of the command is that you want to use then type:

help.findsum(".Data") One time initialization
help.start(gui="motif")

and then browse.

You can  print out some of the documentation found on the department Splus page.

Finishing off

Type q() to quit S+. If you are using the Emacs interface, you can save you session to a file by using the "Save as" under the "File" menu. The variables you created during this session will still be there for your next session, which is convenient but eventually you'll need to clean some of them out - more on that later.

SAS (optional)

As a service to those of you who would like to learn SAS, I'll be providing the occasional SAS program that does some of the same things that we have been doing in the lab. I'm no expert at SAS but it is possible to gain working knowledge of the program by examining example programs. Here's a simple SAS program to read in the Galapagos data and compute some summary statistics. You can run it by typing:

                            sas simple.sas

and examine the output in the file simple.lst. It should be the same as I found.

ITD offers Courses in SAS.

Logging out

Make sure you log out properly! Click on the Logout button when you are all done. Make sure the Login Window
appears before you leave.



 Vadim Kutsyy - kutsyy@umich.edu