411 REFERENCE · Wikibooks
Statistical Analysis: an Introduction using R/R basics
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
3
Why R?
R is a command-driven statistical package. At first sight, this can make it rather daunting to use. However, there are a number of reasons to learn statistics using this computer program. The two most important are:
R is free; you can download it from http://www.r-project.org and install it onto just about any sort of computer you like.
R allows you to do all the statistical tests you are likely to need, from simple to highly advanced ones. This means that you should always be able to perform the right analysis on your data.
An additional bonus is that R has excellent graphics and programming capabilities, so can be used as an aid to teaching and learning. For example, all the illustrations in this book have been produced using R; by clicking on any illustration, you can obtain the R commands used to produce it.
A final benefit, which is of more use once you have some basic knowledge of either statistics or R, is that there are many online resources to help users of R. A list is available in the appendix to this book.
How to use this book with R
The main text in this book describes the why and how of statistics, which is relevant whatever statistical package you use. However, alongside the main text, there are a large number of "R topics": exercises and examples that use R to illustrate particular points. You may find that it takes some time to get used to R, especially if you are unfamiliar with the idea of computer languages.
Don't worry! The topics in this chapter and in Chapter 2 should get you going, to the point where you can understand and use R's basic functionality. This chapter is intended to get you started: once you have installed R, there are topics on how to carry out simple calculations and use functions, how to store results, how to get help, and how to quit. The few exercises in Chapter 1 mainly show the possibilities open to you when using R, then Chapter 2 introduces the nuts and bolts of R usage: in particular vectors and factors, reading data into data frames, and plotting of various sorts. From then on, the exercises become more statistical in nature.
If you wish to work straight through these initial exercises before statistical discussion, they are collected here. Note that when working through R topics online, you may find it more visually appealing if you set up wikibooks to display R commands nicely. If the R topics get in the way of reading the main text, they can be hidden by clicking on the arrow at the top right of each box.
Starting R
If you don't already have R installed on your computer, download the latest version for free from http://www.r-project.org, and install the base system. You don't need to install any extra packages yet. Once you have installed it, start it up, and you should be presented with something like this:
R version 2.11.1 (2010-05-31)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
>
You are now in an R session. R is a command-driven program, and the ominous-looking ">" character means that R is now waiting for you to type something. Don't be daunted. You will soon get the hang of the simplest commands, and that is all you should need for the moment. And you will eventually find that the command-line driven interface gives you a degree of freedom and powerThese are poor attempts at a statistical jokes, as you will soon find out. that is impossible to achieve using more "user-friendly" packages.
h4 right #8888FF R as a calculator ../R/R as a calculator
h4 right #8888FF Storing objects ../R/Storing objects
h4 right #8888FF Functions ../R/Functions
h4 right #8888FF Getting help ../R/Getting help
h4 right #8888FF Quitting R ../R/Quitting R
Setting up wikibooks
Before you start on the main text, we recommend that you add a few specific wikibooks preferences. The first three lines will display the examples of R commands in a nicer format. The last line gives a nicer format to figures consisting of multiple plots (known as subfigures).
You can do this by creating a user CSS file, as follows.
Make sure you are logged in (and create yourself an account if you do not have one already).
Visit your personal css stylesheet, at Special:MyPage/skin.css.
Click on "Edit this page".
Paste the following lines into the large edit box
pre {padding:0; border: none; margin:0; line-height: 1.5em; }
.code .input ol {list-style: none; font-size: 1.2em; margin-left: 0;}
.code .input ol li div:before {content: "\003E \0020";}
table.subfigures div.thumbinner, table.subfigures tr td, table.subfigures {border: 0;}(note that this is a temporary hack until GeSHi supports R code, in which case ../R/Syntax can be changed. The css code should really read.pre {padding:0; border: none; margin:0; line-height: 1.5em; }
.source-R ol {list-style: none; font-size: 1.2em; margin-left: 0;}
.source_R ol li div:before {content: "\003E \0020";}
If you know any CSS, make any alterations you like to this stylesheet.
Finally save the page by clicking on "Save page",
Enough! Let's move on to the main text.
Notes
Chapter 1 Cover