In: Statistics and Probability
(a) Generate 200 replicas of uniform [-3.14, 3.14] and 200
normal with
mean 0 and standard deviation 1/8. Set data
x=uniform
e=normal
y=sin(x)+e
Fit the data with various types of smoothing techniques.
(b) The same as (a) except changing the standard deviation from 1/8
to 1/2.
Answer:
Here we used R studio to find replicas ( samples).
R Code:
##Generating 200 replicas of
uniform [-3.14, 3.14]
x = runif(200,-3.14,3.14)
x
#200 normal with mean 0 and standard deviation
1/8.
e = rnorm(200,0,1/8)
e
y = sin(x)+e
y
# Same process with standard deviation of normal is 1/2
##Generating 200 replicas of
uniform [-3.14, 3.14]
x = runif(200,-3.14,3.14)
x
#200 normal with mean 0 and standard deviation
1/2.
e = rnorm(200,0,1/2)
e
y = sin(x)+e
y
Output:
> ##Generating 200 replicas
of uniform [-3.14, 3.14]
> x = runif(200,-3.14,3.14)
> x
[1] 0.88672255 -1.07707247 0.85213919 2.69110031 0.47252104
-0.83722540 -0.39810666
[8] 2.23518977 0.80381220 1.84491104 1.41403515 0.53408085
-2.93419405 -1.04879341
[15] 3.11938063 0.30315676 0.47623086 -0.27434050 -2.53348661
1.91879230 -3.13418911
[22] -0.20884738 -2.05192172 -1.51208229 2.63309147 -1.68348221
-2.80988758 -1.22841432
[29] -3.06636188 -1.25155565 2.37122718 1.03795041 -0.29035684
-2.80513576 0.82209476
[36] -0.36307702 -1.46106406 3.03810335 -2.54262032 1.79588610
-2.38732830 2.39403313
[43] -2.31670414 -0.62587814 -2.59606399 -0.78625726 1.16045619
1.47437240 1.70155178
[50] 0.50230800 0.06970162 2.21673768 0.81527686 0.49615710
1.50876554 -0.70869949
[57] 3.09939639 -0.63999806 2.98300649 2.03774822 0.47726154
-2.28456611 2.76152940
[64] -2.03293191 2.00774882 -3.06389659 0.87959137 -1.46305994
0.43644588 2.92209990
[71] -1.89390391 1.21111984 2.11020632 2.53651924 2.91725180
0.99030532 0.30717185
[78] 2.41796447 -0.32421508 1.52816833 -0.53802761 1.13514431
2.67514457 0.83899563
[85] 0.99846087 -0.13447592 2.00225449 2.91358379 2.66079130
-2.10766266 -0.93262201
[92] 0.73551051 0.50341548 2.77453669 -1.82079805 -2.89615361
0.72762169 0.09181122
[99] 2.63742402 -0.27984743 2.17933140 2.32761734 1.14928844
1.76746453 -1.56168767
[106] -2.84825251 0.39725942 -1.29532792 -0.93593724 -2.64274376
2.04289834 -1.48073678
[113] -1.48304536 -2.57240722 -0.24589574 1.20309758 2.19147145
-1.59439895 0.94778447
[120] 1.13162656 -2.48352302 -2.43672981 -1.78568803 -2.32286913
1.04457521 -0.07677495
[127] -0.92125251 2.80722756 -2.43696130 0.40110220 2.18748471
0.07390231 1.04591243
[134] -2.97351900 -2.47142863 1.22737484 -1.42339551 1.53840861
1.54108280 -2.09291913
[141] 3.01348516 0.59508469 1.18201493 -2.06073081 -2.87822982
-1.94774268 1.64172911
[148] 0.37349253 0.03463022 2.96921725 -2.63382687 0.35949448
2.48692503 -2.46240612
[155] -0.31851383 -1.20066607 -1.67749709 2.06025774 -2.43112320
2.41153411 1.41689457
[162] 2.63969391 -2.36782797 2.83318158 1.06573538 -2.60559213
0.50966472 -1.80541550
[169] -1.61886245 0.22791699 -2.02806033 0.44213224 -2.16399439
-0.16064665 1.42811092
[176] 2.17478841 2.87986007 -0.25853703 -0.85894427 2.74041199
2.41636871 1.07157724
[183] 2.17953037 2.25860623 -0.11589442 -1.14885442 2.62004201
0.02949439 -3.05162770
[190] 0.60020046 -0.31871118 0.24617648 -2.55018340 1.57595840
-2.65770045 2.69431257
[197] 1.94943173 1.64112718 0.96213597 2.76393576
> #200 normal with mean 0 and standard deviation 1/8.
> e = rnorm(200,0,1/8)
> e
[1] 0.0861156855 0.2942145627 -0.1268872089 0.0363721900
0.1956657599 -0.1058897960
[7] 0.1659575198 0.0596307914 0.0231563671 0.0316618610
0.3240284188 0.1342933741
[13] -0.1996127365 -0.0109485745 0.0450959488 -0.1099949977
-0.4154168706 -0.0584394316
[19] 0.0539425332 -0.0754986817 0.0843058366 0.0794900670
-0.0766212984 0.0518614182
[25] 0.1096679216 0.0026446978 0.2262979118 -0.0565119630
-0.0156404982 0.0958500521
[31] -0.0114400326 -0.2342882262 -0.0830202522 0.0254266022
-0.3243054242 -0.0117167414
[37] -0.0534149897 0.0553724096 -0.1484759907 0.0783031842
0.0452058252 -0.0591200724
[43] 0.1181117128 0.1133002809 0.0589717131 0.0486874913
0.0652425334 0.1130566050
[49] 0.2120988658 -0.1105421794 0.1070612127 0.0218678063
-0.0498131203 0.0344003203
[55] -0.1585898499 -0.0012601661 0.0816752156 0.0123224974
0.1128271177 -0.0649871870
[61] -0.1616863725 -0.0058622138 -0.0793745332 -0.0272127840
-0.1968552079 -0.0346878940
[67] 0.0687865259 -0.0763683271 -0.2668581815 0.0874096797
0.1346494959 0.1084897697
[73] -0.0988424223 -0.0136662717 -0.1162937576 -0.0458901581
-0.1116142886 -0.0447216010
[79] -0.0334327655 -0.0389899373 -0.0373374665 -0.0741919518
0.1033379799 -0.2701758020
[85] -0.1151303116 0.0646453837 0.0296079235 -0.0883596531
0.1023673324 0.0137538837
[91] -0.0859325642 0.1975753177 0.0430192646 0.2138096580
-0.0138402461 0.1939557667
[97] 0.0685702043 0.1696230538 -0.0512644377 0.0132741546
0.0360225015 -0.0371495640
[103] -0.0203017876 -0.2087054070 -0.0678481578 0.0086052526
-0.0571043857 -0.1358147838
[109] -0.0851802263 -0.0262948613 0.0613884245 0.1022583191
0.0123745350 0.3166667626
[115] 0.1059821060 -0.0253398254 0.0395677544 0.1024264722
0.0534531556 0.1143621584
[121] 0.1187028009 0.0029490591 0.2182976094 0.0860511103
0.0419051979 -0.0233389357
[127] 0.0033363061 -0.0814538564 -0.0650020922 0.0655287674
-0.1210636707 0.1139916425
[133] 0.0116040747 -0.0666163622 -0.2083631895 -0.0717931863
0.0931266410 0.0906987035
[139] -0.0982876290 -0.1916114871 0.0973641407 -0.1015257194
-0.1096555260 -0.0097588839
[145] 0.1508314674 -0.0018628872 -0.1219282314 0.0607896365
0.0472661333 -0.0180259849
[151] 0.1600145234 0.3276466390 0.0949507194 0.1361016449
-0.0377770797 0.3268282168
[157] 0.0899830738 -0.1137322558 0.1361918986 0.0453993788
0.0493793110 -0.1624274368
[163] 0.2244874268 -0.0745852110 0.1696843294 -0.1138282788
0.0300406983 0.0587697297
[169] -0.0203930393 -0.0259663171 -0.0858856393 0.0291281936
-0.0092721764 -0.0920809270
[175] 0.1258785469 -0.0748271608 -0.0824016423 -0.0644394223
-0.0226504863 0.0017391437
[181] 0.0178913612 0.0454466017 -0.0248914309 -0.2312559117
-0.0199185407 0.0704517260
[187] 0.0683537263 -0.0053611701 -0.1917162637 0.1172988899
0.1639481410 -0.2864139118
[193] 0.0232405467 -0.0873333178 -0.0032415956 0.1061537574
-0.0472032094 0.0467879734
[199] 0.0699193863 -0.0002283374
> y = sin(x)+e
> y
[1] 0.86112040 -0.58635964 0.62580331 0.47178100 0.65079829
-0.84867811 -0.22171624
[8] 0.84692171 0.74316323 0.99432708 1.31176653 0.64334348
-0.40552768 -0.87777080
[15] 0.06730614 0.18853950 0.04301582 -0.32935159 -0.51737152
0.86455932 0.07690236
[22] -0.12784240 -0.96309598 -0.94641541 0.59653654 -0.99101296
-0.09935771 -0.99846958
[29] -0.09080033 -0.85362395 0.68495754 0.62707665 -0.36931440
-0.30471813 0.40826789
[36] -0.36686907 -1.04740044 0.15867708 -0.71227000 1.05307726
-0.63954691 0.62073099
[43] -0.61636042 -0.47250890 -0.45989838 -0.65902650 0.98222772
1.10841142 1.20356254
[50] 0.37090754 0.17670641 0.82040128 0.67810234 0.51044987
0.83948686 -0.65210713
[57] 0.12385896 -0.58487139 0.27074939 0.82795740 0.29766207
-0.76176144 0.29160468
[64] -0.92231515 0.70919031 -0.11230581 0.83926498 -1.07057037
0.15586300 0.30514425
[71] -0.81360380 1.04450051 0.75916945 0.55515618 0.10617002
0.79030331 0.19074979
[78] 0.61738642 -0.35199762 0.96010163 -0.54978072 0.83240313
0.55305464 0.47379656
[85] 0.72550808 -0.06942560 0.93796484 0.13767872 0.56485716
-0.84556171 -0.88911727
[92] 0.86854109 0.52543937 0.57267872 -0.98275224 -0.04902647
0.73366570 0.26130534
[99] 0.43181525 -0.26293486 0.85650885 0.68987285 0.89217126
0.77201765 -1.06780667
[106] -0.28054604 0.32978825 -1.09811268 -0.89033550 -0.50470989
0.95200277 -0.89368906
[113] -0.98377782 -0.22227932 -0.13744312 0.90781722 0.85305375
-0.89729500 0.86557793
[120] 1.01946714 -0.49288794 -0.64498030 -0.75870188 -0.64422328
0.90661646 -0.10003848
[127] -0.79302349 0.24671564 -0.71275511 0.45596207 0.69473449
0.18782670 0.87698620
[134] -0.23389982 -0.82947773 0.86981494 -0.89602951 1.09017427
0.90127096 -1.05837393
[141] 0.22512152 0.45905317 0.81571615 -0.89212258 -0.10949744
-0.93165585 0.87555709
[148] 0.42565903 0.08188943 0.15349704 -0.32621161 0.67944771
0.70384634 -0.49205864
[155] -0.35093257 -0.60545202 -0.90432980 0.76885395 -0.51599781
0.71231264 1.03755979
[162] 0.31866354 -0.47434558 0.22895986 1.04482932 -0.62452978
0.51792531 -0.91383321
[169] -1.01923809 0.19998255 -0.98314942 0.45699584 -0.83842933
-0.25203749 1.11571624
[176] 0.74824778 0.17635288 -0.32010590 -0.77980383 0.39224468
0.68119441 0.92340329
[183] 0.79548115 0.54138233 -0.13555369 -0.84184366 0.56657894
0.02412894 -0.28155991
[190] 0.68210680 -0.14939477 -0.04271641 -0.53429093 0.91265336
-0.46846963 0.53866854
[197] 0.88196672 1.04431578 0.89033410 0.36851515
> ##Generating 200 replicas of uniform [-3.14, 3.14]
> x = runif(200,-3.14,3.14)
> x
[1] 0.453157824 2.810530391 -0.641779173 3.021216234 -1.350107502
1.902004868
[7] -2.954627891 0.755767999 0.304810150 2.176621741 -2.944411173
-2.685009578
[13] -0.562354028 -2.832335182 2.190429784 -0.103842224 0.373360276
2.710470842
[19] -2.593633661 -2.124397254 0.896530925 0.190293222 0.700108561
-0.383671936
[25] -0.962653682 -0.188151304 -1.665128707 0.109609622
-1.028910026 -0.576594635
[31] 0.399389632 -0.900741976 2.789098690 0.495912964 2.705191194
1.275270609
[37] 0.048328789 -0.356113646 -1.727980386 -0.192761210
-1.626338126 2.646496059
[43] -0.849129130 0.202065103 1.821774801 -2.950174803 -0.527248079
0.054716804
[49] 0.802098218 0.812687761 1.633013013 0.601029384 -1.793877917
-2.965426019
[55] 1.207001050 -2.441297993 -1.395034101 -1.679833922 0.197331837
-2.287668567
[61] -2.218277051 0.786671307 0.800469917 -0.740174871 -3.029150206
1.108934235
[67] -2.073889204 1.453483850 -1.269601381 2.270619453 1.858919462
2.502681796
[73] -1.344075768 1.016312149 1.163424911 2.250836551 -0.410258963
-0.381631265
[79] 1.363176680 1.739308789 -2.122580505 0.529888140 1.061127026
0.798219334
[85] -1.032046457 -2.519164230 -1.632165989 -0.434497309
1.828599163 1.749234906
[91] 0.307602689 -2.941659810 -1.651204358 1.110980121 -0.920058900
0.001869811
[97] 0.568162936 2.342223103 2.626701385 0.242799598 0.486243306
-2.038927888
[103] 3.129219645 1.843581012 -3.051139587 -0.773863589 1.544189986
-0.134390595
[109] 3.054578212 -0.963285055 -2.722236347 2.710566569
-1.022637220 0.342280176
[115] 2.356325182 0.677560120 -1.699332612 -1.136695358 2.160854203
0.390081417
[121] 0.803373686 -1.807203734 2.949643328 3.068466796 0.999216733
-2.899038623
[127] 1.005911324 1.832243813 -0.896036461 0.568607258 0.945561610
2.684523982
[133] 1.897885593 -2.518558447 0.962312591 -1.405214793 0.840753449
-0.763410184
[139] 1.683759624 1.155259232 2.998993708 0.498290169 1.373514707
-2.645657495
[145] -0.365067843 -0.778748791 -1.860994972 2.117530249
-2.507899195 -0.524372762
[151] 2.668020667 -2.086243713 -1.207170079 -1.915967672
-2.085209269 -2.967348813
[157] 0.613160828 0.886075238 2.308455434 -1.084663094 -0.947833851
2.752533655
[163] -2.649443731 0.932088787 0.037821273 -0.156426943
-1.078315383 0.109754220
[169] -2.471022298 -1.177181218 -0.092641047 -1.552877099
3.126635359 2.110444181
[175] -0.843106228 -2.246123473 -1.666026989 -2.662856993
0.447752321 -2.819945617
[181] -2.721504679 0.080674246 -1.972700080 -2.093965677
2.235789122 -2.318176016
[187] -1.759795121 -0.141634560 -0.564496828 0.079903502
2.123395512 0.299134066
[193] 0.350079080 3.085858811 2.404572819 -1.984172387 -2.779565247
1.659226513
[199] -3.124110246 -0.404490095
> #200 normal with mean 0 and standard deviation 1/2.
> e = rnorm(200,0,1/2)
> e
[1] -0.097468821 0.122671049 0.601145925 0.412197250 -0.315100356
-0.187452616
[7] -0.433917110 -0.564355593 -0.799256926 0.501257605 0.089340576
0.732439374
[13] -0.361611519 0.240652726 0.529152504 0.161840924 -0.009865128
-1.602984608
[19] -0.021846145 0.154459634 -0.777364690 0.594949978 0.042979898
0.297709653
[25] -0.016281202 0.010029187 -0.362376124 -0.627035775 0.380419691
-0.302324041
[31] -0.456884518 0.056345450 -1.179862438 -0.784699137 0.613728459
0.381023986
[37] -0.419059462 0.691410700 -0.712894286 0.784712544 -0.589411117
-0.406298171
[43] -0.253381356 -0.167527599 -0.263831806 0.480054385
-0.717846959 0.206251000
[49] -0.507909137 -0.147210804 0.319192623 -0.565341440
-0.017147640 -0.437355878
[55] 0.388849553 0.114535680 0.225678116 -0.088620678 0.293167205
-0.375112248
[61] 0.212066867 -0.469445703 -1.214536902 0.091263995 0.981693001
-0.356446706
[67] -0.566233513 0.148621443 -0.550813805 -0.711662017 0.484635356
-0.017113973
[73] -0.036436541 -0.897463858 0.442338549 0.758919655 0.235551282
0.270089777
[79] -0.214643167 -0.175674346 0.697910583 -0.445993096 0.532514592
0.400404866
[85] -0.184037251 0.136648449 -0.469299696 -0.619849262 0.424633287
-0.401951701
[91] 0.191583074 -0.584122234 -0.077844798 0.960999627 -0.291627934
0.307756632
[97] -0.016622158 -0.149226387 -0.491586612 0.403789902 0.254164841
0.267580932
[103] -0.528904933 0.030315513 -0.734134849 0.434781278
-0.069192801 -0.218967347
[109] -1.085456505 0.639885122 -0.134742548 0.236032170 0.364413209
0.017163828
[115] 0.122133125 0.241342627 -0.159311247 -0.062735136
-0.116446161 -0.502484392
[121] 0.475079498 0.098267060 0.087731213 -0.400396155 -0.386292358
-0.789059363
[127] -0.663331519 0.242735100 -0.301855401 -0.130919431
-0.471740040 -0.209837734
[133] -0.833553927 0.481142121 -0.060241530 0.378246525
-0.348913545 0.170100161
[139] 0.722419500 0.446504978 0.197344676 0.228911306 -0.098937571
0.825259788
[145] -0.018302380 -0.219413967 1.393603368 -0.440235125
-0.238201254 0.154235761
[151] -0.010087324 -0.020799928 -0.429791941 0.297883039
-0.088545914 -1.141175998
[157] 0.342421964 1.180599112 -0.294905857 0.647040520 0.266612848
0.750712293
[163] -0.068092512 -0.214555756 0.084880837 0.331557253 0.306051701
-0.316901475
[169] -0.011315789 -0.044775686 -0.320794892 0.288692077
-1.040709887 -0.075687279
[175] 0.238167571 -0.044296768 0.594698743 0.463858439 0.293826384
0.383752151
[181] -0.872769369 0.394850453 0.431016007 -0.010973828 0.539596928
-0.117429738
[187] 0.035851053 -1.094985552 0.340483312 0.026595451 -0.338752034
0.004530075
[193] 0.271429216 -0.678447171 0.124077824 0.166013380 0.777288549
0.361453476
[199] 0.969817276 0.110959531
> y = sin(x)+e
> y
[1] 0.3403379934 0.4477188404 0.0025243623 0.5322831620
-1.2908472515 0.7581974173
[7] -0.6197945237 0.1214921853 -0.4991448441 1.3232899580
-0.1065656330 0.2915555957
[13] -0.8947907056 -0.0636986916 1.3432438800 0.0581852244
0.3548811332 -1.1850943797
[19] -0.5427922772 -0.6961772060 0.0038010995 0.7840968095
0.6872806131 -0.0766183051
[25] -0.8369918241 -0.1770139599 -1.3579301236 -0.5176455008
-0.4763176499 -0.8474963451
[31] -0.0680284340 -0.7274424637 -0.8346229384 -0.3088643043
1.0364093885 1.3376731491
[37] -0.3707494848 0.3427763446 -1.7005662858 0.5931428518
-1.5878690681 0.0688184775
[43] -1.0040867173 0.0331652457 0.7048380735 0.2898033452
-1.2210040126 0.2609405043
[49] 0.2109072164 0.5789269592 1.3172577897 0.0001503211
-0.9923679625 -0.6126127130
[55] 1.3234026618 -0.5299073487 -0.7589154270 -1.0826819671
0.4892208538 -1.1289766931
[61] -0.5855390355 0.2385607539 -0.4968534957 -0.5831530436
0.8694873446 0.5387775666
[67] -1.4423290760 1.1417482221 -1.5057964820 0.0532941035
1.4434142374 0.5792075175
[73] -1.0108453381 -0.0472917218 1.3605039806 1.5364670810
-0.1632955336 -0.1023450963
[79] 0.7638811846 0.8101609960 -0.1536800148 0.0594437278
1.4054204919 1.1165192187
[85] -1.0423879991 -0.4463614383 -1.4674171694 -1.0408037347
1.3915857804 0.5821703325
[91] 0.4943577965 -0.7827257464 -1.0746138132 1.8571337046
-1.0872652353 0.3096264420
[97] 0.5214623546 0.5676903229 0.0008536059 0.6442109489
0.7214727614 -0.6248319892
[103] -0.5165322400 0.9933399104 -0.8244646217 -0.2641224700
0.9304532712 -0.3529537721
[109] -0.9985518267 -0.1811860681 -0.5419151675 0.6538354277
-0.4890720792 0.3527996971
[115] 0.8291474870 0.8682365972 -1.1510618261 -0.9699836727
0.7144623167 -0.1222206752
[121] 1.1947819714 -0.8739186129 0.2785039936 -0.3273354518
0.4547551678 -1.0292420386
[127] 0.1813186466 1.2087519450 -1.0827123890 0.4075395431
0.3390857245 0.2314818451
[133] 0.1134276106 -0.1023598363 0.7602741639 -0.6080761449
0.3962322622 -0.5212890975
[139] 1.7160459286 1.3614046154 0.3394608347 0.7068356263
0.8816654433 0.3494054347
[145] -0.3753150471 -0.9218033343 0.4354163142 0.4139919838
-0.8303264023 -0.3464343811
[151] 0.4459807354 -0.8908722095 -1.3644051801 -0.6431344516
-0.9591276332 -1.3145394756
[157] 0.9178773250 1.9551945889 0.4451391127 -0.2371055388
-0.5455407367 1.1300301987
[163] -0.5406133766 0.5883111835 0.1226930941 0.1757674755
-0.5751108470 -0.2073674719
[169] -0.6327487318 -0.9683042824 -0.4133034826 -0.7111473781
-1.0257531502 0.7822023998
[175] -0.5085452445 -0.8247992447 -0.4007702432 0.0032010958
0.7267669053 0.0676225927
[181] -1.2806101492 0.4754372183 -0.4893019615 -0.8772138649
1.3265181594 -0.8509021981
[187] -0.9463417763 -1.2361470476 -0.1945074633 0.1064139547
0.5124110491 0.2992229117
[193] 0.6144013073 -0.6227421780 0.7961619867 -0.7497564896
0.4231175980 1.3575460743
[199] 0.9523357598 -0.2825905237