Professional Documents
Culture Documents
Introduction to R
Walt Pohl
Universität Zürich
Department of Business Administration
Walt Pohl (UZH QBA) Stochastic Models February 28, 2013 2/1
R versus Excel
R has many more probability and statistical
functions built in or avaiable in free packages.
R is command-driven. You enter a sequence of
commands to manipulate your data.
While everything in Excel is in terms of cells, R has
a bunch of different data types: vectors, arrays,
objects. You can define your own.
Normally you will create a “.R” command file that
is separate from your data.
Note: Excel also has a separate command language –
VBA.
Walt Pohl (UZH QBA) Stochastic Models February 28, 2013 3/1
R versus Matlab
Walt Pohl (UZH QBA) Stochastic Models February 28, 2013 4/1
R versus Other Statistics Programs
R is free.
R is more command-driven and less GUI driven.
R is very close to S-Plus.
R supports as broad of an array of operations as any
other statistics program.
R’s programming language is better-designed than
most of its competitors.
Since different packages are written by different
volunteers, R is not as uniform as some other
systems.
Walt Pohl (UZH QBA) Stochastic Models February 28, 2013 5/1
Important URLs
Walt Pohl (UZH QBA) Stochastic Models February 28, 2013 6/1
Monte Carlo Simulation in R
R has many, built-in probability distributions. For each
supported distribution XXX, R comes with four functions:
dXXX – density function
pXXX – cumulative distribution function
qXXX – quantile function (inverse of the CDF)
rXXX – random draw
XXX = unif, norm, chisq, t, etc.
Example: For the normal distribution, we have dnorm,
pnorm, qnorm, rnorm.
Walt Pohl (UZH QBA) Stochastic Models February 28, 2013 7/1
Vectors in R
Walt Pohl (UZH QBA) Stochastic Models February 28, 2013 8/1
Vectors in R, cont’d
Walt Pohl (UZH QBA) Stochastic Models February 28, 2013 9/1
Operations on Vectors