Question

In: Math

Use R to complete the following questions. You should include your R code, output and plots...

Use R to complete the following questions. You should include your R code, output and plots in your answer.

Two methods of generating a standard normal random variable are:

a. Take the sum of 5 uniform (0,1) random numbers and scale to have mean 0 and standard deviation 1. (Use the properties of the uniform distribution to determine the required transformation).

b. Generate a standard uniform and then apply inverse cdf function to obtain a normal random variate (Hint: use qnorm).


QUESTION 1.

For each method generate 10,000 random numbers and check the distribution using

a. Normal probability plot

b. Mean and standard deviation

c. The proportion of the data lying within the theoretical 2.5 and 97.5 percentiles and the 0.5 and 99.5 percentiles. (Hint: The ifelse function will be useful)

Solutions

Expert Solution

Algorithm:
Step 1: Generate uniform random number of size n (say).
Step 2: Use the inversion formula for particular distribution to generate the random from that distribution.

> ######generate Unifrom random number (sample size = 5)
> u1=runif(n=5,0,1)
> u1
[1] 0.3807355 0.6838301 0.5793533 0.7001886 0.1476591
> sum(u1) ###sum of 5 uniform (0,1) random numbers
[1] 2.491767
> ####### Generate a standard uniform number use qnorm.
> u2=runif(5);u1
[1] 0.3807355 0.6838301 0.5793533 0.7001886 0.1476591
> u=qnorm(u2);u
[1] 1.9863522 -0.4100890 0.3649655 -1.2394764 0.2776269
> ####### Q.1
> u3=runif(1000);u3
[1] 0.178273742 0.338654670 0.502983252 0.574192463
[5] 0.938588518 0.164298457 0.568822881 0.277261303
[9] 0.587949903 0.822968805 0.486584451 0.308141776
[13] 0.057207227 0.523044843 0.481863485 0.357590487
[17] 0.278691400 0.547701614 0.912094467 0.255963780
[21] 0.017637369 0.827254662 0.049479483 0.595249967
[25] 0.981266572 0.569439175 0.727461077 0.151835970
[29] 0.318237809 0.699689800 0.854843975 0.378279480
[33] 0.275432114 0.988443919 0.134025161 0.977952887
[37] 0.642202243 0.600516791 0.162106824 0.143829044
[41] 0.762430230 0.781958816 0.217104930 0.714697188
[45] 0.293083606 0.271073145 0.903164100 0.934551410
[49] 0.452999341 0.329169206 0.398795732 0.169447463
[53] 0.209013989 0.827561936 0.347139587 0.599187326
[57] 0.452403407 0.093152807 0.896113889 0.262902533
[61] 0.711164872 0.249534035 0.896619297 0.174416814
[65] 0.468116865 0.795492926 0.341465854 0.478540409
[69] 0.260783592 0.985835146 0.438381592 0.730666561
[73] 0.680872272 0.907649460 0.760866767 0.853651691
[77] 0.254686764 0.453843033 0.784928615 0.591713174
[81] 0.988043745 0.927597355 0.885562700 0.569294132
[85] 0.919895268 0.290173398 0.256231378 0.720954146
[89] 0.162788707 0.482136352 0.980341022 0.714786028
[93] 0.603208002 0.756598214 0.042582439 0.892577048
[97] 0.766692444 0.472288112 0.897595979 0.407147537
[101] 0.767170512 0.941631244 0.765189774 0.650673144
[105] 0.923338404 0.270001958 0.960051585 0.441324859
[109] 0.262421818 0.362591780 0.902642826 0.294795499
[113] 0.214329107 0.052150619 0.936144301 0.840517639
[117] 0.612928761 0.048513069 0.269719144 0.760647244
[121] 0.917457117 0.042594744 0.623126212 0.025791519
[125] 0.996860833 0.177718724 0.654859019 0.661239052
[129] 0.820549976 0.876687104 0.082439308 0.830690825
[133] 0.417017611 0.066647755 0.104336319 0.731123660
[137] 0.594064977 0.534583113 0.048505401 0.615337142
[141] 0.738851126 0.117799712 0.366601524 0.135035213
[145] 0.297117565 0.908073284 0.112918757 0.564549285
[149] 0.008583148 0.787502195 0.807160685 0.509219521
[153] 0.478424136 0.403077338 0.543652771 0.007867210
[157] 0.173895296 0.896861917 0.519487014 0.973213919
[161] 0.805484351 0.949031616 0.285357425 0.619058772
[165] 0.795161493 0.935566761 0.526652905 0.831893430
[169] 0.800116418 0.658076967 0.995597235 0.845622191
[173] 0.879890635 0.482919763 0.094897597 0.028267485
[177] 0.009439711 0.823091849 0.043040400 0.823170943
[181] 0.091859132 0.864137657 0.022668031 0.050639909
[185] 0.949141232 0.228148169 0.626769278 0.439620057
[189] 0.599773124 0.968633908 0.994204796 0.273533738
[193] 0.287168470 0.199977183 0.196244740 0.991003036
[197] 0.955346841 0.506245054 0.236431236 0.517316789
[201] 0.577782649 0.218334426 0.222556222 0.825124176
[205] 0.363241312 0.924038738 0.320962447 0.120048779
[209] 0.210499389 0.559180991 0.403326527 0.789544941
[213] 0.471045552 0.873281119 0.176097968 0.305159749
[217] 0.395722471 0.004994244 0.898505884 0.424280648
[221] 0.020754369 0.632583446 0.253635833 0.789984525
[225] 0.114601608 0.069106708 0.200499010 0.293540743
[229] 0.391404357 0.353940719 0.003051260 0.304292710
[233] 0.531214076 0.863909848 0.259208594 0.093974944
[237] 0.083889605 0.257744178 0.086540011 0.117788461
[241] 0.186304734 0.069494832 0.338623188 0.860353916
[245] 0.781542517 0.277202218 0.723161361 0.633321233
[249] 0.156334724 0.152739369 0.158851962 0.895088423
[253] 0.289939353 0.018619489 0.049620316 0.593186052
[257] 0.241353801 0.304142122 0.794493628 0.750661148
[261] 0.589345373 0.136211386 0.627481826 0.864842833
[265] 0.597692031 0.197969936 0.982050263 0.131674617
[269] 0.181336075 0.788943350 0.236138895 0.860342829
[273] 0.419425327 0.651857140 0.579699595 0.323007263
[277] 0.431335230 0.417773142 0.522972820 0.432197149
[281] 0.182775282 0.070289564 0.964844320 0.542852027
[285] 0.748663097 0.554676080 0.680594160 0.250223322
[289] 0.284464552 0.126662511 0.693831057 0.880094765
[293] 0.968801859 0.317698028 0.045397989 0.949943755
[297] 0.400208505 0.371284345 0.324154023 0.560770155
[301] 0.091314258 0.774883735 0.413061508 0.823627154
[305] 0.365933198 0.883123858 0.245355511 0.594524894
[309] 0.365887217 0.745536448 0.011344925 0.925059291
[313] 0.869512550 0.638616879 0.295088985 0.935575329
[317] 0.663063156 0.618219852 0.561209138 0.176157437
[321] 0.520921070 0.711753411 0.925892704 0.067051924
[325] 0.236690307 0.695405485 0.332264071 0.113306195
[329] 0.939782017 0.372087179 0.706058034 0.751002471
[333] 0.403755571 0.227361978 0.273286580 0.072920854
[337] 0.910408618 0.459842255 0.600472450 0.275654292
[341] 0.973215841 0.873161961 0.751179213 0.136125233
[345] 0.655204212 0.080378616 0.265310630 0.223805349
[349] 0.498866989 0.924211003 0.800580584 0.806108595
[353] 0.664286047 0.229822823 0.286321921 0.061472379
[357] 0.949580774 0.649938368 0.617928571 0.072906912
[361] 0.494374668 0.440830963 0.013917039 0.248682106
[365] 0.171046166 0.345438675 0.456405981 0.654901610
[369] 0.953590865 0.726935534 0.247356471 0.613288462
[373] 0.128787193 0.052366293 0.567321367 0.740011448
[377] 0.750754249 0.352847454 0.125696890 0.866560883
[381] 0.069579976 0.650474829 0.244731351 0.329884567
[385] 0.274328860 0.979834995 0.913374244 0.674176028
[389] 0.326536032 0.148618585 0.579086140 0.477506300
[393] 0.960701694 0.157627866 0.002057758 0.086027329
[397] 0.238918506 0.590526449 0.435348495 0.597216841
[401] 0.762081118 0.789204862 0.470843896 0.934225282
[405] 0.645869571 0.665627897 0.270417793 0.502791649
[409] 0.638165310 0.534609866 0.806940141 0.806592199
[413] 0.497163989 0.166165425 0.547377223 0.185009908
[417] 0.847412064 0.154381476 0.697753233 0.821393932
[421] 0.387256954 0.753594385 0.799000961 0.051941172
[425] 0.888509980 0.764760763 0.341600794 0.123064455
[429] 0.173528212 0.565935960 0.346349916 0.853956492
[433] 0.203340870 0.216345853 0.590784603 0.713518189
[437] 0.339589359 0.375325617 0.243176455 0.887737171
[441] 0.112777991 0.742362105 0.044284578 0.720649027
[445] 0.863230416 0.039876486 0.721131758 0.326834837
[449] 0.726444875 0.032174349 0.372234785 0.415885718
[453] 0.121231657 0.407248453 0.424385557 0.357479038
[457] 0.830057639 0.365814243 0.293699471 0.374506313
[461] 0.719548796 0.100653077 0.691715453 0.235637697
[465] 0.779742779 0.282059433 0.706762615 0.619718383
[469] 0.544563180 0.924641102 0.531242341 0.271171188
[473] 0.905813898 0.020223106 0.779149749 0.364991618
[477] 0.307303057 0.160867940 0.176943196 0.693851550
[481] 0.621652109 0.468918368 0.869892344 0.693520504
[485] 0.506954286 0.913280662 0.812330135 0.404537447
[489] 0.794142246 0.017007901 0.548779433 0.254125526
[493] 0.253319016 0.624762121 0.090745371 0.460815903
[497] 0.913422323 0.485198421 0.388692948 0.171777135
[501] 0.677473963 0.292836735 0.075758994 0.719629838
[505] 0.132899838 0.991176752 0.098000679 0.837644470
[509] 0.548980407 0.983141540 0.703873824 0.281914421
[513] 0.253390006 0.177424038 0.002899268 0.454129540
[517] 0.992385163 0.816874481 0.066406031 0.898935678
[521] 0.829591758 0.024087609 0.472519187 0.272334988
[525] 0.336495083 0.057294943 0.205245066 0.869877560
[529] 0.940513984 0.960492567 0.123542711 0.881292025
[533] 0.565366857 0.532137827 0.599130224 0.057422890
[537] 0.152380878 0.322147847 0.617132141 0.080236230
[541] 0.957498794 0.928580394 0.950919238 0.106630008
[545] 0.557867326 0.742990294 0.342305454 0.370324479
[549] 0.661520795 0.077816255 0.189265553 0.408123146
[553] 0.212645051 0.980271553 0.455587409 0.955461214
[557] 0.027056524 0.040871849 0.516093694 0.102335132
[561] 0.762620967 0.161880870 0.168592367 0.857959896
[565] 0.060331176 0.329365385 0.821863838 0.446692215
[569] 0.958970293 0.770069090 0.251505435 0.219794163
[573] 0.975352971 0.647225778 0.646266310 0.638372786
[577] 0.096874715 0.459759643 0.963887846 0.921417943
[581] 0.200894469 0.305496338 0.087948175 0.489524599
[585] 0.390109701 0.178165076 0.226199844 0.341700639
[589] 0.126379829 0.065163645 0.277436177 0.600410688
[593] 0.273144482 0.941489053 0.799276451 0.089914952
[597] 0.392770776 0.174849976 0.456753087 0.481765486
[601] 0.142861928 0.034419505 0.202051959 0.264258587
[605] 0.744757670 0.353446902 0.877193653 0.135480624
[609] 0.570409286 0.412244422 0.225636233 0.797575301
[613] 0.398676400 0.591562685 0.906964443 0.384809852
[617] 0.371891612 0.374291895 0.182152950 0.041934537
[621] 0.261202744 0.304963026 0.178527893 0.558146396
[625] 0.371059665 0.642810347 0.924115872 0.259350448
[629] 0.239350285 0.848965338 0.699011598 0.884429610
[633] 0.209242901 0.528550479 0.228069716 0.102115365
[637] 0.102061887 0.150018109 0.116709932 0.626661309
[641] 0.515648632 0.670773006 0.861331310 0.636687285
[645] 0.570006530 0.894844278 0.275015817 0.490434975
[649] 0.946826611 0.142462477 0.174120710 0.886910460
[653] 0.507694072 0.190409639 0.562036618 0.547679755
[657] 0.893743749 0.704780649 0.561151840 0.447658210
[661] 0.105691165 0.658082008 0.168128955 0.486573109
[665] 0.167834845 0.129795962 0.416056700 0.255846069
[669] 0.693765950 0.249083919 0.958213799 0.764405156
[673] 0.841369813 0.875609934 0.009615549 0.036116867
[677] 0.285924633 0.080531561 0.968794668 0.564562469
[681] 0.984704898 0.836638826 0.880193851 0.244424738
[685] 0.732067207 0.498606006 0.503376291 0.568116239
[689] 0.652677042 0.064712493 0.676612402 0.735371693
[693] 0.111299667 0.046654618 0.130910312 0.880956365
[697] 0.839725489 0.868142720 0.033382926 0.107906996
[701] 0.549296889 0.109317743 0.722590516 0.725010276
[705] 0.789521863 0.617478245 0.503007366 0.456149423
[709] 0.034665802 0.209638843 0.342787279 0.545594801
[713] 0.769484416 0.428764684 0.686461671 0.521868988
[717] 0.796536368 0.903052028 0.432457164 0.331940473
[721] 0.917114556 0.209279713 0.812734745 0.300712818
[725] 0.572182454 0.386782175 0.279481675 0.260042868
[729] 0.959383609 0.634132585 0.081877257 0.926206241
[733] 0.890942530 0.912085011 0.718498562 0.682527713
[737] 0.555186460 0.401709436 0.863837790 0.074413949
[741] 0.283284486 0.162637435 0.763896585 0.116375717
[745] 0.167471821 0.475883521 0.005788442 0.974413290
[749] 0.114147759 0.080774309 0.322919441 0.118785095
[753] 0.985772469 0.404147644 0.241781906 0.354878908
[757] 0.153240084 0.287547626 0.256672147 0.157690251
[761] 0.029771646 0.811628372 0.579172815 0.576731940
[765] 0.701486865 0.063766200 0.502482899 0.383949951
[769] 0.426416348 0.544390162 0.643638207 0.791192387
[773] 0.846853398 0.072626310 0.860110642 0.956164637
[777] 0.926419157 0.053963660 0.246409464 0.487369670
[781] 0.100063382 0.195159257 0.213571525 0.207682233
[785] 0.028771427 0.234566428 0.107185220 0.277315790
[789] 0.696021955 0.266257392 0.660476814 0.212416518
[793] 0.005266102 0.102902506 0.287400001 0.444156097
[797] 0.692992780 0.020884316 0.955751769 0.804110624
[801] 0.911739890 0.309466796 0.323927877 0.138359778
[805] 0.957560620 0.232669176 0.023714907 0.052111627
[809] 0.932719734 0.038751502 0.807113662 0.696882099
[813] 0.388050787 0.390583366 0.982332567 0.216765057
[817] 0.566959663 0.980335618 0.574558311 0.632866844
[821] 0.782992921 0.856875613 0.041593013 0.895225023
[825] 0.188516586 0.387341884 0.494502024 0.370316362
[829] 0.693625107 0.733155085 0.308549734 0.972441896
[833] 0.243334341 0.835028139 0.390575896 0.908863697
[837] 0.607566295 0.607495053 0.894327145 0.975288389
[841] 0.676351208 0.091138610 0.777949302 0.517544394
[845] 0.652370169 0.339297696 0.292120431 0.783712422
[849] 0.319965783 0.489277602 0.134141912 0.653294066
[853] 0.783924127 0.921809286 0.258463774 0.513232899
[857] 0.858583322 0.151413594 0.641468017 0.825477348
[861] 0.972295296 0.173125720 0.710021871 0.110715289
[865] 0.416779255 0.284621345 0.341154850 0.168895211
[869] 0.547096898 0.797205828 0.858630747 0.332270424
[873] 0.515725486 0.371684692 0.436701348 0.742428995
[877] 0.011101299 0.046900366 0.371817852 0.658156762
[881] 0.529650157 0.588913933 0.785948208 0.504572585
[885] 0.593546614 0.872144154 0.891242010 0.939548917
[889] 0.848769896 0.811404374 0.824689138 0.916008334
[893] 0.723415147 0.910254459 0.785772749 0.224662109
[897] 0.025505915 0.382444482 0.920264228 0.842048720
[901] 0.879420725 0.715013948 0.945104592 0.377839050
[905] 0.475368502 0.764876201 0.762309468 0.276107021
[909] 0.013929509 0.191360186 0.508207597 0.357133010
[913] 0.064195928 0.694495361 0.911169011 0.449594197
[917] 0.854834523 0.751918294 0.374545260 0.609409488
[921] 0.792774655 0.386679893 0.124152965 0.267549657
[925] 0.521273961 0.590104377 0.886542718 0.328781780
[929] 0.404275393 0.047014354 0.480532115 0.748229080
[933] 0.443648359 0.468462170 0.731393147 0.293246638
[937] 0.163580966 0.503860285 0.192165966 0.321273932
[941] 0.029732935 0.869980632 0.647166965 0.318806882
[945] 0.293482209 0.669097224 0.407680992 0.663763635
[949] 0.049678547 0.495533216 0.785123125 0.906233663
[953] 0.020996784 0.162863294 0.654907126 0.887484326
[957] 0.925433173 0.448821391 0.039802389 0.661046990
[961] 0.174042276 0.026689433 0.626593738 0.031572743
[965] 0.114810244 0.951679254 0.955425197 0.609623392
[969] 0.104700660 0.692146658 0.891687072 0.737418877
[973] 0.331607591 0.622847309 0.765353283 0.077647318
[977] 0.650668845 0.395230689 0.781125475 0.626846384
[981] 0.015295418 0.916748053 0.133362752 0.079918742
[985] 0.219676089 0.007125481 0.821645687 0.113951277
[989] 0.312969944 0.090880581 0.972712883 0.852674136
[993] 0.498993299 0.274403698 0.291713902 0.053610240
[997] 0.970454900 0.577010068 0.498106406 0.682937474
> mean(u3)
[1] 0.4906725
> var(u3)
[1] 0.08887691
> sd=sqrt(var(u3));sd
[1] 0.2981223
> qqnorm(u3)
> ########### part C
if(u3>0)
{
(u3>2.5)
else
(u3<97.5)
}
if(u3>0)
{
(u3>0.5)
else
(u3<99.5)
}


Related Solutions

Use R to complete the following questions. You should include your R code, output and plots...
Use R to complete the following questions. You should include your R code, output and plots in your answer. 1. Two methods of generating a standard normal random variable are: a. Take the sum of 5 uniform (0,1) random numbers and scale to have mean 0 and standard deviation 1. (Use the properties of the uniform distribution to determine the required transformation). b. Generate a standard uniform and then apply inverse cdf function to obtain a normal random variate (Hint:...
Use R to complete the following questions. You should include your R code, output and plots...
Use R to complete the following questions. You should include your R code, output and plots in your answer. 1. Two methods of generating a standard normal random variable are: a. Take the sum of 5 uniform (0,1) random numbers and scale to have mean 0 and standard deviation 1. (Use the properties of the uniform distribution to determine the required transformation). b. Generate a standard uniform and then apply inverse cdf function to obtain a normal random variate (Hint:...
please use linux or unix to complete, and include pictures of the output. Modify the code...
please use linux or unix to complete, and include pictures of the output. Modify the code below to implement the program that will sum up 1000 numbers using 5 threads. 1st thread will sum up numbers from 1-200 2nd thread will sum up numbers from 201 - 400 ... 5th thread will sum up numbers from 801 - 1000 Make main thread wait for other threads to finish execution and sum up all the results. Display the total to the...
You have to include the appropriate output in your report. Your analysis output should be properly...
You have to include the appropriate output in your report. Your analysis output should be properly shaped such as changing the decimal points, copy, and pasted on to your report paper. when you label your output, specify what program did you use to bring the regression output. Ex: Excel Regression Analysis. Submit in one file using docs or PDF format. (1-2 page including regression output) Recognizing appropriate tools & performing all analysis that needs to be done Able to organize...
The following should be performed using R and the R code included in your submission. To...
The following should be performed using R and the R code included in your submission. To obtain first prize in a lottery, you need to correctly choose n different numbers from N and 1 number from 20, known as the supplementary. That is we first draw n numbers from 1:N without replacement and then 1 number from 1:20 in another draw. Suppose n=7 and N=35. Let X be the number of drawn numbers that match your selection, where the supplementary...
Using the R package to answer the following two questions. You MUST submit your R code...
Using the R package to answer the following two questions. You MUST submit your R code for analysis. 2. Below are heights for a simple random sample of n = 15 young trees (in cm). (50 pts) 27, 33, 33, 34, 36, 37, 39, 40, 40, 41, 41, 42, 44, 46, 47. (a) Test the hypothesis that the mean tree height is equal to 38 cm. (b) Calculate the 95% confidence interval for the population mean of young trees. (c)...
Answer the following questions using R (include both the input and output for each question). I)...
Answer the following questions using R (include both the input and output for each question). I) A random variable P has a Poisson distribution with a mean of 10. Solve for the probability that random variable P is greater than 8. II) What is the probability that in 30 tosses of a fair coin, the head comes up 10 or 15 times? III) What is the probability that a normal random variable is less than 40, assuming that the variable...
Answer the following questions using R (include both the input and output for each question). I)...
Answer the following questions using R (include both the input and output for each question). I) A random variable P has a Poisson distribution with a mean of 10. Solve for the probability that random variable P is greater than 8. II) What is the probability that in 30 tosses of a fair coin, the head comes up 10 or 15 times? III) What is the probability that a normal random variable is less than 40, assuming that it has...
Use Minitab and produce the appropriate output to answer the following questions. Attach or include the...
Use Minitab and produce the appropriate output to answer the following questions. Attach or include the relevant Minitab output. Construct a scatter plot. Recalling what scatter plots are used for, write a couple of sentences addressing what you observed from the plot. Be sure to relate your observations to the purpose of using scatter plots in regression. (4 points) Can we conclude that median family income helps in predicting median home price? Follow the 7 steps for hypothesis testing. (10...
1. Use R Studio: Include R Code A survey is taken of 250 students, and a...
1. Use R Studio: Include R Code A survey is taken of 250 students, and a phat of 0.48 is found. The same survey is repeated with 1000 students, and the same phat value is found. Compare the two 95% confidence intervals. What is the relationship between them? Is the margin of error for the second one four times smaller? If not, how much smaller is it?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT