The R and R-commander software

This course uses the statistical package 'R' and the 'R-commander' graphical user interface (Rcmdr). Full details about these packages and the advantages associated with using them are detailed in the chapter from the forthcoming Sage book on the Rcmdr which accompanies this course. The documentation about installation that is available in the notes (and on the web) is comprehensive and so no additional information will be provided here.

This course is practically-orientated with each technique demonstrated using exercises that can be run in R. It is essential, therefore, that everyone is able to run the software and load data. After this session everyone will be able to....

  1. Load R and the Rcmdr package
  2. Search for and install additional libraries
  3. Import data files

Installing R on your lap-top/USB

R and the Rcmdr are very easy to install on all computer platforms and you are advised to install the software directly onto your own computer or USB drive (this enables you to have an up-to-date version with your own libraries and also 'take your software with you'). The software can be easily downloaded from the net and installed direct to a PC/laptop or USB drive. For information about installing R and Rcmdr, see the course notes (session 2) or:

R and the Rcmdr are available on the Manchester University servers, but for convenience are also provided on the CD that accompanies this course. The software can be run direct from this CD. It is, however, preferable for all users to install their own copies from the web (this only takes a few minutes).

Exercise: if you are familiar with R and the Rcmdr, you might wish to use this session to install them to a USB drive or onto your lap-top. If you have already installed these packages you may use this session to investigate some of the other features offered by this software (see, for example, graphics and the contributed documentation on CRAN, including the task-views). Alternatively, you could help someone who is new to the package with this exercise.

Running R from the CD

(skip this page if you are using your own installation)

In order that everyone has access to the same software, R and the Rcmdr are available to run directly from the course CD. This provides access to the software for everyone, but the programs run a lot slower than if they were installed diirectly to a hard-drive (or a USB).

The course CD provides a copy of the R programme (for windows) and a number of associated add-on libraries that are required for this course. These are designed to run directly from the computers in the labaoratory.

Insert the CD into your computer and then access the CD using the “My Computer” option in the Start menu.

The CD has the following directories:

Data -all the data sets used in this course

Exercises -copies of the exercises

Notes-the course notes

R-2.15.2-the R programme files and libraries

Reading -additional reading

To start R from the CD, go to “MY Computer” and select the CD drive. Then locate the file “Rgui.exe”, which is found in directory...

CD

R-2.15.2

bin

i386

Rgui.exe

Double-clicking on this file will load the R-console...

The R console

Start the R-console....

As the Rconsole is not all that intuitive (or attractive) for new users, we use a simple graphical interface for R, called the Rcmdr (R-commander). This can be loaded using the pull-down menus in the Rconsole.

Packages

Load Packages

Rcmdr
OK

OR, by typing in the command library(Rcmdr) into the command line on the R console. Note: if you are using your own installation, you will need to install the Rcmdr first (installing packages is very easy - see the instructions provided in the notes or on

The Rcmdr GUI should now load...

The R Commander interface

You will find that Rcmdr is intuitive and very similar to other software. You should, therefore, have little difficulty in using this package to load and analyse your data.

Importing Data

Data can be imported into R from a number of formats including text files, SPSS, STATA, MINITAB and Excel. The data files for this course are saved as comma-separated text files (.csv files). This format is used as these files are easily read in a number of packages, have their own identification (i.e., the .csv ending to the files indicate that they are data files) and can also be easily imported into spreadsheets and text editors. To import .csv data, select the following commands in Rcmdr:

Data

Import data ►

from text file, clipboard or URL...

Importing text data into R

This will open up the Read Text Data From File window...

Importing text data into R: options

Enter a name for the data set: choose a name or use the default name “Dataset”

Variable names in file:the first line in all the data sets we use in this course contain the variable names. Leave this box checked.

Missing data indicator:All data files used in this course use NA to indicate missing data. Keep the indicator as NA.

Field Separator: commas (the files are comma-separated). Change the Field separator to Commas.

Click OK. This will open up another window from which you will be able to select the data set you wish to load (the example below selects the dataset MNLexample.csv):

Importing text data into R: selecting a file


The data (MNLexample.csv) will now load into R. You can check the data set by clicking on the View data set button in Rcmdr.

Loading multiple data sets:

You can load as many data sets into Rcmdr as you like (provided that you give them different names), and select which one to use by simply clicking on the blue Dataset button. The following graphic shows an Rcmdr session where a number of data sets have been loaded. Once a particular dataset is selected it's name will appear in blue in the dataset window.


Installing Additional Packages:

The copy of R and Rcmdr included on the course CD (and most installations) only provides a very small selection of packages that are available (these include all that are used during this course). There are, however, many more available, all of which can be downloaded and installed on your computer/USB drive.

Packages may be installed from the R-console via the Packages, Install package(s)... menu option.

What packages are available?

Go to and select Packages in the left-hand menu. Click on the list of available packages. Details of nearly 4,000 packages will be presented that can be searched for keywords using your browser (for example, cluster analysis).

A useful resource for identifying useful packages is to look at the CRAN Task Views (available via the packages menu), which group similar packages together and explain which techniques are available. For this course, the SocialSciences task view is particularly relevant.

Once you have identified a package – click on it and have a look at its manual and vignettes (if available). If it is of interest, install it using the instructions above.

Rcmdr Plugins:

There are a number of Plugins that have been specially written for Rcmdr and these add additional functions to the Rcmdr menu tree. These plugins are really just packages that have been specially adapted for Rcmdr and are installed in exactly the same way as all other packages, but they are loaded in the Rcmdr using the Tools, Load Rcmdr plug-in(s)... pull-down menu.


A very useful plugin for this course is the RcmdrPlugin.HH, which provides additional menu items once loaded.

If you have time...

Exercise: If you have any time to spare before the next session, look at the graphical capabilities of R (try a google search for “R graphics”). A very useful site is...

SPSS data files:

There are some issues with sharing data with SPSS, as SPSS uses numeric codes to represent all data (whether or not the data are actually numeric). This can cause some confusion, but it is not a major problem to share data between R and SPSS. For more information about this issue, see the tutorial in the Journal of Modelling in Management (2011, No. 1)