This preview shows pages 1–2. Sign up to view the full content.
Lab 2: Generating Random Variables
Andrew J. Womack
September 2, 2011
1 Probability Inverse Transformation
Write a function which has two inputs (
N
(a number of draws) and
W
which is an inverse
CDF
F

1
) with the following code. We will use the
...
input in the function to allow
variable input to
W
.
randx<function(N,W,.
..){
if(missing(N)){return("Number of draws N unspecified")}
if(missing(W)){return("Inverse CDF W unspecified")}
u<runif(N)
s<W(u,.
..)
return(s)
}
Use this function sample from random variables with the following CDFs:
Normal Distribution:
Use a mean of 4 and a standard deviation of 7 and the
qnorm
function
Hyperbolic Secant:
F
(
x
) =
2
π
tan

1
±
exp
(
π
2
x
)²
Gumbel Distribution:
F
(
x
) = exp
±

exp
(

x

a
b
)²
for
a
= 6 and
b
= 3.
2 Using Optimize
Suppose that we have the CDF
F
(
x
) =
1+
x
2
1+
x
2
+exp(

x
)
. Since
F

1
cannot be solved for analyt
ically, we will have to ﬁnd it computationally. Write a function using
optimize
which will
compute
F

1
(
p
). Use this function to sample
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
This note was uploaded on 01/29/2012 for the course STAT 6866 taught by Professor Womack during the Fall '11 term at University of Florida.
 Fall '11
 Womack
 Probability

Click to edit the document details