This is project report for coursera statistical inferense part1 In this project I will investigate the exponential distribution in R and compare it with the Central Limit Theorem. The exponential distribution can be simulated in R with rexp(n, lambda) where lambda is the rate parameter. The mean of exponential distribution is 1/lambda and the standard deviation is also 1/lambda. Set lambda = 0.2 for all of the simulations. You will investigate the distribution of averages of 40 exponentials. Note that you will need to do a thousand simulations
## Show the sample mean and compare it to the theoretical mean of the distribution.
set.seed(0)
nosim <- 1000
n <- 40
lambda <- 0.2
x1 <-replicate(nosim,mean(rexp(n,lambda)))
simulation <- matrix(rexp(nosim*n, rate=lambda), nosim,n)
simulation_mean <- rowMeans(simulation)
hist(simulation_mean, col = 'blue')
# question 1 ## For this part of we will compare the sample mean with theorical data mean ### we already have the mean of the simulation, now we can use that data to calculate the actual mean of the data
simulation_mean <- rowMeans(simulation)
theorical_mean <- 1/lambda
simulation_mean
## [1] 5.130639 5.282780 4.763182 3.215518 5.341980 4.218632 5.129262
## [8] 5.794198 3.786431 4.506915 6.013493 4.035450 4.467237 5.405823
## [15] 4.761404 5.793536 5.486207 4.455984 4.918931 6.110330 4.844154
## [22] 5.494356 4.857612 6.067014 5.529543 4.651474 4.820613 4.513367
## [29] 5.396918 6.293674 5.435907 5.696274 4.768276 5.421622 4.210054
## [36] 4.331651 4.347907 3.315820 4.987566 5.288332 4.837880 5.311534
## [43] 6.810365 3.981852 3.707201 4.918630 6.082756 6.260353 5.676823
## [50] 4.899129 4.170870 6.830760 6.246163 5.565135 4.411540 3.972370
## [57] 4.222651 5.406059 5.418017 4.916168 4.772242 4.693734 3.939816
## [64] 5.777762 5.992830 4.802160 5.331397 5.117886 5.566677 4.737094
## [71] 5.690113 5.520489 5.019091 5.559496 7.278232 5.366320 6.932426
## [78] 5.473887 5.998909 6.106774 5.114714 4.306664 5.783691 4.692518
## [85] 4.846582 5.640030 7.183695 4.298571 4.272142 4.917307 6.069336
## [92] 5.935462 4.923416 4.200699 3.834672 4.586607 5.015023 5.426025
## [99] 4.715686 5.032177 5.744763 5.628565 5.480477 4.849867 6.258298
## [106] 5.114693 5.053102 5.257629 5.329320 4.352867 4.604615 5.742387
## [113] 4.537134 5.071888 5.612755 4.844040 4.756885 4.634279 5.185943
## [120] 5.505349 5.077404 5.707778 4.957156 3.949363 5.279093 6.136387
## [127] 4.104834 4.509669 4.470533 4.522098 5.051464 5.257410 5.826372
## [134] 6.565763 5.311442 4.331258 4.751428 4.907017 4.649100 4.326255
## [141] 4.788066 4.339089 6.281011 4.338475 5.021845 5.009748 5.574455
## [148] 4.315298 6.169545 4.413364 4.611102 5.205449 5.872892 4.468119
## [155] 4.919242 4.462645 5.040734 5.392309 5.028334 4.395448 5.215483
## [162] 4.410989 5.470676 3.521421 5.209233 4.720204 5.502982 5.894993
## [169] 5.828760 3.772271 5.718656 5.367448 4.620842 5.519275 6.734519
## [176] 5.660148 5.636409 5.064139 5.220556 5.168613 6.983367 3.636415
## [183] 5.542543 4.875249 5.355263 6.337218 5.235607 4.661457 6.574121
## [190] 5.124661 4.504935 4.627564 4.521807 5.993374 5.031830 5.000530
## [197] 4.052150 3.633053 4.529877 4.122110 4.435029 4.095628 3.773808
## [204] 5.567242 5.313330 6.143740 6.133426 5.933658 5.278618 4.802777
## [211] 4.706973 5.102336 4.679426 4.767984 4.752808 2.964585 4.762544
## [218] 4.574759 4.324422 4.546726 4.680197 5.356068 4.489250 5.572497
## [225] 6.090456 5.631248 3.949757 4.384896 5.594412 4.661390 5.316906
## [232] 4.663970 7.090554 4.195710 5.154956 3.697883 4.155061 4.867770
## [239] 4.603012 6.248378 6.167465 6.764853 6.010787 5.946509 4.356820
## [246] 4.363906 5.578327 5.690117 5.398773 5.962984 4.562686 3.616152
## [253] 4.365567 4.166719 4.787684 4.211136 4.535143 5.672611 5.491491
## [260] 4.604671 6.351253 5.825370 3.717034 4.286247 4.420082 6.799376
## [267] 5.743103 5.139864 4.450231 3.378954 3.413257 5.578963 5.410375
## [274] 5.448370 4.836768 5.809214 4.650887 5.236740 4.373446 4.474470
## [281] 4.298590 4.613782 4.758674 5.365607 5.947978 4.651894 4.478839
## [288] 4.529872 5.312789 4.899624 4.841689 3.675560 4.193156 5.206767
## [295] 4.941494 4.141709 5.185215 4.385767 5.200428 5.537631 3.671030
## [302] 7.033246 5.464852 5.270631 6.054001 5.077082 5.062400 5.865127
## [309] 4.902839 5.165768 6.514375 4.113087 4.722064 5.153203 5.030741
## [316] 3.601389 4.921997 5.294478 3.938313 3.974113 6.081494 4.335796
## [323] 4.842548 4.842626 4.863621 5.007175 5.346060 3.829168 5.289855
## [330] 4.771226 6.109006 5.958200 4.117742 5.941048 4.531064 4.614792
## [337] 5.635478 5.417092 5.211784 5.604543 4.186227 3.501654 3.393375
## [344] 5.947788 5.401268 4.071457 4.319927 4.852058 4.773495 4.041462
## [351] 5.433452 5.215157 3.644327 3.339009 3.365607 3.124540 3.994189
## [358] 5.450329 4.774928 6.084013 5.011222 5.643438 5.520953 4.862195
## [365] 5.182415 4.878099 6.056193 5.034549 4.266456 4.152299 5.104358
## [372] 3.522471 4.272348 5.879700 4.275132 5.664090 4.443137 4.623586
## [379] 4.850125 4.563151 4.888066 5.106739 3.505142 2.972013 5.820991
## [386] 4.293585 4.307284 5.770897 3.591264 4.685935 5.099067 5.305080
## [393] 3.945688 3.915457 5.064511 5.966264 4.562071 6.123274 5.374872
## [400] 4.571843 4.704604 4.680340 5.713041 5.100269 5.386879 4.807015
## [407] 5.068381 6.995784 3.345154 4.154874 4.185932 5.609025 4.569986
## [414] 3.307138 5.380649 5.217342 4.726617 4.289739 5.171989 4.559768
## [421] 4.672060 5.207373 4.760909 5.151207 4.778335 5.865993 4.652088
## [428] 4.114907 4.380564 3.771038 6.247128 4.652558 5.137341 4.824552
## [435] 4.250690 6.811423 4.615323 4.562771 5.654863 4.709519 5.294029
## [442] 6.043774 4.716742 3.977798 3.956572 4.686025 3.494705 6.166172
## [449] 4.396396 5.938623 4.931060 4.308828 5.780683 6.392321 5.573655
## [456] 4.185187 4.895788 5.608862 3.863763 4.918016 5.536763 5.439288
## [463] 4.387815 5.385559 5.287579 4.691765 5.140552 6.220602 4.774075
## [470] 6.313470 4.268865 5.352856 4.624925 4.448824 4.103540 5.034070
## [477] 4.766886 5.062809 5.033056 4.063692 5.746235 5.129879 5.344225
## [484] 5.741469 4.529609 5.800678 4.885567 4.493132 5.054104 4.250719
## [491] 3.629792 4.366496 4.316552 5.816217 4.043958 4.655721 4.929141
## [498] 6.308391 4.760599 5.562018 4.093828 5.010822 4.147959 4.639609
## [505] 5.493878 5.732252 3.554537 4.805744 4.264403 4.927261 5.254975
## [512] 4.303267 5.187038 5.144422 5.034500 4.516392 5.196332 4.647774
## [519] 5.637313 4.579799 4.566660 5.924319 5.325271 4.316897 4.740824
## [526] 5.396324 4.117422 2.971589 4.417297 5.094385 5.345302 4.933535
## [533] 4.867229 6.770427 4.747107 5.026242 4.972000 5.113111 4.832767
## [540] 3.730819 5.862803 4.756454 5.617684 3.616300 5.779235 4.480063
## [547] 4.818775 5.441187 6.420491 4.222317 4.993788 4.869463 4.227076
## [554] 3.864908 3.942363 5.161638 4.437252 4.429227 5.600130 5.768152
## [561] 5.407645 5.294636 5.140818 5.573050 6.396082 4.362366 6.231876
## [568] 4.874333 4.817680 4.211767 4.235153 4.441195 4.118942 7.549527
## [575] 4.160387 5.750427 3.812272 4.709360 4.492643 4.327803 5.087801
## [582] 4.976588 5.461014 4.782354 6.561502 4.549981 4.753355 5.004109
## [589] 5.474949 4.830830 4.233763 5.046352 3.723519 4.080894 5.146137
## [596] 4.509737 6.252736 5.210683 3.843156 3.882148 4.355430 4.605066
## [603] 4.631784 4.276240 4.419017 5.477726 5.701142 4.083018 4.674303
## [610] 4.872461 5.511445 5.339210 4.511983 4.164632 5.896106 3.971439
## [617] 5.409566 5.741183 4.791433 4.886999 6.019486 4.265289 3.825419
## [624] 5.696701 5.201401 5.002437 4.387191 6.260930 5.629359 5.124992
## [631] 6.297615 5.133475 4.701876 4.437933 4.205394 5.678426 6.104360
## [638] 5.257035 4.925585 6.200807 4.052135 4.776632 7.455016 4.994764
## [645] 5.418265 4.381134 6.167195 5.502254 6.623400 4.690607 5.435403
## [652] 5.502058 4.440336 5.689765 5.920199 4.973855 4.994537 6.451741
## [659] 4.651152 5.513951 6.892052 4.949364 5.177579 6.372887 4.668577
## [666] 4.781592 5.428084 4.508743 5.746678 4.946529 5.277181 4.219107
## [673] 4.599470 5.300607 5.379690 4.167547 4.075090 5.376039 3.566425
## [680] 5.873268 4.643745 5.871192 6.244780 4.440586 4.072238 6.211329
## [687] 5.110691 4.851013 4.174273 6.144587 4.178742 5.453661 4.253755
## [694] 4.141693 3.989367 4.379994 3.370778 4.461982 5.702264 4.211154
## [701] 5.833355 5.311654 4.035878 4.606525 4.564013 5.861255 5.248466
## [708] 4.264526 5.749676 4.205477 5.261173 4.878020 5.833274 5.635356
## [715] 4.151264 4.364760 6.485003 5.031015 4.162414 4.920702 4.601788
## [722] 5.706603 4.293327 5.001154 5.687209 5.103636 3.923065 4.534781
## [729] 4.765682 5.498750 4.548273 3.238172 5.611897 5.973132 4.992404
## [736] 4.474543 4.458655 5.590324 6.568851 5.526010 5.806665 3.466383
## [743] 4.514693 5.884414 6.992718 5.199308 4.830857 5.721704 4.669593
## [750] 4.004694 4.707654 5.112750 4.875499 6.018100 5.464757 5.660713
## [757] 5.851684 4.706219 4.161978 5.307662 4.127923 5.349744 4.416593
## [764] 5.028476 4.992739 5.685586 6.186770 4.076392 4.741908 4.853942
## [771] 4.989163 5.956650 4.435827 4.045723 4.513642 4.980636 5.959571
## [778] 4.953903 5.741542 6.133750 4.362937 5.888884 4.007786 6.047875
## [785] 4.406616 5.036768 4.834858 6.651872 5.073324 4.416245 3.741591
## [792] 5.303122 5.238069 5.922994 4.511851 5.189723 5.620955 4.461647
## [799] 5.763828 4.712383 2.988622 4.054259 5.561513 5.624515 6.137796
## [806] 5.428059 5.611834 4.541090 4.761739 3.746914 5.996235 5.764074
## [813] 4.535668 5.021398 6.626056 5.052332 5.388949 4.901326 5.565579
## [820] 4.027637 4.749035 5.997344 4.737554 6.629976 7.361523 5.060400
## [827] 6.038683 6.310422 3.795093 5.404723 6.277708 5.454667 5.170555
## [834] 5.086997 6.854060 3.933184 3.996909 5.171935 5.532311 6.161879
## [841] 7.028253 6.038065 4.169960 4.664354 4.633681 6.075114 4.590895
## [848] 4.382434 4.736059 5.493529 5.200474 5.572343 4.826810 4.835591
## [855] 5.294006 4.185246 5.900712 5.848443 3.828424 6.645729 6.292790
## [862] 4.114881 5.155791 6.093011 4.503956 5.091315 4.285789 5.088867
## [869] 4.006758 4.075627 4.526559 5.241633 4.093109 4.686311 6.337224
## [876] 5.369617 5.134266 4.236791 3.974264 4.987847 5.523136 4.138988
## [883] 4.235100 4.826219 5.677585 4.741217 4.420199 5.472501 5.518104
## [890] 4.327130 5.354423 6.661542 4.672289 5.610292 6.173759 3.876114
## [897] 6.242608 4.393599 4.182925 5.257654 6.191687 5.565696 5.177844
## [904] 5.500593 6.807803 3.937743 4.544794 4.514668 5.690738 4.559362
## [911] 4.718558 4.664409 6.343206 4.315610 5.246340 5.430264 5.892858
## [918] 7.049399 4.878420 5.211838 6.724657 6.519558 7.220511 5.829173
## [925] 3.988689 3.516956 4.111492 5.194514 4.248613 4.104396 4.832519
## [932] 6.574874 6.314987 4.722049 5.875007 4.133222 6.045780 4.445311
## [939] 7.044860 5.413317 4.502191 4.617938 4.951990 4.917264 4.371299
## [946] 4.097469 4.940093 3.914212 4.828453 4.596823 4.660572 3.187567
## [953] 5.333720 5.210073 6.253647 3.328380 4.763818 5.337306 5.108377
## [960] 5.247110 5.349338 4.182400 4.894282 4.729826 7.175404 4.368815
## [967] 5.293266 6.237732 4.589756 5.237240 6.380349 3.917073 4.144337
## [974] 4.506208 5.648022 3.995954 4.873641 4.379390 5.648918 5.085500
## [981] 4.565294 5.881707 4.505365 4.206449 4.155409 4.871961 3.971732
## [988] 5.027465 4.516122 5.796562 4.757624 5.359243 6.359115 4.991228
## [995] 5.393407 3.790187 4.719297 3.816751 5.674932 4.306422
theorical_mean
## [1] 5
simulation_var <- var(simulation_mean)
simulation_var
## [1] 0.6326191
theorical_var <- (1/lambda)^2/n
theorical_var
## [1] 0.625
sample_mean <- mean(simulation_mean)
sample_mean
## [1] 5.013886
The graph below show the that the aproximity of both, theorical and sample quintiles.
## Show that the distribution is approximately normal.