In: Statistics and Probability
Q3. Please use R software to solve this.
A confidence interval having 100(1 − α)% confidence for normally distributed data is formed by y ± zα/2σ / √n. (That's actually y-bar in the expression, not y). Generate 500 records of 10 columns of normal data with mean 50 and standard deviation 10. Generate two more columns using the confidence bounds expression to give a lower and upper bound consistent with a 95% confidence interval, using each record as a sample of 10 values. Using a logical expression in your software establish a result column that will be true, have value 1, if the theoretical mean of 50 is within the interval. Show the calculated proportion of intervals formed for which the interval covered the mean and comment on its closeness to the 95% confidence.
y=matrix(0,50,12)
y=matrix(rnorm(500,50,10),50,10)
Low_CI=rowMeans(y)+(qnorm(0.025)*(10/sqrt(10))) ### Lower
confidence
Up_CI=rowMeans(y)+(qnorm(0.975)*(10/sqrt(10))) ### upper
confidence
cbind(y,Low_CI,Up_CI)
i=1:length(Low_CI)
mean_cp=mean(sapply(i,function(i)
ifelse(Low_CI[i]<50&&Up_CI[i]>50,1,0)))
### Proportion
I got following result
[1,] 59.57852 46.39382 42.07816 46.37343 56.18238 50.45146 68.39339 44.10094 42.77697 53.68895 [2,] 44.66465 48.19583 43.13685 36.26322 42.92557 45.83168 53.20251 45.25868 49.68268 67.00801 [3,] 63.25422 44.88777 65.85238 55.00180 27.74367 69.20008 57.14078 45.36467 53.77645 39.60957 [4,] 62.19498 49.98214 59.85819 43.10803 66.92258 39.13111 43.96098 46.45145 58.34229 83.25300 [5,] 47.48607 45.64656 60.92279 53.62927 36.73358 54.61039 57.28025 63.97058 62.13236 56.32645 [6,] 39.05279 31.79012 40.32564 51.75676 53.83334 63.68568 56.13379 38.72944 27.60931 48.19458 [7,] 38.29589 58.29345 41.70752 64.43295 58.63162 55.19311 60.72294 50.25934 49.60575 48.09584 [8,] 45.37755 58.42054 54.31469 45.89614 47.68024 48.44631 47.11462 49.50450 55.17763 56.46433 [9,] 41.95536 51.92351 49.29931 46.00436 40.64226 61.41830 57.00200 54.01011 54.40354 40.95588 [10,] 46.31983 49.61951 25.65964 38.02163 53.15711 53.60026 45.50512 43.14841 32.67256 61.13319 [11,] 46.98385 34.94077 43.10489 29.52993 43.59337 57.25602 45.67121 57.51085 37.54471 62.96642 [12,] 54.61521 50.77930 38.95281 61.34773 47.63638 65.28508 64.51387 51.26551 59.29288 49.93180 [13,] 47.54114 60.73269 46.05305 47.78417 49.23113 49.42975 50.38007 31.48199 50.11335 52.64546 [14,] 56.11698 39.00805 48.64264 30.92197 71.25639 48.26282 38.96378 75.65075 48.45869 20.97487 [15,] 62.76552 43.16175 48.02297 37.86411 56.04495 57.84021 51.07407 49.07603 45.03401 26.35665 [16,] 57.00678 61.34474 59.11310 42.45724 40.51970 37.89295 50.12876 34.77763 55.17594 34.38066 [17,] 50.82692 58.76585 46.58643 63.51954 49.68163 38.83141 61.98909 34.58990 38.69620 55.79845 [18,] 60.81474 61.24496 41.71252 65.04561 47.41562 55.27952 41.43843 59.37685 62.56891 52.15737 [19,] 45.48505 49.61173 44.90705 30.20035 51.78590 40.08831 51.02583 63.57944 48.35630 43.21243 [20,] 63.11833 52.90772 56.49161 57.41834 64.68666 52.44256 42.68577 47.64202 63.80627 42.66060 [21,] 54.40194 34.69718 53.52251 69.84264 49.71645 38.15450 58.28123 41.46476 44.30760 69.34549 [22,] 47.05414 50.19134 65.17408 57.89013 52.29702 41.07829 53.22337 47.67837 51.05193 52.56331 [23,] 64.19532 50.61790 63.82509 83.65810 54.11703 46.91720 57.84776 52.76268 54.95219 53.63407 [24,] 45.49797 48.27573 51.92481 54.57862 50.79933 56.38347 68.06928 63.43156 53.40783 62.90913 [25,] 51.55984 35.85948 53.22969 45.39111 45.86408 49.49657 51.69968 55.64270 58.94122 38.96183 [26,] 53.58082 50.69988 39.02543 42.97550 53.99108 50.08990 52.35218 50.66548 50.67925 45.69530 [27,] 43.77172 48.70752 44.25847 55.51300 43.24571 37.33870 49.48278 43.48238 43.99852 56.00743 [28,] 53.39500 41.17332 36.76970 30.95263 30.85719 53.99376 54.14883 39.12847 47.87979 47.93795 [29,] 39.76479 42.38569 42.58119 44.28197 42.46808 55.51638 54.74995 70.57468 54.34034 62.12476 [30,] 56.04887 41.19998 52.03106 26.05970 62.08028 62.19663 48.04010 44.35547 59.27469 45.64430 [31,] 51.67485 49.59852 58.47197 59.07896 45.35639 57.93580 42.13661 42.63404 42.24011 47.23180 [32,] 51.99078 65.74554 56.33426 46.05164 53.91476 50.74391 51.73119 50.27019 59.82805 37.05341 [33,] 49.74211 62.27820 48.81314 54.70101 50.39751 68.90879 54.50946 43.04678 52.17150 47.82409 [34,] 36.57067 57.90402 41.13891 45.16604 47.59240 33.72334 63.08826 37.79343 54.81282 47.90385 [35,] 49.30751 49.02229 59.76337 47.37464 46.42542 50.90187 32.53116 50.49501 48.52102 41.60642 [36,] 57.56422 53.71520 47.42651 39.15216 51.02491 50.79472 55.27079 60.71923 58.33057 74.66341 [37,] 52.64783 51.84992 53.47862 62.51350 43.89166 63.26215 47.09492 45.93336 38.78545 56.61203 [38,] 45.19855 38.36023 54.27924 53.39651 62.49347 72.60950 54.12119 41.64481 41.43452 53.41978 [39,] 52.32353 52.06405 49.39770 61.31271 43.95251 42.65054 38.13406 50.87544 63.33668 52.39863 [40,] 48.47592 58.31649 45.54506 56.05750 38.39454 50.12381 49.18111 48.75027 43.93205 46.66388 [41,] 67.07461 60.13623 42.53814 68.97204 47.69567 45.32030 47.48994 63.76420 38.07996 63.75085 [42,] 71.85805 58.38574 58.13872 49.74543 50.17586 45.12533 49.02387 66.69618 65.25157 56.32670 [43,] 51.62337 43.00289 30.30423 39.95825 39.88318 59.00877 44.43473 54.66387 53.93165 55.30936 [44,] 38.43831 33.78761 40.02057 45.27031 62.05092 82.57354 48.71318 38.68813 64.48033 48.89013 [45,] 37.52010 35.84489 55.37606 46.12855 32.57734 39.52067 39.15877 51.72580 45.54653 37.83903 [46,] 47.72658 38.80433 47.50002 33.93758 63.58965 55.01357 51.09712 38.15563 49.55098 52.54643 [47,] 58.06117 35.49947 55.86129 56.47925 38.50557 69.84278 60.12157 46.11986 42.75324 60.12883 [48,] 49.91938 37.72957 46.77800 52.91296 65.16691 58.62607 38.33356 54.70574 45.74052 40.37660 [49,] 36.92191 59.03154 54.21787 47.13958 54.08720 41.55248 53.15200 34.00196 60.43739 43.38070 [50,] 54.75323 58.00168 53.99966 61.96173 65.32593 54.63450 38.67616 62.49299 59.21458 59.07442 Low_CI Up_CI [1,] 44.80385 57.19975 [2,] 41.41902 53.81492 [3,] 45.98519 58.38109 [4,] 49.12253 61.51843 [5,] 47.67588 60.07178 [6,] 38.91320 51.30910 [7,] 46.32589 58.72179 [8,] 44.64170 57.03760 [9,] 43.56351 55.95941 [10,] 38.68578 51.08168 [11,] 39.71225 52.10815 [12,] 48.16411 60.56001 [13,] 42.34133 54.73723 [14,] 41.62774 54.02364 [15,] 41.52608 53.92198 [16,] 41.08180 53.47770 [17,] 43.73059 56.12649 [18,] 48.50750 60.90340 [19,] 40.62729 53.02319 [20,] 48.18804 60.58394 [21,] 45.17548 57.57138 [22,] 45.62225 58.01815 [23,] 52.05479 64.45069 [24,] 49.32982 61.72572 [25,] 42.46667 54.86257 [26,] 42.77753 55.17343 [27,] 40.38267 52.77857 [28,] 37.42571 49.82161 [29,] 44.68083 57.07673 [30,] 43.49516 55.89106 [31,] 43.43795 55.83385 [32,] 46.16842 58.56432 [33,] 47.04131 59.43721 [34,] 40.37142 52.76732 [35,] 41.39692 53.79282 [36,] 48.66822 61.06412 [37,] 45.40899 57.80489 [38,] 45.49783 57.89373 [39,] 44.44663 56.84253 [40,] 42.34611 54.74201 [41,] 48.28424 60.68014 [42,] 50.87479 63.27069 [43,] 41.01408 53.40998 [44,] 44.09335 56.48925 [45,] 35.92582 48.32172 [46,] 41.59424 53.99014 [47,] 46.13935 58.53525 [48,] 42.83098 55.22688 [49,] 42.19431 54.59022 [50,] 50.61554 63.01144
Mean = 0.9
There is 90% times when the 95%
confidence interval cover the true value of mean.