##Question 1
mean(my_sample$anxiety)
## [1] 50.08
sd(my_sample$anxiety)
## [1] 5.348431
50+(1.96*(5/sqrt(50)))
## [1] 51.38593
50-(1.96*(5/sqrt(50)))
## [1] 48.61407
mean(my_sample$depression)
## [1] 99.88
sd(my_sample$depression)
## [1] 12.28345
99.88+(1.96*(10/sqrt(50)))
## [1] 102.6519
99.88-(1.96*(10/sqrt(50)))
## [1] 97.10814
mean(my_sample$sociable)
## [1] 100.92
sd(my_sample$sociable)
## [1] 13.54937
100.92+(1.96*(11/sqrt(50)))
## [1] 103.969
100.92-(1.96*(11/sqrt(50)))
## [1] 97.87096
mean(my_sample$control)
## [1] 61.58
sd(my_sample$control)
## [1] 11.41265
61.58+(1.96*(9.9/sqrt(50)))
## [1] 64.32414
61.58-(1.96*(9.9/sqrt(50)))
## [1] 58.83586
mean(my_sample$memory)
## [1] 91.3
sd(my_sample$memory)
## [1] 13.17891
91.3+(1.96*(10.5/sqrt(50)))
## [1] 94.21045
91.3-(1.96*(10.5/sqrt(50)))
## [1] 88.38955
mean(my_sample$intelligence)
## [1] 107.68
sd(my_sample$intelligence)
## [1] 10.38531
107.68+(1.96*(9.5/sqrt(50)))
## [1] 110.3133
107.68-(1.96*(9.5/sqrt(50)))
## [1] 105.0467
The 95% CI for anxiety is (48.6, 51.4) The 95% CI for depression is (97.1, 102.7) The 95% CI for sociable is (97.9, 104) The 95% CI for control is (58.8, 64.3) The 95% CI for memory is (88.4, 94.2) The 95% CI for Intelligence is (105.05, 110.3)
##Question 2
ciMean(my_sample$anxiety)
## 2.5% 97.5%
## [1,] 48.55999 51.60001
ciMean(my_sample$depression)
## 2.5% 97.5%
## [1,] 96.38908 103.3709
ciMean(my_sample$sociable)
## 2.5% 97.5%
## [1,] 97.06931 104.7707
ciMean(my_sample$control)
## 2.5% 97.5%
## [1,] 58.33656 64.82344
ciMean(my_sample$memory)
## 2.5% 97.5%
## [1,] 87.5546 95.0454
ciMean(my_sample$intelligence)
## 2.5% 97.5%
## [1,] 104.7285 110.6315
I think that the intervals are wider because r studio uses a
different critical value to increase the confidence interval to ensure
that the value we are looking for is within the range.
##Question 3
mean(aliens$anxiety)
## [1] 49.9967
mean(aliens$depression)
## [1] 100.0021
mean(aliens$sociable)
## [1] 99.9884
mean(aliens$control)
## [1] 60.069
mean(aliens$memory)
## [1] 92.0556
mean(aliens$intelligence)
## [1] 108.5385
All six of of the CIs obtained in question 2 correspond to the population means, meaning that the population means are within the CI ranges found.
##Question 4
foo <- make.sampling.dist.ci(studentID = 34252777, n.indiv = 50,
data = aliens, n.samples = 100, variable = "intelligence",
conf.level = .95)
foo
## sample.mean CI.lower CI.upper
## 1 107.68 104.7285 110.6315
## 2 110.14 107.9551 112.3249
## 3 109.44 106.8632 112.0168
## 4 107.42 104.8127 110.0273
## 5 109.86 107.3685 112.3515
## 6 109.20 106.4131 111.9869
## 7 106.22 103.6000 108.8400
## 8 106.54 103.9131 109.1669
## 9 108.60 106.0316 111.1684
## 10 107.82 104.9328 110.7072
## 11 107.72 105.1516 110.2884
## 12 110.94 107.5742 114.3058
## 13 112.32 109.9219 114.7181
## 14 108.52 105.4611 111.5789
## 15 106.64 103.7872 109.4928
## 16 107.98 105.3379 110.6221
## 17 109.06 106.5590 111.5610
## 18 107.72 105.6049 109.8351
## 19 108.46 105.7711 111.1489
## 20 110.56 107.7524 113.3676
## 21 105.38 102.5696 108.1904
## 22 107.00 104.2048 109.7952
## 23 108.04 105.5307 110.5493
## 24 110.14 107.7047 112.5753
## 25 109.90 107.5034 112.2966
## 26 107.56 104.8822 110.2378
## 27 105.08 102.3530 107.8070
## 28 110.32 107.5578 113.0822
## 29 109.10 106.2045 111.9955
## 30 107.10 104.1219 110.0781
## 31 106.38 103.8945 108.8655
## 32 109.76 107.0961 112.4239
## 33 109.24 106.7022 111.7778
## 34 107.16 104.4405 109.8795
## 35 109.54 106.8968 112.1832
## 36 109.18 106.6086 111.7514
## 37 110.12 107.0033 113.2367
## 38 109.26 106.6751 111.8449
## 39 106.70 104.3775 109.0225
## 40 106.44 103.7346 109.1454
## 41 108.24 105.7362 110.7438
## 42 111.00 108.1131 113.8869
## 43 107.82 104.9713 110.6687
## 44 107.64 105.0488 110.2312
## 45 105.88 103.0307 108.7293
## 46 108.96 106.3936 111.5264
## 47 111.52 108.8176 114.2224
## 48 106.82 104.2250 109.4150
## 49 109.20 106.4220 111.9780
## 50 107.06 104.3944 109.7256
## 51 107.30 104.4935 110.1065
## 52 106.40 103.2651 109.5349
## 53 107.74 105.1653 110.3147
## 54 109.08 106.3289 111.8311
## 55 111.08 108.4079 113.7521
## 56 108.78 106.0503 111.5097
## 57 105.20 102.8919 107.5081
## 58 110.40 107.5401 113.2599
## 59 110.64 108.1467 113.1333
## 60 107.34 104.5884 110.0916
## 61 109.12 106.0309 112.2091
## 62 109.88 106.6292 113.1308
## 63 108.26 105.6738 110.8462
## 64 109.08 106.6145 111.5455
## 65 110.24 107.6167 112.8633
## 66 109.70 107.1905 112.2095
## 67 110.34 107.6699 113.0101
## 68 109.06 106.2675 111.8525
## 69 108.52 105.7424 111.2976
## 70 106.92 104.3116 109.5284
## 71 106.60 104.1344 109.0656
## 72 108.96 106.6865 111.2335
## 73 106.18 103.5297 108.8303
## 74 109.50 106.8178 112.1822
## 75 105.64 102.8758 108.4042
## 76 109.16 106.4496 111.8704
## 77 108.90 106.4323 111.3677
## 78 108.30 105.5571 111.0429
## 79 104.72 102.1077 107.3323
## 80 109.46 106.6121 112.3079
## 81 107.72 104.7504 110.6896
## 82 107.84 105.6005 110.0795
## 83 106.86 104.0070 109.7130
## 84 109.58 107.2833 111.8767
## 85 109.44 106.6750 112.2050
## 86 109.68 106.8360 112.5240
## 87 107.96 105.0217 110.8983
## 88 108.32 105.4443 111.1957
## 89 106.28 104.0518 108.5082
## 90 109.74 107.5061 111.9739
## 91 109.20 106.4554 111.9446
## 92 105.38 102.8040 107.9560
## 93 110.82 108.0852 113.5548
## 94 108.18 105.7811 110.5789
## 95 108.92 106.0585 111.7815
## 96 109.72 107.1683 112.2717
## 97 107.94 105.4134 110.4666
## 98 108.08 105.5590 110.6010
## 99 111.06 108.4342 113.6858
## 100 108.58 106.2050 110.9550
There are 8 cases where the CI does not include the population mean and you would expect to have only 5 cases because you are finding a 95% CI so you should only have 5% of cases not have the mean population, not 8%.
##Question 5
foo <- make.sampling.dist.ci(studentID = 34252777, n.indiv = 50,
data = aliens, n.samples = 100, variable = "intelligence",
conf.level = .80)
foo
## sample.mean CI.lower CI.upper
## 1 107.68 105.7721 109.5879
## 2 110.14 108.7276 111.5524
## 3 109.44 107.7742 111.1058
## 4 107.42 105.7345 109.1055
## 5 109.86 108.2494 111.4706
## 6 109.20 107.3984 111.0016
## 7 106.22 104.5263 107.9137
## 8 106.54 104.8419 108.2381
## 9 108.60 106.9397 110.2603
## 10 107.82 105.9536 109.6864
## 11 107.72 106.0597 109.3803
## 12 110.94 108.7642 113.1158
## 13 112.32 110.7698 113.8702
## 14 108.52 106.5426 110.4974
## 15 106.64 104.7958 108.4842
## 16 107.98 106.2721 109.6879
## 17 109.06 107.4432 110.6768
## 18 107.72 106.3527 109.0873
## 19 108.46 106.7218 110.1982
## 20 110.56 108.7450 112.3750
## 21 105.38 103.5632 107.1968
## 22 107.00 105.1931 108.8069
## 23 108.04 106.4179 109.6621
## 24 110.14 108.5657 111.7143
## 25 109.90 108.3508 111.4492
## 26 107.56 105.8289 109.2911
## 27 105.08 103.3171 106.8429
## 28 110.32 108.5344 112.1056
## 29 109.10 107.2282 110.9718
## 30 107.10 105.1749 109.0251
## 31 106.38 104.7733 107.9867
## 32 109.76 108.0380 111.4820
## 33 109.24 107.5995 110.8805
## 34 107.16 105.4020 108.9180
## 35 109.54 107.8314 111.2486
## 36 109.18 107.5178 110.8422
## 37 110.12 108.1052 112.1348
## 38 109.26 107.5890 110.9310
## 39 106.70 105.1986 108.2014
## 40 106.44 104.6911 108.1889
## 41 108.24 106.6215 109.8585
## 42 111.00 109.1338 112.8662
## 43 107.82 105.9785 109.6615
## 44 107.64 105.9649 109.3151
## 45 105.88 104.0381 107.7219
## 46 108.96 107.3010 110.6190
## 47 111.52 109.7731 113.2669
## 48 106.82 105.1425 108.4975
## 49 109.20 107.4042 110.9958
## 50 107.06 105.3368 108.7832
## 51 107.30 105.4858 109.1142
## 52 106.40 104.3735 108.4265
## 53 107.74 106.0756 109.4044
## 54 109.08 107.3016 110.8584
## 55 111.08 109.3527 112.8073
## 56 108.78 107.0154 110.5446
## 57 105.20 103.7079 106.6921
## 58 110.40 108.5513 112.2487
## 59 110.64 109.0282 112.2518
## 60 107.34 105.5613 109.1187
## 61 109.12 107.1231 111.1169
## 62 109.88 107.7785 111.9815
## 63 108.26 106.5882 109.9318
## 64 109.08 107.4862 110.6738
## 65 110.24 108.5442 111.9358
## 66 109.70 108.0778 111.3222
## 67 110.34 108.6140 112.0660
## 68 109.06 107.2548 110.8652
## 69 108.52 106.7245 110.3155
## 70 106.92 105.2338 108.6062
## 71 106.60 105.0062 108.1938
## 72 108.96 107.4903 110.4297
## 73 106.18 104.4667 107.8933
## 74 109.50 107.7661 111.2339
## 75 105.64 103.8531 107.4269
## 76 109.16 107.4079 110.9121
## 77 108.90 107.3048 110.4952
## 78 108.30 106.5268 110.0732
## 79 104.72 103.0313 106.4087
## 80 109.46 107.6190 111.3010
## 81 107.72 105.8003 109.6397
## 82 107.84 106.3923 109.2877
## 83 106.86 105.0157 108.7043
## 84 109.58 108.0953 111.0647
## 85 109.44 107.6526 111.2274
## 86 109.68 107.8415 111.5185
## 87 107.96 106.0605 109.8595
## 88 108.32 106.4611 110.1789
## 89 106.28 104.8396 107.7204
## 90 109.74 108.2959 111.1841
## 91 109.20 107.4258 110.9742
## 92 105.38 103.7148 107.0452
## 93 110.82 109.0521 112.5879
## 94 108.18 106.6292 109.7308
## 95 108.92 107.0702 110.7698
## 96 109.72 108.0705 111.3695
## 97 107.94 106.3067 109.5733
## 98 108.08 106.4503 109.7097
## 99 111.06 109.3626 112.7574
## 100 108.58 107.0447 110.1153
There are 30 samples where the population intelligence is not included within the CI and you would expect to only see 20 of the samples not include the population mean. This is because we are finding the 80% CI which should have 20% of samples not include the mean instead of 30% in 100 samples.
##Question 6
income_mean <- make.sampling.dist.ci(studentID = 34252777, n.indiv = 40,
data = aliens, n.samples = 100, variable = "income",
conf.level = .95)
income_mean
## sample.mean CI.lower CI.upper
## 1 65125 51030.74 79219.26
## 2 70175 57307.18 83042.82
## 3 66925 55921.71 77928.29
## 4 75675 60908.26 90441.74
## 5 81875 61581.53 102168.47
## 6 69150 52793.96 85506.04
## 7 67200 51418.02 82981.98
## 8 74025 58213.59 89836.41
## 9 52675 43405.19 61944.81
## 10 73950 56181.92 91718.08
## 11 56600 46352.13 66847.87
## 12 73450 57568.51 89331.49
## 13 76700 59619.43 93780.57
## 14 66775 52988.27 80561.73
## 15 68300 52657.40 83942.60
## 16 60725 50606.36 70843.64
## 17 56075 47137.64 65012.36
## 18 61625 44434.46 78815.54
## 19 64250 49239.05 79260.95
## 20 77100 61910.50 92289.50
## 21 80625 64476.62 96773.38
## 22 70425 56880.77 83969.23
## 23 65625 50616.51 80633.49
## 24 72775 54408.07 91141.93
## 25 54725 43917.08 65532.92
## 26 77150 58849.86 95450.14
## 27 58125 46888.50 69361.50
## 28 57300 44126.76 70473.24
## 29 64125 49105.59 79144.41
## 30 75900 56304.29 95495.71
## 31 71025 54789.51 87260.49
## 32 61900 48580.73 75219.27
## 33 74225 60444.93 88005.07
## 34 56300 44681.61 67918.39
## 35 73800 60426.80 87173.20
## 36 78325 62737.79 93912.21
## 37 74300 53455.33 95144.67
## 38 63250 53507.23 72992.77
## 39 70175 49414.84 90935.16
## 40 60100 47300.66 72899.34
## 41 66550 54024.85 79075.15
## 42 59800 47529.49 72070.51
## 43 53275 42138.89 64411.11
## 44 78650 61161.67 96138.33
## 45 66975 48590.94 85359.06
## 46 79900 57570.53 102229.47
## 47 76425 59597.08 93252.92
## 48 66625 53978.42 79271.58
## 49 62100 49584.52 74615.48
## 50 76450 55170.67 97729.33
## 51 73975 59376.50 88573.50
## 52 73375 57582.64 89167.36
## 53 59900 48658.23 71141.77
## 54 68525 45156.29 91893.71
## 55 67575 51720.79 83429.21
## 56 67500 53873.71 81126.29
## 57 70250 54310.19 86189.81
## 58 74950 57285.84 92614.16
## 59 64150 45451.35 82848.65
## 60 61450 49419.57 73480.43
## 61 66325 52391.45 80258.55
## 62 67150 55857.77 78442.23
## 63 78150 60445.11 95854.89
## 64 67100 52518.34 81681.66
## 65 71175 55913.14 86436.86
## 66 55050 44152.91 65947.09
## 67 59225 46091.78 72358.22
## 68 73775 59371.46 88178.54
## 69 63000 49547.46 76452.54
## 70 66700 51560.59 81839.41
## 71 76750 59070.14 94429.86
## 72 79525 58683.88 100366.12
## 73 69850 51414.65 88285.35
## 74 87225 66047.03 108402.97
## 75 60550 47501.83 73598.17
## 76 84075 58701.34 109448.66
## 77 64200 52503.77 75896.23
## 78 67225 51989.01 82460.99
## 79 56825 46342.55 67307.45
## 80 63375 48902.95 77847.05
## 81 75900 59118.13 92681.87
## 82 68225 52082.50 84367.50
## 83 72600 59935.99 85264.01
## 84 79725 64193.82 95256.18
## 85 70950 54978.93 86921.07
## 86 68350 53148.12 83551.88
## 87 66950 52834.21 81065.79
## 88 72000 57668.66 86331.34
## 89 72275 59493.87 85056.13
## 90 58100 42816.18 73383.82
## 91 61150 48044.96 74255.04
## 92 61125 48803.73 73446.27
## 93 69550 55032.48 84067.52
## 94 61375 49976.41 72773.59
## 95 64025 49915.62 78134.38
## 96 70975 56496.82 85453.18
## 97 67950 50590.45 85309.55
## 98 69325 51866.56 86783.44
## 99 86275 67228.74 105321.26
## 100 84450 66461.87 102438.13
hist(income_mean$sample.mean)
The graph did not begin to look normal untill I got to a sample size of
40.
##Question 7
my_sample_200 <- make.my.sample(34252777, 200, aliens)
bargraph.CI(x.factor = my_sample_200$college, response = my_sample_200$sociable,
ci.fun = ciMean, ylim = c(0, 150))
The following graphs show the mean sociability of a sample of 200 aliens
depending on the college they attend. The error bars demonstrate the
margin of error that could exist with the mean value that was found.
This means that the real mean could be anywhere between the bars, which
shows that there could be an equal mean value for sociability within the
sample at all the colleges since all the error bars fall within each
other.
##Question 8
my_sample_200 <- make.my.sample(34252777, 200, aliens)
bargraph.CI(x.factor = my_sample_200$college, response = my_sample_200$intelligence,
ci.fun = ciMean, ylim = c(0, 150))
I tested our numerous different values and discovered that anxiety,
depression, and control are all equal between the two colleges, but
intelligence differs. Callisto and Europa both have equal intelligence
levels between the two and Ganymede and Io both have equal, but Ganymede
and Io have a higher mean intelligence than the other two schools.
##Question 9
my_sample_200 <- make.my.sample(34252777, 200, aliens)
bargraph.CI(x.factor = my_sample_200$college, response = my_sample_200$sociable, ylim = c(0, 150))
Getting rid of the ci.fun=ciMean argument makes the error bars much
smaller for all of the variables. I believe this is because the standard
deviation is smaller than the CI, making the error bars smaller.