labsep2 - Lab 2: Generating Random Variables Andrew J....

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
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 find it computationally. Write a function using optimize which will compute F - 1 ( p ). Use this function to sample
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
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.

Page1 / 2

labsep2 - Lab 2: Generating Random Variables Andrew J....

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online