Presentation is loading. Please wait.

Presentation is loading. Please wait.

Random Numbers and Simulation  Generating truly random numbers is not possible Programs have been developed to generate pseudo-random numbers Programs.

Similar presentations


Presentation on theme: "Random Numbers and Simulation  Generating truly random numbers is not possible Programs have been developed to generate pseudo-random numbers Programs."— Presentation transcript:

1 Random Numbers and Simulation  Generating truly random numbers is not possible Programs have been developed to generate pseudo-random numbers Programs have been developed to generate pseudo-random numbers Values are generated from deterministic algorithms Values are generated from deterministic algorithms 1 © Fall 2011 John Grego and the University of South Carolina

2 Random Numbers Pseudo-random deviates can pass any statistical test for randomness Pseudo-random deviates can pass any statistical test for randomness They appear to be independent and identically distributed They appear to be independent and identically distributed Random number generators for common distributions are available in R Random number generators for common distributions are available in R Special techniques (STAT 740) may be needed as well Special techniques (STAT 740) may be needed as well 2

3 Monte Carlo Simulation  Some common uses of simulation Modeling stochastic behavior Modeling stochastic behavior Calculating definite integrals Calculating definite integrals Approximating the sampling distribution of a statistics (e.g., maximum of a random sample) Approximating the sampling distribution of a statistics (e.g., maximum of a random sample) 3

4 Modeling Stochastic Behavior  Buffon’s needle  Random Walk  Observe X 1, X 2, …, where p=P(X i =1)=P(X i =-1)=.5 and study S 1,S 2,…, where 4

5 Modeling Stochastic Behavior  This is also called Gambler’s ruin; each X i represents a $1 bet with a return of $2 for a win and $0 for a loss. 5

6 Gambler’s Ruin  The properties of a fair game (p=.5) are a lot more interesting than the properties of an unfair game (p≠.5)  Some properties of this process are easy to anticipate (E(S)) 6

7 Gambler’s Ruin  Some properties are difficult to anticipate, and can be aided by simulation. Expected number of returns to 0 Expected number of returns to 0 Expected length of a winning streak Expected length of a winning streak Probability of going broke given an initial bank Probability of going broke given an initial bank 7

8 Calculating Definite Integrals In statistics, we often have to calculate difficult definite integrals (posterior distributions, expected values) In statistics, we often have to calculate difficult definite integrals (posterior distributions, expected values) (here, x could be multidimensional) 8

9 Calculating Definite Integrals Example 1 Example 1 Example 2 Example 2 9

10 Hit-or-Miss Monte Carlo Example 1 Example 1 Determine c such that c≥h(x) across entire region of interest (here, c=4) Determine c such that c≥h(x) across entire region of interest (here, c=4) 10

11 Hit-or-Miss Monte Carlo Generate n random uniform (X i,Y i ) pairs, X i ’s from U[a,b] (here, U[0,1]) and Y i ’s from U[0,c] (here, U[0,4]) Generate n random uniform (X i,Y i ) pairs, X i ’s from U[a,b] (here, U[0,1]) and Y i ’s from U[0,c] (here, U[0,4]) Count the number of times (call this m) that Y i is less than h(X i ) Count the number of times (call this m) that Y i is less than h(X i ) Then I 1 ≈c(b-a)m/n Then I 1 ≈c(b-a)m/n I.e., (height)(width)(proportion under curve) I.e., (height)(width)(proportion under curve) 11

12 Classical Monte Carlo Integration Take n random uniform values, U 1,…,U n over [a,b] and estimate I using Take n random uniform values, U 1,…,U n over [a,b] and estimate I using This method seems straightforward, but is actually more efficient than Hit-or-Miss Monte Carlo This method seems straightforward, but is actually more efficient than Hit-or-Miss Monte Carlo 12

13 Expected Value of a Function of a Random Variable Suppose X is a random variable with density f. Find E[h(x)] for some function h, e.g., Suppose X is a random variable with density f. Find E[h(x)] for some function h, e.g., 13

14 Expected Value of a Function of a Random Variable For n random values X 1, X 2, …, X n from the distribution of X (i.e., with density f), For n random values X 1, X 2, …, X n from the distribution of X (i.e., with density f), 14

15 Examples Example 3: If X is a random variable with a N(10,1) distribution, find E(X 2 ) Example 3: If X is a random variable with a N(10,1) distribution, find E(X 2 )  Example 4: If Y is a random variable with a Beta(5,1) distribution, E(-lnY) There are more advanced methods of integration using simulation (Importance Sampling) There are more advanced methods of integration using simulation (Importance Sampling) 15

16 Integration integrate() performs numerical integration for functions of a single variable (not using simulation techniques) integrate() performs numerical integration for functions of a single variable (not using simulation techniques) adapt() in the adapt package performs multivariate numerical integration adapt() in the adapt package performs multivariate numerical integration 16

17 Approximating the Sampling Distribution of a Statistic To perform inference (CI’s, hypothesis tests) based on sampling statistics, we need to know the sampling distribution of the statistics, at least up to an approximation To perform inference (CI’s, hypothesis tests) based on sampling statistics, we need to know the sampling distribution of the statistics, at least up to an approximation Example: X 1, X 2, …, X n ~ iid N( ,  2 ). Example: X 1, X 2, …, X n ~ iid N( ,  2 ). 17

18 Approximating the Sampling Distribution of a Statistic What if the data’s distribution is not known? What if the data’s distribution is not known? Large sample: Central Limit Theorem Large sample: Central Limit Theorem Small sample: Normal theory or nonparametric procedures based on permutation distributions Small sample: Normal theory or nonparametric procedures based on permutation distributions 18

19 Approximating the Sampling Distribution of a Statistic If the population distribution is known, we can approximate the sampling distribution with simulation. If the population distribution is known, we can approximate the sampling distribution with simulation. Repeatedly (m times) generate random samples of size n from the population distribution Repeatedly (m times) generate random samples of size n from the population distribution Calculate a statistic (say, S) each time Calculate a statistic (say, S) each time The empirical (observed) distribution of S- values approximates the true distribution of S The empirical (observed) distribution of S- values approximates the true distribution of S 19

20 Example X 1, X 2, X 3, X 4 ~Expon(1) X 1, X 2, X 3, X 4 ~Expon(1) What is the sampling distribution of: What is the sampling distribution of: 20


Download ppt "Random Numbers and Simulation  Generating truly random numbers is not possible Programs have been developed to generate pseudo-random numbers Programs."

Similar presentations


Ads by Google