Random Number Functions
Simulation
BTRY 3520
1 / 27
On Randomness
2 / 27
Random Number Functions
R has a number of built-in functions associated with specic
distributions.
These provide the density, distribution and quantile functions of
each distribution

Reading and Writing Data
Complex Data Structures
Writing Functions
BTRY 3520
1 / 44
Outline
1
Reading/Writing data
read.table plus data frames, load, save and others.
2
Complex Objects
data frames, factors, lists
3
Functions
structure of a function
good c

Markov Chain Monte Carlo
MCMC
1 / 66
Some Examples
So far we have studied simulating sequences of iid random variables.
This in turn was used to calculate sample averages as
approximations of integrals.
Modelling various phenomena using iid random variabl

Optimisation and Root Finding
JMR Chapter 10
BTRY 3520
1 / 55
Formal Optimisation Ancient Times
2 / 55
Formal Optimisation Ancient Times
On the left is a depiction of the burning of the Library of Alexandria
On the right is the picture of Heron of Alexand

Monte Carlo Integration
JMR Chapter 19
1 / 45
Basics
Suppose X is a continuous random variable.
We may be interested in P(a < X < b) for some a and b.
Plenty of situations can be formulated as the above problem.
Suppose buses leave on the hour from some s

Computational Complexity, Numerical Linear
Algebra
BTRY 3520
1 / 44
Computational Complexity
What is computational complexity?
How long will a code take to run?
Depends on many factors
The computer processor
The programming language
But most importantly
T

Multivariate Optimization
1 / 38
Multivariate Optimization
We have seen Golden Section and Newton Raphson searches
for one-dimensional optima.
It is rarely the case that we only want to optimise one thing.
So we need some strategies for working in multipl

The Bootstrap
BTRY 3520
1 / 41
These Boots.
2 / 41
Bootstrap
I doubt if we will be talking much about Nancy Sinatras
contribution in this class.
But denitely about this mans contribution.
3 / 41
Bootstrap
I doubt if we will be talking much about Nancy Sin

Simulation
1 / 32
Background
We have already seen some R functions for simulating random
variables:
Continuous: rnorm, rchisq, rexp, etc.
Discrete: sample, rbinom, etc.
And we've done a few simulation experiments with these functions
(e.g., 2 in section,

Simulation
Monte Carlo Methods
BTRY 3520
1 / 51
Simulating Marginal and Conditional Distributions
Used to notation P(A|B) for the probability of A given B.
Used for marginal distributions
P(A) = B P(A|B)P(B) = EB P(A|B)
In Bayes theorem:
P(B|A) =
P(A|B)P(

Functional Programming and Vectorisation
BTRY 3520
1 / 26
Some Quick Review
Some important data structures in R are
1
Vectors : Building blocks of R.
2
Matrices: Vectors with the two attributes, rows and columns.
Use the functions rbind (row bind),cbind (