RANDOM NUMBER GENERATORS USING DYNAMICAL SYSTEMS REU Project Zsuzsanna HORVÁTH∗ Department of Mathematics, University of Utah Faculty Mentor: Davar Khoshnevisan ∗ Supported in part by NSF and NSF–VIGRE grants 1 Contents 1 Introduction 3 2 Basic Root Finding 2.1 A Simple Example . . . . . . . . . . . . . 2.2 Generalization . . . . . . . . . . . . . . . . 2.3 A Numerical Example for a Nice Function 2.4 An Additional Example . . . . . . . . . . . . . . 5 5 6 6 7 . . . . . . 7 7 8 8 12 12 14 . . . . . . . . 3 Simulations 3.1 White Noise? . . . . . . . . . . . . . . . . . . 3.2 Cauchy Distribution . . . . . . . . . . . . . . 3.3 Proof: Sequence Has The Cauchy Distribution 3.4 Distribution for Other Functions . . . . . . . . 3.5 Further Analysis . . . . . . . . . . . . . . . . 3.6 Unique Tangent Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Other Generators 15 4.1 Generating Normals from Uniform Distribution . . . . . . . . . . . . . . . 15 4.2 Generating Uniforms Using Dynamical Systems . . . . . . . . . . . . . . . 16 5 Independence 18 5.1 Testing for Independence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 6 Appendix 20 7 Bibliography 25 2 1 Introduction Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin. John Von Neumann Numbers that are chosen at random have numerous applications in many fields, such as simulations, sampling, numerical analysis and computer programming. When we refer to randomness, we do not mean a random number; there is no such thing. There is nothing random about any one number. Instead, we refer to a sequence of independent random variables with a specified distribution. Hence, each number was obtained by chance, and has no relationship to any other number in the sequence. At any point, all integers have an equal chance of occurring, and they occur in an unpredictable fashion. To retrieve random numbers from a table is a relatively inefficient and time–consuming practice. Since the advent of computer technology, people have been trying to search for more efficient ways to obtain random numbers using computer programs. There has been, and still is, an interest in the production of random numbers using a computer’s arithmetic capabilities. The main challenge is how do you create a random sequence when each number is dependent upon its predecessor? The answer is that the sequence itself is not random; it just appears to be. The main purpose is to obtain sequences that behave as if they are random. Statistics allows for quantitative measures for randomness. The two most useful and well–known test procedures for studying random data, the chi-square test and the Kolmogorov–Smirnov test, are both used in this paper. The chi-square test allows us to give a probabilistic answer; we can say how probable or improbable certain types of events are. The details are given later in the paper. The chi–square test applies to the situation when observations fall into a finite number of categories. The Kolmogorv–Smirnov test can be used for random quantities that range over infinitely many values. An example of this is a random real number on the interval [0,1]. Even though the computer can only represent finitely many real numbers, we want our random values to behave as if all real numbers in the interval for equally likely. In order to specify the distribution of the values of a random quantity, X, we define the distribution function F (x) = P (X ≤ x). If we take n independent observations of the random quantity, X, i.e. X1 , X2 . . . Xn , we can create the empirical distribution function, Fn (x) = n X i=1 I (Xi ≤ x) , where I(A) denotes the indicator of event A. 3 1.5 1.0 0.5 0.0 −0.5 −1.0 −1.5 0 1000 2000 3000 4000 5000 Figure 1.1 5000 pseudo-random numbers As n gets large, Fn (x) should be a better and better approximation to F (x). The Kolmogorov–Smirnov test is based on the differences between F (x) and Fn (x). A good source of random numbers will provide empirical distribution functions that approximate F (x) sufficiently well. The Kolmogorov–Smirnov test is used to determine how improbable deviations between F (x) and Fn (x) are. The difference between the Kolmogorov–Smirnov test and the chi–squared test is that the Kolmogorov–Smirnov test applies to distribution functions, F (x), having no jumps, while the chi-square test allows for points of discontinuity (i.e. jumps). This is because all observations fall into a specified number of categories. In this paper, we use the Newton–Raphson process to generate a sequence of random numbers. We show that these numbers are independent using both the chi–squared test as well as the Kolmogorov–Smirnov test. Furthermore, we show that the process can be used to generate uniform random variables, which can then be transformed into standard normal data using the Box–Muller transformation method. As a final test for independence, we analyze the sample variance. 4 2 Basic Root Finding 2.1 A Simple Example Let us compute equation √ 7. First, we must consider the problem as finding the solution of the f (x) = x2 − 7 = 0. It is difficult to solve this problem numerically, hence we use a method by which to √ approximate a function near a given point using its tangent line. We know that 7 lies between 2 and 3, so we use one of these points, say x0 = 2, and use the linear approximation at x0 = 2. Recall, f (x) = x2 − 7. Hence, f ′ (x) = 2x. The linear approximation then becomes f (x) ≈ f (x0 ) + f ′ (x0 )(x − x0 ) Making our substitutions yields: f (x) ≈ −3 + 4(x − 2) = 4x − 11 We now approximate the solution to f (x) = 0 by the solution to 4x − 11 = 0. This yields x = 11 = 2.75. This process produces a relatively good approximation, since the 4√ true value of 7 is 2.645751. In order to gain more accuracy, we repeat the process using the new approximate solution. Hence, we will define x1 = 11 and perform the linear 4 approximation at this new point. f (x) ≈ f (x1 ) + f ′ (x1 )(x − x1 ) 11 11 121 − 7) + (x − ) 16 2 4 We define x2 as the solution to f (x) = 0. Solving the above equations gives that x2 = √ 233 7 than x1 . If we = 2.647727.Please note that x is an even better approximation for 2 88 continued this process, we would be generating closer and closer approximations. This process is, in essence, the Newton Method. f (x) ≈ ( 5 2.2 Generalization We can now generate approximate solution to the equation f (x) = 0 using this algorithm. Let us assume that x0 is a point that we believe is relatively close to the solution of the equation. We can take a linear approximation at x0 and solve the corresponding linear equation. More precisely, we define x1 as the solution to the linear equation f (x0 ) + f ′ (x0 )(x − x0 ) = 0. Rearranging the equation above, we obtain that x1 − x0 = − f (x0 ) f ′ (x0 ) and hence, x1 = x0 − f (x0 ) f ′ (x0 ) where, x1 can be thought of as the root of the line that is tangent to the plot of f over x0 . Similar calculations show that x2 = x1 − f (x1 ) f ′ (x1 ) where f ′ (x1 ) is the slope of the tangent to f at the point (x1 , f (x1 )). Continuing this process we define xn = xn−1 − 2.3 f (xn−1 ) , f ′ (xn−1 ) n = 1, 2, 3 . . . A Numerical Example for a Nice Function Let us consider an example where we want to find the root of the function, f (x) = x3 − x + 4. Assume we have chosen x0 = −1 for out initial guess. To perform the Newton–Raphson iteration, we need to know the derivative, f ′ (x) = 3x2 − 1. Hence, xn = xn−1 − x3n−1 − xn−1 + 4 3x2n−1 − 1 Using our initial guess of x0 = −1 we can produce the following values: 6 x0 x1 x2 x3 x4 x5 = −1.000000 = −3.000000 = −2.230769 = −1.881119 = −1.800478 = −1.796333 x6 = −1.796322 x7 = −1.796322 x8 = −1.796322 x9 = −1.796322 x10 = −1.796322 x11 = −1.796322 Note that the last few values of xn became closer and closer to the same value. Hence, we have found the approximate solution of xn = −1.796322, after only 5 steps. 2.4 An Additional Example Consider f (x) = sin(x). Let us use the initial value, x0 = 1. We define xn = xn−1 − sin(xn−1 ) . cos(xn−1 ) Using the Newton–Raphson method, we can produce the following values for xn : x0 = 1.0000000 x1 = −.5574077 x2 = .06593645 x3 = −.0000957 x4 = 0.0000000 In this case, we were able to find the xn that satisfies f (xn ) = 0 in 4 steps, demonstrating the efficiency of the Newton–Raphson method. 3 3.1 Simulations White Noise? Figure 3.2 was produced by applying Newton’s method to the function f (x) = x2 + 1, which has no roots. In this case, as the approximations get closer and closer to 0, the slope of f (x) becomes more and more horizontal. This means that the corresponding tangent line will cross the x-axis at a position that is extremely far from 0. Hence, the iterations become: a number very close to zero, a number very far from 0, a number very close to 0, and so on; making the process appear to be chaotic. Figure 3.2 shows that each output depends on the previous input, but there will be no convergence to any single value, and no discernible patterns. In essence, it appears to be white noise. In actuality, Newton’s method produces a nonrandom sequence; but due to it’s complexity, the iterations in this 7 1.5 1.0 0.5 0.0 −0.5 −1.0 −1.5 0 1000 2000 3000 4000 5000 Figure 3.1 5,000 iterations of Newton’s Method case misleadingly appear random. To demonstrate this effect, Figures 3.2 and 3.1 were obtained by graphing the arctangent of the iterations: yn = arctan(xn ) In this manner, the values are restricted to be between -1.5 and 1.5. In other words, the random variables will take values in a bounded set. 3.2 Cauchy Distribution Figure 3.3 shows the histogram of 200 iterations of Newton’s Method for the function f (x) = x2 + 1 using an initial value x0 = 0.35. The histogram of 200 steps using an initial value of x0 = 0.25 is displayed in figure 3.4. The density of the Cauchy distribution is plotted over the histogram of the iterations, showing that if a function is not nice, using the Newton–Raphson method will generate a chaotic sequence, which will have Cauchy distribution. 3.3 Proof: Sequence Has The Cauchy Distribution We will prove this claim using 200 iterations of the Newton–Raphson process, with initial value x0 = 0.35 and f (x) = x2 + 1. 8 1.5 1.0 0.5 0.0 −0.5 −1.0 −1.5 0 1000 2000 3000 4000 5000 0.00 0.05 0.10 0.15 0.20 0.25 0.30 Figure 3.2 5,000 iterations of Newton’s Method −40 −30 −20 −10 0 10 Figure 3.3 Histogram of 200 iterations of Newton’s Method for f (x) = x2 + 1 with initial value x0 = 0.35 9 H0 : sequence generated has Cauchy Distribution with parameter: location=0, scale=1 Ha : H0 is not true We will divide the interval into K cells and calculate the number of observations that fall into each cell. We define this as Y1 , Y2 , . . . , Y8 . We define the range of our 8 cells as [−∞, −10), [−10, −8), [−8, −1), [−1, 0), [0, 1), [1, 8), [8, 10), [10, ∞) Let K = 8 and n = 200. Recall, the density of the Cauchy distribution: 1 1 f (x) = . π 1 + x2 We define Ei = 200 Z ti f (x)dx. ti−1 Due to symmetry, −10 1 = E8 E1 = 200 1 + x2 −∞ Z −8 1 1 E2 = 200 = E7 1 + x2 −10 π Z −1 1 1 E3 = 200 = E6 1 + x2 −8 π Z 0 1 1 = E5 . E4 = 200 1 + x2 −1 π Z Recall 1 π K X (Yi − Ei )2 i=1 Ei ∼ χ2 (K − 1) We obtain that: Y1 Y2 Y3 Y4 =4 =1 = 40 = 55 Y5 Y6 Y7 Y8 Using the definition of Ei gives: 10 = 55 = 40 =3 =2 0.15 0.10 0.05 0.00 −50 0 50 100 150 Figure 3.4 Histogram of 200 iterations of Newton’s Method for f (x) = x2 + 1 with initial value x0 = 0.25 E1 E2 E3 E4 = E8 = E7 = E6 = E5 = 6.345104 = 1.571581 = 42.08332 = 50 Using the definition of χ2 we get: (4 − 6.345104)2 (1 − 1.571581)2 (1 − 1.571581)2 (40 − 42.08332)2 + + + + 6.345104 1.571581 1.571581 42.08332 (55 − 50)2 (40 − 42.08332)2 (3 − 1.571581)2 2 − 6.345104)2 + + + ∼ χ2 (7) 50 42.08332 1.571581 6.345104 More succinctly, we have just computed K X (Yi − Ei )2 i=1 Ei = 6.554694. Referencing a standard χ2 table shows that χ2 (7) can be as large as 14.07 with 95% probability. Hence, the null hypothesis that these values are Cauchy cannot be rejected (at a significance level of 5%). Furthermore, the corresponding p-value is 0.476667, which strengthens our conclusion that the null hypothesis cannot be rejected. 11 3.4 Distribution for Other Functions Consider the function f (x) = x4 + 1. Figure 3.5 displays the histogram of 200 iterations of the Newton–Raphson process with initial value x0 = 0.15. The density of the Cauchy distribution (with parameters: location=0, scale=10) is shown plotted on the histogram. Hence, the density of the Cauchy distribution is: 1 1 . f (x) = x 2 10π 1 + ( 10 ) H0 : sequence generated has Cauchy distribution with parameter: location=0, scale=10 Ha : H0 is not true We define the range of our K = 8 cells as: [−∞, −100), [−100, −5), [−5, −1), [−1, 0), [0, 1), [1, 5), [5, 100), [100, ∞). Using the definitions from the previous section, we obtain: Y1 Y2 Y3 Y4 E1 E2 E3 E4 = E8 = E7 = E6 = E5 Hence =5 = 35 = 31 = 15 Y5 Y6 Y7 Y8 = 14 = 35 = 52 = 13 = 6.345104 = 64.13818 = 23.17162 = 6.345104 K X (Yi − Ei )2 i=1 Ei = 52.539 ∼ χ2 (7). Although Figure 3.5 may misleadingly imply otherwise, a χ2 statistic as large as 52.539 implies that these iterations did not come from a Cauchy distribution; the null hypothesis must be rejected. Changing the parameters of the Cauchy distribution does not alter this conclusion. 3.5 Further Analysis In this section, we define a jump to be the changes in sign in the subsequent iterations produced by the Newton–Raphson method. To further examine these jumps, let us con12 0.015 0.010 0.005 0.000 −400 −200 0 200 400 600 Figure 3.5 Histogram of 200 iterations of Newton’s Method for f (x) = x4 + 1 with initial value x0 = 0.15 sider the function f (x) = x4 + 1. We will use an initial value of x0 = 0.15. The first 50 iterations are below: [1] 0.15000000 -73.96157407 -55.47117994 -41.60338349 -31.20253414 [6] -23.40189238 -17.55139978 -13.16350359 -9.87251809 -7.40412876 [11] -5.55248066 -4.16290007 -3.11870966 -2.33079058 -1.72834916 [16] -1.24783955 -0.80721367 -0.13010296 113.42402305 85.06801712 [21] 63.80101243 47.85075836 35.88806649 26.91604446 20.18702052 [26] 15.14023500 11.35510422 8.51615741 6.38671329 4.78907533 [31] 3.58953043 2.68674243 2.00216656 1.47047625 1.02423123 [36] 0.53550044 -1.22639762 -0.78426488 -0.06993388 730.87980871 [41] 548.15985653 411.11989240 308.33991929 231.25493946 173.44120458 [46] 130.08090338 97.56067742 73.17050780 54.87788021 41.15840865 Note the large jump between the values of x0 and x1 . While our initial estimate was a small positive number very close to 0, the next iteration has become a large negative number very far from 0. The iterations from x2 to x18 are progressively becoming closer and closer to 0; that is, until the jump between x18 and x19 This jump has created a large positive number that is once again very far from 0. Due to the fact that f (x) does not have any zeros, we can expect that this process will continue indefinitely; producing a chaotic sequence. To further test this claim, we will perform 100000 iterations of Newton’s 13 1.0 0.8 0.6 0.4 0.2 0.0 −1.0 −0.5 0.0 0.5 1.0 Figure 3.6 Histogram of 100000 randomly generated uniform variables on [-0.7594792 , 0.7598336]. Method and examine the values that the process takes immediately before a jump. A histogram of these values can be found in Figure 3.7. Note that the values lie on the interval [-0.7594792 , 0.7598336]. For comparison, Figure 3.6 contains a histogram of 100000 randomly generated uniform variables on the same interval. 3.6 Unique Tangent Line The values that the Newton Raphson process will generate immediately before a jump are in the interval [-0.7594792 , 0.7598336]. This is because there are two distinct points where the tangent line of the graph at those points will intersect the origin, which implies that before those points the value will stay in the same region, and after those points there will be a jump. We again consider f (x) = x4 + 1 and hence, f ′ (x) = 4x3 . We are interested in the tangent line to the point (x, x4 + 1). This tangent line is defined as g(t) = 4x3 (t − x) + x4 + 1. 14 1.0 0.8 0.6 0.4 0.2 0.0 −1.0 −0.5 0.0 0.5 1.0 Figure 3.7 Histogram of the values that are generated before the jump occurs Solving this for 0, we obtain g(0) = 0 = −4x4 + x4 + 1 0 = −3x4 + 1 r 4 1 x=± = ±.759835. 3 4 4.1 Other Generators Generating Normals from Uniform Distribution We will use the Box-Muller transformation method to generate normal random variables. If x1 and x2 are uniform random variables on (0,1), we define y1 and y2 as follows: y1 = p y2 = p The Jacobian determinant is then: 1 ∂(x1 , x2 ) ∂x ∂y1 J= = ∂x ∂(y1 , y2 ) ∂y12 −2 log(x1 ) cos 2πx2 −2 log(x1 ) sin 2πx2 ∂x1 ∂y2 ∂x2 ∂y2 1 2 = − √ e−y1 /2 2π 15 1 −y22 /2 √ e . 2π 2 0 −4 −2 Sample Quantiles 4 Normal Q−Q Plot −4 −2 0 2 4 Theoretical Quantiles Figure 4.1 Normal QQ plot Since this is a product of a function of y1 alone and a function of y2 alone, we see that each y is independently distributed according to the normal distribution. The details for this method of how to generate independent standard normal random variables is as follows: • Step 1: Generate two uniform random variables, x1 and x2 . • Step 2: Apply the formula above to obtain y1 and y2 . Figure 4.2 displays the histogram of 100000 values that were obtained by using the Box Muller transformation method. The density function of the standard normal distribution is plotted over the histogram. Figure 4.1 shows the QQ plot of these 100000 values. Figures 4.1 and 4.2 both show that using the Box-Muller transformation method will, indeed, generate standard normal data. 4.2 Generating Uniforms Using Dynamical Systems The Newton Raphson process can be used to generate uniform random variables. We begin with an initial value, x0 , and perform 500 iterations of the Newton–Raphson method. We then take the produced xn value and use this as our next initial value. We continue with these steps for 1000000 repetitions. After using this procedure of changing the initial value for each run, we examine the values that occurred before a jump. Figure 4.3 contains the histogram of these values. The results of the Kolmogorov–Smirnov test are below. The 16 0.4 0.3 0.2 0.1 0.0 −4 −2 0 2 4 Figure 4.2 Histogram of 100000 values using Box Muller transformation method p-value is 0.2205, hence we cannot reject that null hypothesis that the values came from a uniform distribution. > ks.test(resultT,"punif") One-sample Kolmogorov--Smirnov test data: resultT D = 0.0493, p-value = 0.2205 alternative hypothesis: two.sided We use the uniform values that were generated using the Newton–Raphson process and perform the Box–Muller transformation on these values. The QQ–plot can be found in Figure 4.4. To further ensure that these value can, indeed, follow a normal distribution, we perform the Kolmogorov–Smirnov test; the results are below. > ks.test(box, "pnorm") One-sample Kolmogorov--Smirnov test data: box D = 0.0568, p-value = 0.4586 17 1.2 1.0 0.8 0.6 0.4 0.2 0.0 0.0 0.2 0.4 0.6 0.8 1.0 Figure 4.3 Histogram of values generated before a jump occurs when the initial value is continuously changed alternative hypothesis: two.sided Hence, we can not reject the null hypothesis that these values are normally distributed. 5 5.1 Independence Testing for Independence We wish to determine if the process outlined in the previous section will generate independent values. We will accomplish this by analyzing the sample variance. We define n−k γ(k) = 1X (Xi − X̄)(Xi+k − X̄) n i=1 k = 1, . . . , n − 1 where X̄ denotes the sample mean of X. The ratio, γ(k) γ(0) denotes the sample variance. If the values are independent, then the plot of this ratio should be around 0.This plot can be found on Figure 5.1. The value of γ(1) γ(0) is 1, all other values fluctuate around 0. Therefore we can make the statement that these values are independent. 18 1 0 −2 −1 Sample Quantiles 2 3 Normal Q−Q Plot −3 −2 −1 0 1 2 Theoretical Quantiles −1.0 −0.5 0.0 0.5 1.0 Figure 4.4 Normal QQ–plot using Dynamical Systems 0 Figure 5.1 Plot of 100 200 γ(k) γ(0) 19 300 400 3 6 Appendix zero<-function(x){ x^2+1 } deriv<-function(x){ 2*x } newton<-function(x0, n){ x<-numeric(0) x[1]<-x0 for (i in 1:n){ x[i+1]=x[i]-zero(x[i])/deriv(x[i]) } return(x) } n<-1000 x0<-4 kk<-1000 y<-numeric(0) for(k in 1:kk) y<-rbind(y,newton(k/1000,n)) yy<-atan(newton(.1,5000)) postscript( ’~/graph1.ps’,horizontal=FALSE,height=6,width=6) plot(yy, type=’l’, xlab="", ylab="") dev.off() xx<-newton(.35,200) postscript( ’~/graph2.ps’,horizontal=FALSE,height=6,width=6) hist(xx, nclass=100, xlab="", ylab="", main="", prob=T) curve(dcauchy(x, location = 0, scale = 1, log = FALSE), add=T) dev.off() h<-runif(5000,-1.5,1.5) postscript( ’~/graph3.ps’,horizontal=FALSE,height=6,width=6) 20 plot(h, xlab="", ylab="", main="5000 pseudo-random numbers") dev.off() xx<-newton(.25,200) postscript( ’~/graph4.ps’,horizontal=FALSE,height=6,width=6) hist(xx, nclass=100, xlab="", ylab="", main="", prob=T) curve(dcauchy(x, location = 0, scale = 1, log = FALSE), add=T) dev.off() integrand<-function(x){(1/(pi))*(1/(1+x^2))} integrate(integrand, lower=-Inf, upper=-10) 1-pchisq(6.554694, df=7) #looks for jumps m=100000 xx<-newton(.15,m) yH=numeric(0) yL=numeric(0) j=1 for(i in 1:m){ if(xx[i]<0 && xx[i+1]>0){ yL[j]=xx[i] #values that function takes before shooting far out yH[j]=xx[i+1] #value it lands on after it shoots off j=j+1 } if(xx[i]>0 && xx[i+1]<0){ yL[j]=xx[i] yH[j]=xx[i+1] j=j+1 } } xx<-newton(.15,200) postscript( ’~/graph6.ps’,horizontal=FALSE,height=6,width=6) hist(xx, nclass=75, xlab="", ylab="", main="", prob=T) 21 curve(dcauchy(x, location = 0, scale = 10, log = FALSE), add=T) dev.off() integrand2<-function(x){(1/(10*pi))*(1/(1+(x/10)^2))} integrate(integrand2, lower=-Inf, upper=-200) postscript( ’~/graph7.ps’,horizontal=FALSE,height=6,width=6) hist(yL, nclass=200, xlim=c(-1,1), ylim=c(0,1), xlab="", ylab="", main="", prob=T) dev.off() postscript( ’~/graph8.ps’,horizontal=FALSE,height=6,width=6) compare<-runif(100000, -0.7594792,0.7598336) hist(compare, nclass=100, xlim=c(-1,1), ylim=c(0,1), xlab="", ylab="", main="", prob=T) dev.off() box<-function(n) { res<-cos(2*pi*runif(n))*sqrt(-2*log(runif(n))) return(res) } postscript( ’~/graph9.ps’,horizontal=FALSE,height=6,width=6) rr<-box(100000) qqnorm(rr); qqline(rr, col="green") dev.off() postscript( ’~/graph10.ps’,horizontal=FALSE,height=6,width=6) rr<-box(100000) hist(rr, nclass=50, xlab="", ylab="", main="", prob=T) curve(dnorm(x, mean = 0, sd = 1, log = FALSE), add=T) dev.off() k=1 result<-numeric(0) 22 while((k*500)<length(yL)){ result[k]=yL[500*k] k=k+1} #picks a point, generates 500 values, takes last one, and runs it again using #the last one as the new starting point resultT<- (result+max(yL))/(max(yL)) box<-cos(2*pi*resultT[1:226])*sqrt(-2*log(resultT[228:453])) postscript( ’~/uniform1.ps’,horizontal=FALSE,height=6,width=6) hist(resultT, nclass=9, xlim=c(0,1), xlab="", ylab="", main="", prob=T) dev.off() postscript( ’~/box1.ps’,horizontal=FALSE,height=6,width=6) qqnorm(box); qqline(box, col="green") dev.off() #tests for independece: n=453 gam<-numeric(n) for (k in 0:(n-1)){ gam[k+1]<-(1/n)*sum((resultT[1:(n-k)]-mean(resultT))*(resultT[(k+1):n] -mean(resultT))) } gam0=(1/n)*sum((resultT-mean(resultT))^2) #the ratio of gam[1:n]/gam[1] is the sample variance, it should be #around 0 if the values are independent. postscript( ’~/gam2.ps’,horizontal=FALSE,height=6,width=6) plot(gam[1:n]/gam[1], ylim=c(-1,1), type="l", xlab="", ylab="") dev.off() 23 24 7 Bibliography Bain, L.J., Engelhardt, M.(1992). Introduction to Probability and Mathematical Statistics (Second Edition). Duxbury Thomson Learning: United Kingdom.109,118,150,268. Devaney, R.L. (1992). A First Course in Chaotic Dynamical Systems. Addison-Wesley Publishing Company, Inc: New York. 164-173. Knuth, D.E. (1998). The Art of Computer Programming (Third Edition) Volume 2. Addison-Wesley: MA. 48-60. Ross, S.M. (2003). Introduction to Probability Models (Eighth Edition). Academic Press: MA. Ross, S.M. (2002). Simulation (Third Edition). Academic Press: MA. 25