CS代考程序代写 University of California, Los Angeles Department of Statistics

University of California, Los Angeles Department of Statistics
Statistics 100B Instructor: Nicolas Christou
Simulating a continuous random variable
Many times computer simulations are used to evaluate proposed statistical techniques. Typ- ically, these simulations require that we obtain observed values of random variables with a prescribed distribution. Most computer systems contain a subroutine that provides ob- served values of a uniform random variable on the interval [0,1]. Let X1,X2,···,Xn be a random sample from this distribution. How can we use these values to generate n obser- vations Y1, Y2, · · · , Yn from an exponential distribution with parameter λ, Y ∼ exp(λ)? As a reminder the probability density function (pdf) of an exponential random variable Y is f(y) = λe−λy,y ≥ 0, and the cumulative distribution function (cdf) is F(y) = 1−e−λy,y ≥ 0.

Example:
Suppose we want to generate 100 values form the exponential distribution with parameter λ = 0.25. We will first generate 100 values from uniform [0, 1]. Here they are:
> x <- runif(100); x [1] 0.051018780 0.633835176 0.316826761 0.428229412 0.907661578 0.993477130 [7] 0.750858171 0.805013227 0.414591927 0.822393034 0.856314588 0.016146515 [13] 0.071784463 0.122571166 0.613897717 0.001209994 0.954154581 0.351573293 [19] 0.410093796 0.007272958 0.603123222 0.747129264 0.626160788 0.477646846 [25] 0.050995086 0.984879869 0.293646467 0.250682793 0.322653704 0.566582250 [31] 0.205673748 0.316166543 0.128313377 0.699693979 0.055456475 0.903748008 [37] 0.357488344 0.197242119 0.997325008 0.915138927 0.384455960 0.254831758 [43] 0.440502153 0.912334391 0.263937093 0.522613614 0.546005381 0.945161675 [49] 0.394401442 0.644344347 0.983463021 0.563307032 0.879276463 0.406286849 [55] 0.758659304 0.125155509 0.535370943 0.770937048 0.567509420 0.787695544 [61] 0.029144404 0.845371360 0.690853273 0.520675362 0.985960909 0.680727438 [67] 0.780857383 0.907264206 0.504714281 0.052280051 0.120086492 0.685356938 [73] 0.660381331 0.422037191 0.509566451 0.300926229 0.726050804 0.455755142 [79] 0.924619806 0.956001621 0.574201672 0.270501456 0.418710439 0.482915046 [85] 0.905365532 0.552876442 0.216049740 0.889648968 0.039285457 0.395933149 [91] 0.383691375 0.079916710 0.880780600 0.717155750 0.074550390 0.032717140 [97] 0.753688467 0.272438001 0.457411286 0.075257131 Histogram of 100 values from uniform(0,1) 0.0 0.2 0.4 0.6 0.8 1.0 x Frequency 0 5 10 15 20 25 We transform these values using y = log(1−x). Here are the transformed values: −λ > y=log(1-x)/(-0.25); y
[1] 0.209465081 4.018686828 1.524027227 2.236069749 9.529179821
[6] 20.129763167 5.558931804 6.539294215 2.141784458 6.912728913
[11] 7.760516035 0.065113163 0.297965253 0.523037713 3.806611852
[16] 0.004842908 12.329919957 1.732825206 2.111166924 0.029198139
[21] 3.696517720 5.499507380 3.935717955 2.597645516 0.209365209
[26] 16.766913048 1.390557650 1.154371513 1.558290483 3.344212941
[31] 0.921044024 1.520163498 0.549301190 4.811813023 0.228214044
[36] 9.363142438 1.769481284 0.878808512 23.695235960 9.866959171
[41] 1.940995139 1.176581032 2.322862399 9.736902397 1.225758771
[46] 2.957716331 3.158679736 11.613463846 2.006151834 4.135169128
[51] 16.408624959 3.314099683 8.457008650 2.085435946 5.686182672
[56] 0.534836532 3.066063676 5.895033653 3.352778933 6.198935687
[61] 0.118310152 7.466915630 4.695757075 2.941508683 17.063638551
[66] 4.566840454 6.072130168 9.512002999 2.810481894 0.214784931
[71] 0.511726649 4.625265677 4.319727412 2.192983023 2.849861939
[76] 1.431996019 5.179250425 2.433424109 10.340842870 12.494409965
[81] 3.415157814 1.261591625 2.170025053 2.638192391 9.430934038
[86] 3.219681226 0.973638816 8.816355190 0.160311822 2.016281626
[91] 1.936029706 0.333164323 8.507159160 5.051435544 0.309902377
[96] 0.133057252 5.604632603 1.272224248 2.445614717 0.312958237
Histogram of 100 values from exponential(0.25)
0 5 10 15 20 25
y
Verify that y = log(1−x) follows indeed the exponential distribution with parameter λ. −λ
Frequency
0 10 20 30 40 50 60 70

Leave a Reply

Your email address will not be published. Required fields are marked *