class: center, middle, inverse, title-slide # Simulation study about confidence intervals ### STAT 021 with Prof Suzy ### Swarthmore College --- <style type="text/css"> pre { background: #FFBB33; max-width: 100%; overflow-x: scroll; } .scroll-output { height: 70%; overflow-y: scroll; } .scroll-small { height: 50%; overflow-y: scroll; } .red{color: #ce151e;} .green{color: #26b421;} .blue{color: #426EF0;} </style> ## Problem set-up `$$y = 50 + 10x + \epsilon, \quad \text{where } \epsilon \sim N(0,16)$$` Generate 500 samples of 20 observations drawing one observation for each level of `\(x=1,1.5,2, \dots,10\)` for each sample. ```r set.seed(1001) # this makes all our code results reproducible remove(list=ls()) # this makes sure we clear all previously defined environmental variables library('tidyverse') x <- seq(0.5, 10, by=0.5) generate.response <- function(x){ y <- 50 + 10*x + rnorm(20, mean=0, sd=4) return(y) } y_mtx <- matrix(rep(x, 500), ncol=500, byrow=FALSE) y_mtx <- apply(y_mtx, 2, generate.response) ``` .footnote[This is based on Problem 2.23 of our textbook.] --- ## Part 1 ### For each sample compute the least-squares estimates of the slope and intercept. .scroll-output[ ```r estimate.parameters <- function(response, predictor=x){ mod = lm(response ~ predictor) beta0_hat = mod$coefficients[1] beta1_hat = mod$coefficients[2] return(c(beta0_hat, beta1_hat)) } estimated_betas <- matrix(rep(NA,500*2), ncol=2) colnames(estimated_betas) <- c("beta0_hat", "beta1_hat") for(k in 1:500){ estimated_betas[k,] = estimate.parameters(y_mtx[ ,k]) } (estimated_betas <- data.frame(estimated_betas)) ``` ``` ## beta0_hat beta1_hat ## 1 49.36025 10.119946 ## 2 50.50145 9.955727 ## 3 49.05717 10.230453 ## 4 51.85018 9.650854 ## 5 48.92939 10.097233 ## 6 49.94559 9.876696 ## 7 54.51256 9.264963 ## 8 50.27653 9.998367 ## 9 49.89103 9.855813 ## 10 49.08186 10.321053 ## 11 50.54902 10.199823 ## 12 50.99510 9.809642 ## 13 50.07954 10.068946 ## 14 47.66235 10.380888 ## 15 46.41288 10.374000 ## 16 49.14913 10.016137 ## 17 50.48089 9.761221 ## 18 51.82931 9.888719 ## 19 50.32666 10.099167 ## 20 49.58916 10.104864 ## 21 47.88446 10.202420 ## 22 48.30015 10.072072 ## 23 48.32303 10.149130 ## 24 49.80229 10.419065 ## 25 52.39232 9.594094 ## 26 51.13039 9.782921 ## 27 51.69008 9.694311 ## 28 51.72601 9.574929 ## 29 50.40125 9.869801 ## 30 48.90777 9.827512 ## 31 49.95591 10.037724 ## 32 50.13531 10.122602 ## 33 48.19467 10.180164 ## 34 49.45791 10.506829 ## 35 50.19787 9.952744 ## 36 49.51913 10.278822 ## 37 50.94617 10.089459 ## 38 47.57353 10.384631 ## 39 48.04002 9.993129 ## 40 50.78207 9.935562 ## 41 49.06506 10.256130 ## 42 51.06710 9.712085 ## 43 47.77837 10.353454 ## 44 51.47534 10.046072 ## 45 52.36845 9.660555 ## 46 51.27537 9.650016 ## 47 54.75501 9.268795 ## 48 49.51485 10.238416 ## 49 49.32407 10.285986 ## 50 50.60282 10.038412 ## 51 51.02901 9.679336 ## 52 52.80791 9.698226 ## 53 53.72271 9.746433 ## 54 49.29696 10.073581 ## 55 48.57237 10.079550 ## 56 48.32190 10.307795 ## 57 52.34643 9.588393 ## 58 46.82501 10.545065 ## 59 53.96935 9.356672 ## 60 53.19654 9.348059 ## 61 47.26604 10.237532 ## 62 48.89625 10.213843 ## 63 50.75347 9.849713 ## 64 48.43198 9.990531 ## 65 48.35327 10.279806 ## 66 48.74287 10.185137 ## 67 47.83764 10.533588 ## 68 47.91771 10.157721 ## 69 53.45524 9.445088 ## 70 49.40349 10.186229 ## 71 50.04148 10.082817 ## 72 49.39188 10.239942 ## 73 52.34182 9.512561 ## 74 50.15205 9.885870 ## 75 48.73729 10.357533 ## 76 52.72573 9.664966 ## 77 51.91193 9.582834 ## 78 50.02408 9.951382 ## 79 50.31487 9.659862 ## 80 48.87429 10.161652 ## 81 49.11028 10.551244 ## 82 48.28354 10.236868 ## 83 48.02888 10.470806 ## 84 51.02403 10.176934 ## 85 52.57178 9.440518 ## 86 49.05629 10.239853 ## 87 51.49287 9.752545 ## 88 49.49741 9.983482 ## 89 49.27763 10.026048 ## 90 47.83668 10.355431 ## 91 48.54145 10.113094 ## 92 51.43650 9.817371 ## 93 50.23036 10.001923 ## 94 51.84316 9.679424 ## 95 48.57198 10.250392 ## 96 48.87314 10.181976 ## 97 51.79292 9.642417 ## 98 51.60146 9.674266 ## 99 48.15380 10.278138 ## 100 48.14763 10.130005 ## 101 49.55774 10.238389 ## 102 50.67971 9.990875 ## 103 48.68094 10.052219 ## 104 47.06739 10.368637 ## 105 49.01302 9.996641 ## 106 49.12004 10.166130 ## 107 48.42784 10.021121 ## 108 49.07326 10.170304 ## 109 52.67829 9.441844 ## 110 47.57268 10.082077 ## 111 47.88799 10.280058 ## 112 50.88071 10.003946 ## 113 50.05232 9.840240 ## 114 49.03003 10.120635 ## 115 48.85271 10.174011 ## 116 49.85416 9.929253 ## 117 49.54462 10.003007 ## 118 52.05423 9.507854 ## 119 49.70730 9.728289 ## 120 50.91511 9.629949 ## 121 50.90589 9.594236 ## 122 47.91967 10.394651 ## 123 50.66089 9.887822 ## 124 50.42378 10.068302 ## 125 49.00043 10.262450 ## 126 48.75485 10.472710 ## 127 47.58824 10.490750 ## 128 53.79768 9.389367 ## 129 49.01148 10.047839 ## 130 51.00751 9.540544 ## 131 49.51905 9.922761 ## 132 47.65248 10.521199 ## 133 50.55352 9.971932 ## 134 46.93152 10.561638 ## 135 49.88277 9.813954 ## 136 48.96689 9.974236 ## 137 52.00156 9.845025 ## 138 46.98215 10.534203 ## 139 48.30701 10.184671 ## 140 49.68327 10.123682 ## 141 53.10081 9.520256 ## 142 48.95251 10.129944 ## 143 50.98754 10.197132 ## 144 51.19936 9.693178 ## 145 46.73443 10.416121 ## 146 49.61662 10.043102 ## 147 50.17202 10.036949 ## 148 51.66234 9.652709 ## 149 46.50800 10.448233 ## 150 53.14888 9.754943 ## 151 50.60578 10.110856 ## 152 48.02057 10.447847 ## 153 45.62096 10.630380 ## 154 53.69247 9.345274 ## 155 47.34544 10.474141 ## 156 50.49340 9.924675 ## 157 49.30506 9.915072 ## 158 48.52295 10.228035 ## 159 49.58328 10.077322 ## 160 50.94662 9.957272 ## 161 49.86260 10.154127 ## 162 48.31979 10.194347 ## 163 48.37878 10.337467 ## 164 49.83159 10.263352 ## 165 51.07510 9.885043 ## 166 50.32978 9.811358 ## 167 51.75743 9.820098 ## 168 48.31965 10.103592 ## 169 49.88163 9.835899 ## 170 46.24465 10.400259 ## 171 52.04073 9.700025 ## 172 51.34716 9.807354 ## 173 50.53137 9.788471 ## 174 50.58537 10.012516 ## 175 47.28578 10.409071 ## 176 49.08124 10.070018 ## 177 51.57842 9.578043 ## 178 48.53781 10.227521 ## 179 50.32892 9.874678 ## 180 48.60386 10.197100 ## 181 51.76282 9.875729 ## 182 48.15354 10.349409 ## 183 49.90340 9.968051 ## 184 49.61621 9.951955 ## 185 50.07061 9.796735 ## 186 52.77577 9.577772 ## 187 50.03592 9.985224 ## 188 48.97417 10.454097 ## 189 48.50515 10.303186 ## 190 47.70914 10.278724 ## 191 51.29228 10.070247 ## 192 49.57053 10.081581 ## 193 50.12977 10.232296 ## 194 49.34939 10.202476 ## 195 47.98694 10.295779 ## 196 53.23820 9.342819 ## 197 49.17228 10.055436 ## 198 49.24930 10.035068 ## 199 51.10419 9.846128 ## 200 50.73292 9.717219 ## 201 47.65227 10.487285 ## 202 49.95882 10.072693 ## 203 49.73385 10.024113 ## 204 47.76085 10.409730 ## 205 51.61410 9.797304 ## 206 45.81386 10.658089 ## 207 48.21130 10.170520 ## 208 48.51418 10.187693 ## 209 46.86120 10.499775 ## 210 52.14791 9.555164 ## 211 47.78836 10.385363 ## 212 51.46218 9.925178 ## 213 50.47244 9.960023 ## 214 52.79056 9.504991 ## 215 50.20723 10.003616 ## 216 51.39221 9.741009 ## 217 51.89160 9.567216 ## 218 50.93050 9.769581 ## 219 49.04729 10.275245 ## 220 49.96431 9.886033 ## 221 50.98197 9.845672 ## 222 54.72735 9.390588 ## 223 54.03509 9.475121 ## 224 49.49549 9.995472 ## 225 51.63606 9.711645 ## 226 50.12382 9.987935 ## 227 50.63941 9.857899 ## 228 51.55137 9.792909 ## 229 49.47117 10.077976 ## 230 50.26712 10.002255 ## 231 48.34186 10.266439 ## 232 51.09473 10.016301 ## 233 50.69109 10.049807 ## 234 48.49634 10.270640 ## 235 49.51396 10.239106 ## 236 51.31532 9.697718 ## 237 51.21460 9.732116 ## 238 49.78039 9.505371 ## 239 55.70964 9.303864 ## 240 50.96367 9.873757 ## 241 50.62587 9.836270 ## 242 49.98097 10.029839 ## 243 46.61430 10.617537 ## 244 51.31233 9.772220 ## 245 49.87186 9.920033 ## 246 50.06077 9.841075 ## 247 52.49493 9.489007 ## 248 50.31021 9.954801 ## 249 50.22615 10.009501 ## 250 51.10284 9.916259 ## 251 46.85876 10.335076 ## 252 49.85387 9.951336 ## 253 47.00557 10.321562 ## 254 51.80778 9.901625 ## 255 50.95614 9.603398 ## 256 50.04948 10.246473 ## 257 51.38073 9.924828 ## 258 52.30880 9.544024 ## 259 48.66856 10.398209 ## 260 45.78686 10.631930 ## 261 49.98596 9.707821 ## 262 47.06820 10.334463 ## 263 48.79425 10.069057 ## 264 47.86755 10.431341 ## 265 50.50118 9.926633 ## 266 48.22832 10.119704 ## 267 53.03595 9.835284 ## 268 51.42536 9.830879 ## 269 51.36885 9.866260 ## 270 49.02454 10.359843 ## 271 50.79689 9.774238 ## 272 49.35955 10.212416 ## 273 49.26931 10.163382 ## 274 49.56260 10.107475 ## 275 51.79556 9.647679 ## 276 51.15788 9.608794 ## 277 50.56801 9.782889 ## 278 51.39958 9.793135 ## 279 47.70855 10.573763 ## 280 49.40926 10.012224 ## 281 48.42082 10.635105 ## 282 52.16961 9.763180 ## 283 48.42531 10.257661 ## 284 52.31532 9.423723 ## 285 54.39133 9.529933 ## 286 50.01303 10.053356 ## 287 49.01920 9.950735 ## 288 50.20477 9.895075 ## 289 52.14086 9.579884 ## 290 48.01027 10.181068 ## 291 48.77477 10.053323 ## 292 49.18167 10.281946 ## 293 50.57171 9.758922 ## 294 50.74830 9.953009 ## 295 47.14650 10.555386 ## 296 49.34743 10.155939 ## 297 50.15167 9.880458 ## 298 49.41361 9.978328 ## 299 53.27377 9.839105 ## 300 50.25853 9.881689 ## 301 49.19644 10.120941 ## 302 47.71828 10.243396 ## 303 49.40054 10.198556 ## 304 52.01879 9.689416 ## 305 49.27859 10.149903 ## 306 50.58467 9.769194 ## 307 48.58250 10.219513 ## 308 50.33468 9.842422 ## 309 50.87412 9.782802 ## 310 45.22658 10.893313 ## 311 48.59013 10.242563 ## 312 53.14382 9.694967 ## 313 47.25737 10.418286 ## 314 51.09304 9.734875 ## 315 51.29925 9.770201 ## 316 51.83571 9.788883 ## 317 50.60747 9.842374 ## 318 51.38572 9.953026 ## 319 51.86682 9.997074 ## 320 44.39325 11.034288 ## 321 50.81656 9.755472 ## 322 46.44695 10.400513 ## 323 48.29401 10.309510 ## 324 50.93734 9.943227 ## 325 48.75109 10.324900 ## 326 51.56081 9.767661 ## 327 52.33155 9.851333 ## 328 50.79239 9.596042 ## 329 48.81143 10.141915 ## 330 52.37866 9.664431 ## 331 51.50929 9.579842 ## 332 47.50255 10.540831 ## 333 47.66092 10.477259 ## 334 51.38948 9.721964 ## 335 50.32302 9.849941 ## 336 53.61632 9.517424 ## 337 49.21240 10.109408 ## 338 52.85201 9.435259 ## 339 50.01058 10.031822 ## 340 52.74289 9.617208 ## 341 51.04120 9.450681 ## 342 48.95799 10.225189 ## 343 47.37957 10.440234 ## 344 50.04351 9.878949 ## 345 49.52700 9.871946 ## 346 51.07176 9.786138 ## 347 49.66561 10.254691 ## 348 49.79744 10.239883 ## 349 49.50325 9.884223 ## 350 53.28799 9.582329 ## 351 49.93906 9.981827 ## 352 50.44902 9.566933 ## 353 53.13474 9.625740 ## 354 51.56625 9.549063 ## 355 49.72489 9.869689 ## 356 48.27467 10.339757 ## 357 52.99383 9.502829 ## 358 50.18093 10.098738 ## 359 45.31589 10.574873 ## 360 50.91629 9.845634 ## 361 48.25786 10.023729 ## 362 49.02481 10.406635 ## 363 51.55815 9.857603 ## 364 52.93757 9.833919 ## 365 50.65396 10.028627 ## 366 54.23483 9.523363 ## 367 51.57217 9.905039 ## 368 51.48628 9.565745 ## 369 50.83701 10.044547 ## 370 50.39965 10.027113 ## 371 52.02646 9.940398 ## 372 48.63739 10.105924 ## 373 52.92982 9.576622 ## 374 50.99660 9.980814 ## 375 53.00417 9.131333 ## 376 51.99979 9.813664 ## 377 50.30501 10.141915 ## 378 52.37188 9.604348 ## 379 51.48186 9.690184 ## 380 52.43590 9.636306 ## 381 49.77410 9.989500 ## 382 49.76291 10.105978 ## 383 51.39248 10.019884 ## 384 47.70247 10.428594 ## 385 49.67129 10.116319 ## 386 50.82817 9.865871 ## 387 49.55354 10.057431 ## 388 50.27430 9.928841 ## 389 50.50892 9.998303 ## 390 52.43142 9.727657 ## 391 48.39914 10.097141 ## 392 52.06390 9.408377 ## 393 51.62036 9.931245 ## 394 51.92929 9.758610 ## 395 47.88419 10.394614 ## 396 49.25798 10.078461 ## 397 50.04718 9.818446 ## 398 50.80009 9.921137 ## 399 51.18594 9.951653 ## 400 51.04504 9.842603 ## 401 46.84631 10.526048 ## 402 50.36581 9.766917 ## 403 48.29100 10.208143 ## 404 51.66692 9.636570 ## 405 47.66682 10.340261 ## 406 49.27685 10.187499 ## 407 48.80071 10.097259 ## 408 50.09762 9.898742 ## 409 48.60572 10.604836 ## 410 48.80017 10.019878 ## 411 47.51199 10.197800 ## 412 51.41162 9.764612 ## 413 51.79326 9.874599 ## 414 51.56204 9.776672 ## 415 48.76053 10.160030 ## 416 53.67061 9.334029 ## 417 48.56775 10.256768 ## 418 49.58506 10.128133 ## 419 51.93371 9.921161 ## 420 51.03007 9.983376 ## 421 52.30719 9.705080 ## 422 50.07127 10.155028 ## 423 47.56318 10.343224 ## 424 56.07046 9.154804 ## 425 50.56119 9.988303 ## 426 51.14843 9.770001 ## 427 51.92602 9.634763 ## 428 50.21180 9.887687 ## 429 48.54118 10.119895 ## 430 48.16126 10.148098 ## 431 49.89851 9.861552 ## 432 50.02443 10.216385 ## 433 51.72571 9.951179 ## 434 51.59015 9.649595 ## 435 52.68701 9.351560 ## 436 51.62971 9.856085 ## 437 50.65808 9.857819 ## 438 49.56850 10.085881 ## 439 51.83591 9.521115 ## 440 50.96385 10.015000 ## 441 50.63596 9.941563 ## 442 48.72710 10.217148 ## 443 50.01341 10.138526 ## 444 49.38119 9.910153 ## 445 48.82968 10.069140 ## 446 47.21331 10.579032 ## 447 53.43022 9.421660 ## 448 51.89360 9.605836 ## 449 48.81556 10.479552 ## 450 49.89474 9.740164 ## 451 50.24432 9.703810 ## 452 49.77070 9.919740 ## 453 49.52412 10.180369 ## 454 47.68451 10.123101 ## 455 50.21953 9.819188 ## 456 47.98120 10.239013 ## 457 48.46408 10.062495 ## 458 50.82297 10.021990 ## 459 48.34814 10.270362 ## 460 51.79498 9.637896 ## 461 48.59471 10.132247 ## 462 47.65304 10.452201 ## 463 51.32785 9.749063 ## 464 51.85652 9.767940 ## 465 52.55866 9.571646 ## 466 53.26740 9.445501 ## 467 51.08973 9.705521 ## 468 48.18478 10.075303 ## 469 51.12926 9.796436 ## 470 49.19222 10.130948 ## 471 49.13536 10.061383 ## 472 50.34984 10.175142 ## 473 50.71104 9.913577 ## 474 53.59056 9.307872 ## 475 51.61379 9.850680 ## 476 49.12896 9.907928 ## 477 47.48438 10.354154 ## 478 48.92587 10.136049 ## 479 52.59232 9.572929 ## 480 47.40416 10.446961 ## 481 48.70096 10.204372 ## 482 52.23934 9.465153 ## 483 49.58510 10.172561 ## 484 48.91699 10.241568 ## 485 50.52881 9.600450 ## 486 52.70216 9.608894 ## 487 48.98715 10.073932 ## 488 50.47069 9.856052 ## 489 48.07058 10.086485 ## 490 49.67596 9.930632 ## 491 49.83018 10.283664 ## 492 50.18298 9.878692 ## 493 50.62011 9.953366 ## 494 50.41430 10.045652 ## 495 48.16126 10.383905 ## 496 54.23450 9.511101 ## 497 49.31523 10.188956 ## 498 47.18252 10.427264 ## 499 49.17363 10.245728 ## 500 50.22792 9.855489 ``` ] --- ## Part 1 ## Visualize the different sample estimates The code on the next two slides constructs histograms of the sample vlaues of `\(\hat{\beta}_0\)` and `\(\hat{\beta}_1\)`. **Question:** Why do these histograms appear to follow a Normal distribution? --- ## Part 1 ### Visualize the different `\(\hat{\beta}_0\)` values .scroll-output[ ```r ggplot(estimated_betas, aes(x=beta0_hat)) + geom_histogram(bins=40) + labs(title= "Histogram of the estimated intercept for a SLR model", x = "beta0_hat values for each sample", y = "Density") ``` ![](Figs/unnamed-chunk-4-1.png)<!-- --> ] --- ## Part 1 ### Visualize the different `\(\hat{\beta}_1\)` values .scroll-output[ ```r ggplot(estimated_betas, aes(x=beta1_hat)) + geom_histogram(bins=40) + labs(title= "Histogram of the estimated slope for a SLR model", x = "beta1_hat values for each sample", y = "Density") ``` ![](Figs/unnamed-chunk-5-1.png)<!-- --> ] --- ## Part 2 ### For each sample, compute an estimate of `\(E[Y \mid x=5]\)`. .scroll-output[ ```r estimate.observation <- function(response,predictor=x){ mod <- lm(response ~ predictor) y_hat <- mod$coefficients[1] + mod$coefficients[2]*5 return(y_hat=y_hat) } y_hats <- rep(NA,500) for(k in 1:500){ y_hats[k] = estimate.observation(y_mtx[ ,k]) } (y_hats <- data.frame(y_hats)) ``` ``` ## y_hats ## 1 99.95998 ## 2 100.28008 ## 3 100.20944 ## 4 100.10445 ## 5 99.41555 ## 6 99.32907 ## 7 100.83737 ## 8 100.26836 ## 9 99.17010 ## 10 100.68713 ## 11 101.54813 ## 12 100.04331 ## 13 100.42427 ## 14 99.56679 ## 15 98.28288 ## 16 99.22982 ## 17 99.28699 ## 18 101.27290 ## 19 100.82250 ## 20 100.11347 ## 21 98.89657 ## 22 98.66051 ## 23 99.06868 ## 24 101.89761 ## 25 100.36279 ## 26 100.04500 ## 27 100.16164 ## 28 99.60066 ## 29 99.75025 ## 30 98.04533 ## 31 100.14453 ## 32 100.74832 ## 33 99.09549 ## 34 101.99205 ## 35 99.96159 ## 36 100.91324 ## 37 101.39346 ## 38 99.49668 ## 39 98.00566 ## 40 100.45988 ## 41 100.34571 ## 42 99.62752 ## 43 99.54564 ## 44 101.70570 ## 45 100.67123 ## 46 99.52545 ## 47 101.09898 ## 48 100.70693 ## 49 100.75400 ## 50 100.79488 ## 51 99.42569 ## 52 101.29904 ## 53 102.45487 ## 54 99.66487 ## 55 98.97012 ## 56 99.86087 ## 57 100.28840 ## 58 99.55034 ## 59 100.75271 ## 60 99.93683 ## 61 98.45370 ## 62 99.96547 ## 63 100.00203 ## 64 98.38464 ## 65 99.75230 ## 66 99.66855 ## 67 100.50558 ## 68 98.70632 ## 69 100.68068 ## 70 100.33464 ## 71 100.45557 ## 72 100.59160 ## 73 99.90462 ## 74 99.58140 ## 75 100.52495 ## 76 101.05056 ## 77 99.82610 ## 78 99.78099 ## 79 98.61419 ## 80 99.68254 ## 81 101.86650 ## 82 99.46789 ## 83 100.38291 ## 84 101.90870 ## 85 99.77438 ## 86 100.25556 ## 87 100.25559 ## 88 99.41482 ## 89 99.40787 ## 90 99.61383 ## 91 99.10692 ## 92 100.52336 ## 93 100.23997 ## 94 100.24028 ## 95 99.82394 ## 96 99.78302 ## 97 100.00500 ## 98 99.97279 ## 99 99.54449 ## 100 98.79765 ## 101 100.74968 ## 102 100.63409 ## 103 98.94203 ## 104 98.91057 ## 105 98.99622 ## 106 99.95069 ## 107 98.53345 ## 108 99.92478 ## 109 99.88751 ## 110 97.98307 ## 111 99.28828 ## 112 100.90044 ## 113 99.25352 ## 114 99.63320 ## 115 99.72276 ## 116 99.50042 ## 117 99.55965 ## 118 99.59350 ## 119 98.34874 ## 120 99.06485 ## 121 98.87707 ## 122 99.89292 ## 123 100.09999 ## 124 100.76529 ## 125 100.31268 ## 126 101.11840 ## 127 100.04200 ## 128 100.74451 ## 129 99.25067 ## 130 98.71023 ## 131 99.13285 ## 132 100.25848 ## 133 100.41318 ## 134 99.73970 ## 135 98.95254 ## 136 98.83806 ## 137 101.22669 ## 138 99.65316 ## 139 99.23036 ## 140 100.30168 ## 141 100.70209 ## 142 99.60223 ## 143 101.97321 ## 144 99.66525 ## 145 98.81504 ## 146 99.83213 ## 147 100.35677 ## 148 99.92589 ## 149 98.74917 ## 150 101.92359 ## 151 101.16006 ## 152 100.25981 ## 153 98.77286 ## 154 100.41884 ## 155 99.71615 ## 156 100.11677 ## 157 98.88042 ## 158 99.66312 ## 159 99.96989 ## 160 100.73298 ## 161 100.63324 ## 162 99.29153 ## 163 100.06611 ## 164 101.14835 ## 165 100.50032 ## 166 99.38657 ## 167 100.85792 ## 168 98.83761 ## 169 99.06113 ## 170 98.24594 ## 171 100.54086 ## 172 100.38393 ## 173 99.47373 ## 174 100.64794 ## 175 99.33113 ## 176 99.43133 ## 177 99.46864 ## 178 99.67542 ## 179 99.70231 ## 180 99.58936 ## 181 101.14146 ## 182 99.90059 ## 183 99.74365 ## 184 99.37598 ## 185 99.05429 ## 186 100.66463 ## 187 99.96203 ## 188 101.24466 ## 189 100.02108 ## 190 99.10276 ## 191 101.64352 ## 192 99.97844 ## 193 101.29125 ## 194 100.36177 ## 195 99.46584 ## 196 99.95229 ## 197 99.44946 ## 198 99.42464 ## 199 100.33483 ## 200 99.31902 ## 201 100.08869 ## 202 100.32229 ## 203 99.85441 ## 204 99.80950 ## 205 100.60062 ## 206 99.10430 ## 207 99.06390 ## 208 99.45264 ## 209 99.36008 ## 210 99.92373 ## 211 99.71517 ## 212 101.08807 ## 213 100.27256 ## 214 100.31551 ## 215 100.22531 ## 216 100.09725 ## 217 99.72769 ## 218 99.77841 ## 219 100.42352 ## 220 99.39447 ## 221 100.21033 ## 222 101.68029 ## 223 101.41070 ## 224 99.47285 ## 225 100.19429 ## 226 100.06350 ## 227 99.92891 ## 228 100.51591 ## 229 99.86105 ## 230 100.27840 ## 231 99.67406 ## 232 101.17624 ## 233 100.94012 ## 234 99.84954 ## 235 100.70949 ## 236 99.80391 ## 237 99.87518 ## 238 97.30724 ## 239 102.22896 ## 240 100.33246 ## 241 99.80722 ## 242 100.13016 ## 243 99.70199 ## 244 100.17344 ## 245 99.47202 ## 246 99.26614 ## 247 99.93996 ## 248 100.08422 ## 249 100.27365 ## 250 100.68414 ## 251 98.53414 ## 252 99.61055 ## 253 98.61338 ## 254 101.31591 ## 255 98.97313 ## 256 101.28184 ## 257 101.00487 ## 258 100.02892 ## 259 100.65960 ## 260 98.94651 ## 261 98.52507 ## 262 98.74052 ## 263 99.13953 ## 264 100.02426 ## 265 100.13434 ## 266 98.82684 ## 267 102.21237 ## 268 100.57975 ## 269 100.70015 ## 270 100.82375 ## 271 99.66808 ## 272 100.42163 ## 273 100.08622 ## 274 100.09997 ## 275 100.03396 ## 276 99.20185 ## 277 99.48245 ## 278 100.36526 ## 279 100.57736 ## 280 99.47038 ## 281 101.59635 ## 282 100.98551 ## 283 99.71362 ## 284 99.43393 ## 285 102.04100 ## 286 100.27981 ## 287 98.77288 ## 288 99.68014 ## 289 100.04028 ## 290 98.91561 ## 291 99.04138 ## 292 100.59140 ## 293 99.36632 ## 294 100.51334 ## 295 99.92343 ## 296 100.12713 ## 297 99.55396 ## 298 99.30526 ## 299 102.46930 ## 300 99.66698 ## 301 99.80115 ## 302 98.93526 ## 303 100.39332 ## 304 100.46587 ## 305 100.02811 ## 306 99.43064 ## 307 99.68007 ## 308 99.54679 ## 309 99.78813 ## 310 99.69315 ## 311 99.80294 ## 312 101.61866 ## 313 99.34880 ## 314 99.76742 ## 315 100.15025 ## 316 100.78013 ## 317 99.81934 ## 318 101.15085 ## 319 101.85219 ## 320 99.56469 ## 321 99.59392 ## 322 98.44951 ## 323 99.84156 ## 324 100.65348 ## 325 100.37559 ## 326 100.39911 ## 327 101.58822 ## 328 98.77259 ## 329 99.52100 ## 330 100.70081 ## 331 99.40850 ## 332 100.20671 ## 333 100.04721 ## 334 99.99930 ## 335 99.57272 ## 336 101.20344 ## 337 99.75944 ## 338 100.02830 ## 339 100.16969 ## 340 100.82893 ## 341 98.29461 ## 342 100.08393 ## 343 99.58075 ## 344 99.43826 ## 345 98.88674 ## 346 100.00245 ## 347 100.93907 ## 348 100.99686 ## 349 98.92437 ## 350 101.19963 ## 351 99.84819 ## 352 98.28369 ## 353 101.26344 ## 354 99.31157 ## 355 99.07333 ## 356 99.97346 ## 357 100.50798 ## 358 100.67462 ## 359 98.19025 ## 360 100.14447 ## 361 98.37650 ## 362 101.05799 ## 363 100.84616 ## 364 102.10717 ## 365 100.79710 ## 366 101.85164 ## 367 101.09736 ## 368 99.31501 ## 369 101.05975 ## 370 100.53521 ## 371 101.72845 ## 372 99.16701 ## 373 100.81293 ## 374 100.90067 ## 375 98.66084 ## 376 101.06811 ## 377 101.01459 ## 378 100.39363 ## 379 99.93279 ## 380 100.61743 ## 381 99.72160 ## 382 100.29280 ## 383 101.49190 ## 384 99.84544 ## 385 100.25288 ## 386 100.15753 ## 387 99.84069 ## 388 99.91851 ## 389 100.50044 ## 390 101.06971 ## 391 98.88485 ## 392 99.10578 ## 393 101.27658 ## 394 100.72233 ## 395 99.85726 ## 396 99.65029 ## 397 99.13941 ## 398 100.40577 ## 399 100.94420 ## 400 100.25806 ## 401 99.47655 ## 402 99.20039 ## 403 99.33171 ## 404 99.84977 ## 405 99.36812 ## 406 100.21434 ## 407 99.28701 ## 408 99.59133 ## 409 101.62991 ## 410 98.89956 ## 411 98.50099 ## 412 100.23468 ## 413 101.16626 ## 414 100.44540 ## 415 99.56068 ## 416 100.34075 ## 417 99.85159 ## 418 100.22573 ## 419 101.53951 ## 420 100.94695 ## 421 100.83259 ## 422 100.84642 ## 423 99.27929 ## 424 101.84447 ## 425 100.50270 ## 426 99.99843 ## 427 100.09984 ## 428 99.65023 ## 429 99.14065 ## 430 98.90174 ## 431 99.20627 ## 432 101.10635 ## 433 101.48161 ## 434 99.83813 ## 435 99.44481 ## 436 100.91013 ## 437 99.94717 ## 438 99.99791 ## 439 99.44149 ## 440 101.03885 ## 441 100.34377 ## 442 99.81285 ## 443 100.70604 ## 444 98.93196 ## 445 99.17537 ## 446 100.10846 ## 447 100.53852 ## 448 99.92278 ## 449 101.21333 ## 450 98.59556 ## 451 98.76337 ## 452 99.36940 ## 453 100.42597 ## 454 98.30001 ## 455 99.31547 ## 456 99.17627 ## 457 98.77656 ## 458 100.93292 ## 459 99.69995 ## 460 99.98446 ## 461 99.25595 ## 462 99.91404 ## 463 100.07316 ## 464 100.69622 ## 465 100.41689 ## 466 100.49490 ## 467 99.61733 ## 468 98.56129 ## 469 100.11144 ## 470 99.84696 ## 471 99.44227 ## 472 101.22555 ## 473 100.27893 ## 474 100.12992 ## 475 100.86719 ## 476 98.66860 ## 477 99.25516 ## 478 99.60611 ## 479 100.45697 ## 480 99.63897 ## 481 99.72282 ## 482 99.56510 ## 483 100.44791 ## 484 100.12483 ## 485 98.53106 ## 486 100.74664 ## 487 99.35681 ## 488 99.75095 ## 489 98.50301 ## 490 99.32912 ## 491 101.24850 ## 492 99.57644 ## 493 100.38694 ## 494 100.64256 ## 495 100.08078 ## 496 101.79001 ## 497 100.26001 ## 498 99.31884 ## 499 100.40227 ## 500 99.50536 ``` ] --- ## Part 2 ### Visualize the different `\(\hat{y} = E[Y \mid x=5]\)` values The code on the next slide constructs a histogram of the estimates you obtained (the 500 y_hat values). **Question:** What shape do you expect this distribution to look like and why? --- ## Part 2 ### Visualize the different `\(\hat{y} = E[Y \mid x=5]\)` values .scroll-output[ ```r ggplot(y_hats, aes(x=y_hats)) + geom_histogram(bins=40) + labs(title= "Histogram of the fitted response for x=5", x = "Different y_hat values for each sample", y = "Density") ``` ![](Figs/unnamed-chunk-7-1.png)<!-- --> ] --- ## Part 3 ### For each sample, compute a `\(95\%\)` CI on the slope, `\(\beta_1\)` First, let's write a function that will compute the lower and upper bound: ```r CI.slope <- function(response,predictor=x){ mod <- lm(response ~ predictor) t_crit <- qt(0.05/2, df=20-2, lower.tail=FALSE) se_beta1 <- summary(mod)$coefficients[2,2] ##? beta1_hat <- mod$coefficients[2] LB <- beta1_hat - t_crit*se_beta1 UB <- beta1_hat + t_crit*se_beta1 return(c(LB, UB)) } ``` --- ## Part 3 ### For each sample, compute a `\(95\%\)` CI on the slope, `\(\beta_1\)` .scroll-output[ Now, let's apply the function `CI.slope` to our 500 random samples and look at all of the upper and lower bounds computed for each sample. ```r LB_slope <- rep(NA,500) UB_slope <- rep(NA, 500) for(k in 1:500){ conf_int = CI.slope(y_mtx[ ,k]) LB_slope[k] = conf_int[1] UB_slope[k] = conf_int[2] } cbind(LB_slope,UB_slope) ``` ``` ## LB_slope UB_slope ## [1,] 9.302400 10.937493 ## [2,] 9.090191 10.821262 ## [3,] 9.369978 11.090927 ## [4,] 8.929081 10.372627 ## [5,] 9.532741 10.661725 ## [6,] 9.321015 10.432377 ## [7,] 8.835243 9.694684 ## [8,] 9.496176 10.500558 ## [9,] 9.296453 10.415173 ## [10,] 9.856542 10.785564 ## [11,] 9.497740 10.901906 ## [12,] 9.188467 10.430816 ## [13,] 9.467251 10.670641 ## [14,] 9.874971 10.886805 ## [15,] 9.573143 11.174858 ## [16,] 9.285893 10.746381 ## [17,] 9.088242 10.434200 ## [18,] 9.191549 10.585889 ## [19,] 9.477789 10.720545 ## [20,] 9.309499 10.900229 ## [21,] 9.648766 10.756075 ## [22,] 9.505854 10.638289 ## [23,] 9.496494 10.801767 ## [24,] 9.882483 10.955647 ## [25,] 9.067635 10.120554 ## [26,] 8.920893 10.644949 ## [27,] 9.191285 10.197338 ## [28,] 8.901188 10.248670 ## [29,] 9.424836 10.314766 ## [30,] 9.300905 10.354119 ## [31,] 9.360735 10.714713 ## [32,] 9.688488 10.556717 ## [33,] 9.678848 10.681479 ## [34,] 9.905604 11.108053 ## [35,] 9.262047 10.643442 ## [36,] 9.733687 10.823958 ## [37,] 9.395202 10.783717 ## [38,] 9.786020 10.983241 ## [39,] 9.378943 10.607314 ## [40,] 9.243987 10.627136 ## [41,] 9.809299 10.702960 ## [42,] 8.949473 10.474697 ## [43,] 9.599396 11.107513 ## [44,] 9.496061 10.596083 ## [45,] 9.246418 10.074693 ## [46,] 9.084142 10.215889 ## [47,] 8.758796 9.778795 ## [48,] 9.664172 10.812661 ## [49,] 9.502956 11.069017 ## [50,] 9.445403 10.631421 ## [51,] 8.961382 10.397289 ## [52,] 8.872881 10.523571 ## [53,] 9.257490 10.235375 ## [54,] 9.471054 10.676109 ## [55,] 9.392268 10.766833 ## [56,] 9.671239 10.944352 ## [57,] 9.046786 10.130001 ## [58,] 10.010804 11.079326 ## [59,] 8.663206 10.050137 ## [60,] 8.737919 9.958200 ## [61,] 9.683495 10.791568 ## [62,] 9.756649 10.671037 ## [63,] 9.325853 10.373573 ## [64,] 9.416082 10.564980 ## [65,] 9.495596 11.064016 ## [66,] 9.542590 10.827684 ## [67,] 9.871843 11.195332 ## [68,] 9.439544 10.875898 ## [69,] 8.576462 10.313714 ## [70,] 9.637745 10.734713 ## [71,] 9.398227 10.767408 ## [72,] 9.277065 11.202820 ## [73,] 8.885334 10.139788 ## [74,] 9.199641 10.572100 ## [75,] 9.925876 10.789190 ## [76,] 8.883254 10.446678 ## [77,] 8.965387 10.200281 ## [78,] 9.251279 10.651485 ## [79,] 9.011624 10.308101 ## [80,] 9.594273 10.729031 ## [81,] 9.957951 11.144537 ## [82,] 9.565175 10.908561 ## [83,] 9.918829 11.022784 ## [84,] 9.505733 10.848135 ## [85,] 8.856028 10.025009 ## [86,] 9.485335 10.994371 ## [87,] 9.053691 10.451400 ## [88,] 9.298033 10.668932 ## [89,] 9.188851 10.863246 ## [90,] 9.833540 10.877323 ## [91,] 9.412033 10.814155 ## [92,] 9.029417 10.605326 ## [93,] 9.457710 10.546135 ## [94,] 9.051827 10.307022 ## [95,] 9.747316 10.753469 ## [96,] 9.542376 10.821575 ## [97,] 9.005432 10.279401 ## [98,] 9.106395 10.242137 ## [99,] 9.663249 10.893027 ## [100,] 9.469178 10.790833 ## [101,] 9.594190 10.882588 ## [102,] 9.327156 10.654595 ## [103,] 9.459254 10.645185 ## [104,] 9.474622 11.262653 ## [105,] 9.416809 10.576474 ## [106,] 9.657767 10.674493 ## [107,] 9.278006 10.764237 ## [108,] 9.443898 10.896710 ## [109,] 8.753407 10.130281 ## [110,] 9.401390 10.762763 ## [111,] 9.376735 11.183381 ## [112,] 9.272629 10.735264 ## [113,] 9.383913 10.296567 ## [114,] 9.287485 10.953785 ## [115,] 9.564058 10.783963 ## [116,] 9.159214 10.699293 ## [117,] 9.319378 10.686636 ## [118,] 8.916575 10.099133 ## [119,] 8.935396 10.521182 ## [120,] 9.083934 10.175965 ## [121,] 8.963743 10.224729 ## [122,] 9.844693 10.944609 ## [123,] 9.246960 10.528684 ## [124,] 9.605918 10.530685 ## [125,] 9.643745 10.881156 ## [126,] 9.803065 11.142356 ## [127,] 9.827585 11.153915 ## [128,] 8.527383 10.251351 ## [129,] 9.585128 10.510551 ## [130,] 8.973047 10.108041 ## [131,] 9.369880 10.475642 ## [132,] 9.962563 11.079836 ## [133,] 9.473474 10.470389 ## [134,] 9.920494 11.202781 ## [135,] 9.059731 10.568177 ## [136,] 9.449230 10.499242 ## [137,] 9.355574 10.334476 ## [138,] 9.819805 11.248600 ## [139,] 9.625334 10.744008 ## [140,] 9.609408 10.637956 ## [141,] 8.739986 10.300526 ## [142,] 9.378423 10.881465 ## [143,] 9.642619 10.751646 ## [144,] 9.098553 10.287803 ## [145,] 9.613800 11.218441 ## [146,] 9.388273 10.697931 ## [147,] 9.395021 10.678878 ## [148,] 8.917901 10.387517 ## [149,] 9.761534 11.134933 ## [150,] 9.154046 10.355840 ## [151,] 9.469200 10.752512 ## [152,] 9.759899 11.135795 ## [153,] 9.892733 11.368027 ## [154,] 8.853064 9.837485 ## [155,] 9.744040 11.204242 ## [156,] 9.172715 10.676635 ## [157,] 9.446325 10.383818 ## [158,] 9.697568 10.758503 ## [159,] 9.499904 10.654741 ## [160,] 9.389753 10.524792 ## [161,] 9.377932 10.930323 ## [162,] 9.523916 10.864779 ## [163,] 9.760845 10.914089 ## [164,] 9.751476 10.775228 ## [165,] 9.256153 10.513933 ## [166,] 9.042658 10.580059 ## [167,] 9.212548 10.427647 ## [168,] 9.328762 10.878423 ## [169,] 9.372994 10.298804 ## [170,] 9.648530 11.151988 ## [171,] 9.237166 10.162885 ## [172,] 9.152344 10.462364 ## [173,] 9.197333 10.379610 ## [174,] 9.224587 10.800445 ## [175,] 9.670735 11.147406 ## [176,] 9.457893 10.682143 ## [177,] 9.115486 10.040600 ## [178,] 9.573858 10.881185 ## [179,] 9.291231 10.458124 ## [180,] 9.363760 11.030440 ## [181,] 9.291570 10.459887 ## [182,] 9.757333 10.941484 ## [183,] 9.400744 10.535357 ## [184,] 9.404183 10.499727 ## [185,] 9.187545 10.405924 ## [186,] 8.867517 10.288027 ## [187,] 9.351252 10.619195 ## [188,] 9.841958 11.066235 ## [189,] 9.617887 10.988484 ## [190,] 9.843488 10.713961 ## [191,] 9.559903 10.580591 ## [192,] 9.334681 10.828481 ## [193,] 9.593846 10.870746 ## [194,] 9.561895 10.843058 ## [195,] 9.626093 10.965465 ## [196,] 8.714277 9.971360 ## [197,] 9.413989 10.696883 ## [198,] 9.367657 10.702479 ## [199,] 9.277046 10.415211 ## [200,] 8.926829 10.507608 ## [201,] 9.914321 11.060248 ## [202,] 9.351873 10.793513 ## [203,] 9.383613 10.664612 ## [204,] 9.672235 11.147225 ## [205,] 9.140913 10.453696 ## [206,] 10.031886 11.284292 ## [207,] 9.560738 10.780301 ## [208,] 9.664699 10.710687 ## [209,] 9.852429 11.147121 ## [210,] 9.004352 10.105977 ## [211,] 9.726369 11.044356 ## [212,] 9.536746 10.313609 ## [213,] 9.249019 10.671026 ## [214,] 8.801502 10.208479 ## [215,] 9.147948 10.859285 ## [216,] 9.153016 10.329002 ## [217,] 8.925434 10.208999 ## [218,] 9.185338 10.353824 ## [219,] 9.656128 10.894361 ## [220,] 9.277114 10.494953 ## [221,] 9.129885 10.561459 ## [222,] 8.673712 10.107465 ## [223,] 8.903198 10.047043 ## [224,] 9.326069 10.664875 ## [225,] 9.097833 10.325456 ## [226,] 9.292839 10.683031 ## [227,] 9.138017 10.577781 ## [228,] 9.183856 10.401961 ## [229,] 9.489903 10.666049 ## [230,] 9.373713 10.630797 ## [231,] 9.709300 10.823577 ## [232,] 9.512235 10.520367 ## [233,] 9.564959 10.534655 ## [234,] 9.384695 11.156586 ## [235,] 9.699836 10.778376 ## [236,] 9.007376 10.388060 ## [237,] 9.079122 10.385111 ## [238,] 8.927203 10.083538 ## [239,] 8.630671 9.977058 ## [240,] 9.311916 10.435597 ## [241,] 9.126669 10.545870 ## [242,] 9.345856 10.713822 ## [243,] 9.883727 11.351348 ## [244,] 9.256360 10.288081 ## [245,] 9.305587 10.534479 ## [246,] 9.168944 10.513206 ## [247,] 8.906804 10.071210 ## [248,] 9.531466 10.378137 ## [249,] 9.445351 10.573652 ## [250,] 9.310539 10.521979 ## [251,] 9.743265 10.926888 ## [252,] 9.184011 10.718661 ## [253,] 9.699548 10.943575 ## [254,] 9.403538 10.399713 ## [255,] 8.992898 10.213898 ## [256,] 9.660391 10.832554 ## [257,] 9.327096 10.522560 ## [258,] 8.844403 10.243646 ## [259,] 9.922646 10.873772 ## [260,] 9.800864 11.462996 ## [261,] 8.917276 10.498366 ## [262,] 9.759572 10.909354 ## [263,] 9.359525 10.778589 ## [264,] 9.740532 11.122150 ## [265,] 9.476450 10.376815 ## [266,] 9.628742 10.610667 ## [267,] 9.250145 10.420422 ## [268,] 9.234858 10.426900 ## [269,] 9.183505 10.549015 ## [270,] 9.770007 10.949679 ## [271,] 8.986042 10.562434 ## [272,] 9.501335 10.923497 ## [273,] 9.657903 10.668861 ## [274,] 9.517202 10.697747 ## [275,] 8.939260 10.356097 ## [276,] 8.881544 10.336044 ## [277,] 9.079383 10.486396 ## [278,] 9.135542 10.450728 ## [279,] 9.946574 11.200951 ## [280,] 9.396848 10.627600 ## [281,] 9.707105 11.563105 ## [282,] 9.031820 10.494540 ## [283,] 9.660958 10.854365 ## [284,] 8.893090 9.954355 ## [285,] 9.024747 10.035119 ## [286,] 9.519234 10.587478 ## [287,] 9.256586 10.644885 ## [288,] 9.287333 10.502816 ## [289,] 8.971526 10.188242 ## [290,] 9.526960 10.835177 ## [291,] 9.181355 10.925291 ## [292,] 9.719654 10.844237 ## [293,] 9.003211 10.514633 ## [294,] 9.334515 10.571504 ## [295,] 9.751206 11.359566 ## [296,] 9.390196 10.921682 ## [297,] 9.128138 10.632777 ## [298,] 9.181005 10.775652 ## [299,] 9.158983 10.519227 ## [300,] 9.162786 10.600593 ## [301,] 9.153361 11.088522 ## [302,] 9.356698 11.130095 ## [303,] 9.596408 10.800704 ## [304,] 9.188791 10.190040 ## [305,] 9.498720 10.801086 ## [306,] 8.964962 10.573427 ## [307,] 9.730381 10.708646 ## [308,] 9.244382 10.440461 ## [309,] 9.197348 10.368255 ## [310,] 10.096998 11.689628 ## [311,] 9.683331 10.801794 ## [312,] 9.194416 10.195517 ## [313,] 9.678249 11.158323 ## [314,] 9.001487 10.468263 ## [315,] 9.119801 10.420601 ## [316,] 9.226921 10.350845 ## [317,] 9.420937 10.263812 ## [318,] 9.307937 10.598115 ## [319,] 9.428691 10.565458 ## [320,] 10.585228 11.483348 ## [321,] 9.174678 10.336266 ## [322,] 9.422246 11.378780 ## [323,] 9.671867 10.947153 ## [324,] 9.517859 10.368595 ## [325,] 9.511535 11.138265 ## [326,] 9.080506 10.454815 ## [327,] 9.188532 10.514135 ## [328,] 8.808277 10.383806 ## [329,] 9.586803 10.697027 ## [330,] 8.870853 10.458010 ## [331,] 9.188450 9.971234 ## [332,] 9.778315 11.303348 ## [333,] 9.864063 11.090454 ## [334,] 8.983058 10.460870 ## [335,] 9.138374 10.561508 ## [336,] 8.773618 10.261231 ## [337,] 9.376745 10.842071 ## [338,] 8.698853 10.171665 ## [339,] 9.496092 10.567551 ## [340,] 9.175500 10.058916 ## [341,] 8.818500 10.082862 ## [342,] 9.472576 10.977803 ## [343,] 9.822420 11.058048 ## [344,] 9.061577 10.696322 ## [345,] 9.162370 10.581522 ## [346,] 9.013666 10.558610 ## [347,] 9.437109 11.072273 ## [348,] 9.797921 10.681845 ## [349,] 9.207741 10.560705 ## [350,] 8.863068 10.301589 ## [351,] 9.164099 10.799554 ## [352,] 8.861598 10.272268 ## [353,] 8.930934 10.320546 ## [354,] 8.892169 10.205956 ## [355,] 9.361792 10.377585 ## [356,] 9.573804 11.105710 ## [357,] 8.843442 10.162216 ## [358,] 9.445273 10.752203 ## [359,] 10.183980 10.965766 ## [360,] 9.289405 10.401864 ## [361,] 9.358864 10.688593 ## [362,] 9.601130 11.212140 ## [363,] 9.225112 10.490093 ## [364,] 9.146186 10.521653 ## [365,] 9.536609 10.520645 ## [366,] 8.958909 10.087816 ## [367,] 9.139645 10.670432 ## [368,] 8.924645 10.206846 ## [369,] 9.454953 10.634140 ## [370,] 9.408917 10.645309 ## [371,] 9.329138 10.551658 ## [372,] 9.401266 10.810582 ## [373,] 8.917677 10.235566 ## [374,] 9.369890 10.591737 ## [375,] 8.271190 9.991477 ## [376,] 9.153246 10.474082 ## [377,] 9.410849 10.872981 ## [378,] 8.883953 10.324743 ## [379,] 9.038633 10.341736 ## [380,] 9.056593 10.216019 ## [381,] 9.276338 10.702662 ## [382,] 9.454574 10.757382 ## [383,] 9.280669 10.759099 ## [384,] 9.764351 11.092836 ## [385,] 9.514613 10.718025 ## [386,] 9.196399 10.535344 ## [387,] 9.400233 10.714628 ## [388,] 9.092379 10.765304 ## [389,] 9.486967 10.509639 ## [390,] 9.107986 10.347328 ## [391,] 9.540017 10.654265 ## [392,] 8.543005 10.273748 ## [393,] 9.358329 10.504161 ## [394,] 9.194863 10.322356 ## [395,] 9.814722 10.974506 ## [396,] 9.464691 10.692232 ## [397,] 9.017654 10.619238 ## [398,] 9.199777 10.642496 ## [399,] 9.362390 10.540916 ## [400,] 9.365576 10.319631 ## [401,] 9.900939 11.151157 ## [402,] 9.107813 10.426022 ## [403,] 9.670712 10.745573 ## [404,] 8.848089 10.425052 ## [405,] 9.645138 11.035384 ## [406,] 9.631000 10.743998 ## [407,] 9.592813 10.601705 ## [408,] 9.440731 10.356753 ## [409,] 9.802310 11.407363 ## [410,] 9.460562 10.579193 ## [411,] 9.443373 10.952227 ## [412,] 9.072398 10.456826 ## [413,] 9.289259 10.459940 ## [414,] 9.113980 10.439363 ## [415,] 9.625515 10.694545 ## [416,] 8.439064 10.228994 ## [417,] 9.348726 11.164810 ## [418,] 9.432259 10.824007 ## [419,] 9.223498 10.618823 ## [420,] 9.294103 10.672649 ## [421,] 9.049627 10.360532 ## [422,] 9.489035 10.821022 ## [423,] 9.778436 10.908012 ## [424,] 8.586907 9.722700 ## [425,] 9.425472 10.551134 ## [426,] 9.087184 10.452819 ## [427,] 9.007619 10.261908 ## [428,] 9.156719 10.618654 ## [429,] 9.551652 10.688137 ## [430,] 9.574591 10.721604 ## [431,] 9.170236 10.552867 ## [432,] 9.449854 10.982916 ## [433,] 9.282496 10.619863 ## [434,] 9.041663 10.257528 ## [435,] 8.766455 9.936664 ## [436,] 9.337404 10.374766 ## [437,] 9.139618 10.576020 ## [438,] 9.328341 10.843422 ## [439,] 8.974138 10.068091 ## [440,] 9.304340 10.725661 ## [441,] 9.300138 10.582987 ## [442,] 9.415653 11.018644 ## [443,] 9.507265 10.769788 ## [444,] 9.409729 10.410577 ## [445,] 9.444931 10.693348 ## [446,] 10.039315 11.118749 ## [447,] 8.868029 9.975291 ## [448,] 8.955313 10.256358 ## [449,] 9.681594 11.277511 ## [450,] 9.210022 10.270306 ## [451,] 9.069067 10.338553 ## [452,] 9.271274 10.568207 ## [453,] 9.331366 11.029371 ## [454,] 9.583195 10.663007 ## [455,] 9.157532 10.480843 ## [456,] 9.719831 10.758195 ## [457,] 9.270820 10.854170 ## [458,] 9.364862 10.679119 ## [459,] 9.862109 10.678614 ## [460,] 8.927695 10.348098 ## [461,] 9.422484 10.842010 ## [462,] 9.776008 11.128393 ## [463,] 9.108221 10.389905 ## [464,] 9.315609 10.220271 ## [465,] 8.802007 10.341285 ## [466,] 8.871238 10.019764 ## [467,] 9.093968 10.317073 ## [468,] 9.220990 10.929616 ## [469,] 9.018962 10.573911 ## [470,] 9.515299 10.746596 ## [471,] 9.358897 10.763868 ## [472,] 9.658908 10.691376 ## [473,] 9.117510 10.709644 ## [474,] 8.667203 9.948541 ## [475,] 9.208341 10.493019 ## [476,] 9.421141 10.394715 ## [477,] 9.780571 10.927738 ## [478,] 9.516212 10.755886 ## [479,] 8.872642 10.273215 ## [480,] 9.898501 10.995421 ## [481,] 9.652577 10.756167 ## [482,] 8.565628 10.364677 ## [483,] 9.301127 11.043996 ## [484,] 9.482842 11.000293 ## [485,] 8.982203 10.218697 ## [486,] 8.903267 10.314521 ## [487,] 9.502045 10.645818 ## [488,] 9.295303 10.416801 ## [489,] 9.332713 10.840256 ## [490,] 9.192108 10.669156 ## [491,] 9.689540 10.877787 ## [492,] 9.220866 10.536519 ## [493,] 9.331361 10.575371 ## [494,] 9.439429 10.651876 ## [495,] 9.642659 11.125151 ## [496,] 8.916280 10.105921 ## [497,] 9.516781 10.861131 ## [498,] 9.763264 11.091264 ## [499,] 9.647925 10.843531 ## [500,] 9.038342 10.672637 ``` ] --- ## Part 3 ### For each sample, compute a `\(95\%\)` CI on the slope, `\(\beta_1\)` **Question:** How many of these 500 intervals would you expect contain the true value of `\(\beta_1=10\)`? -- .scroll-small[ ```r ((LB_slope<=10)&(UB_slope>=10)) ``` ``` ## [1] TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE ## [13] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [25] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [37] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE ## [49] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE FALSE ## [61] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [73] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [85] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [97] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [109] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [121] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [133] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [145] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE ## [157] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [169] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [181] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [193] TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [205] TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [217] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [229] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE ## [241] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [253] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [265] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [277] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE ## [289] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [301] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE ## [313] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE ## [325] TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE ## [337] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [349] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE ## [361] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [373] TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [385] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [397] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [409] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [421] TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [433] TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [445] TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [457] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [469] TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE ## [481] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ## [493] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE ``` ] --- ## Part 3 ### For each sample, compute a `\(95\%\)` CI on the slope, `\(\beta_1\)` **Question:** How many of these 500 intervals would you expect contain the true value of `\(\beta_1=10\)`? ```r sum((LB_slope<=10)&(UB_slope>=10)) ``` ``` ## [1] 481 ``` --- ## Part 4 ### For each estimate of `\(E[Y \mid x=5]\)` in part 2, compute the `\(95\%\)` CI for the mean response As before, let's write a function that will compute the lower and upper bound: ```r CI.mean.response <- function(response,predictor=x){ dat <- data.frame(response, predictor) remove(list=c("response","predictor")) mod <- lm(response ~ predictor, dat) y_hat <- data.frame(response = mod$coefficients[1] + mod$coefficients[2]*5, predictor=5) PI <- predict(mod, y_hat, interval="confidence", level = 0.95) return(c(PI[2], PI[3])) } ``` --- ## Part 4 ### For each estimate of `\(E[Y \mid x=5]\)` in part 2, compute the `\(95\%\)` CI for the mean response .scroll-output[ Now, let's apply the function `CI.mean.response` to our 500 random samples and look at all of the upper and lower bounds computed for each sample. ```r LB_mean_response <- rep(NA,500) UB_mean_response <- rep(NA, 500) for(k in 1:500){ conf_int = CI.mean.response(y_mtx[ ,k]) LB_mean_response[k] = conf_int[1] UB_mean_response[k] = conf_int[2] } cbind(LB_mean_response,UB_mean_response) ``` ``` ## LB_mean_response UB_mean_response ## [1,] 97.59403 102.32593 ## [2,] 97.77526 102.78491 ## [3,] 97.71926 102.69962 ## [4,] 98.01567 102.19323 ## [5,] 97.78193 101.04917 ## [6,] 97.72095 100.93719 ## [7,] 99.59378 102.08097 ## [8,] 98.81504 101.72168 ## [9,] 97.55133 100.78886 ## [10,] 99.34285 102.03140 ## [11,] 99.51633 103.57993 ## [12,] 98.24566 101.84097 ## [13,] 98.68299 102.16555 ## [14,] 98.10268 101.03089 ## [15,] 95.96523 100.60053 ## [16,] 97.11652 101.34311 ## [17,] 97.33942 101.23457 ## [18,] 99.25532 103.29048 ## [19,] 99.02426 102.62074 ## [20,] 97.81172 102.41523 ## [21,] 97.29431 100.49882 ## [22,] 97.02190 100.29912 ## [23,] 97.17998 100.95739 ## [24,] 100.34476 103.45046 ## [25,] 98.83924 101.88635 ## [26,] 97.55032 102.53967 ## [27,] 98.70590 101.61737 ## [28,] 97.65088 101.55044 ## [29,] 98.46254 101.03796 ## [30,] 96.52135 99.56931 ## [31,] 98.18535 102.10371 ## [32,] 99.49201 102.00463 ## [33,] 97.64470 100.54627 ## [34,] 100.25214 103.73197 ## [35,] 97.96274 101.96044 ## [36,] 99.33564 102.49084 ## [37,] 99.38431 103.40262 ## [38,] 97.76433 101.22903 ## [39,] 96.22823 99.78309 ## [40,] 98.45849 102.46127 ## [41,] 99.05260 101.63882 ## [42,] 97.42055 101.83449 ## [43,] 97.36343 101.72786 ## [44,] 100.11399 103.29740 ## [45,] 99.47273 101.86972 ## [46,] 97.88784 101.16307 ## [47,] 99.62306 102.57490 ## [48,] 99.04509 102.36877 ## [49,] 98.48794 103.02006 ## [50,] 99.07874 102.51102 ## [51,] 97.34796 101.50342 ## [52,] 98.91053 103.68755 ## [53,] 101.03989 103.86985 ## [54,] 97.92118 101.40856 ## [55,] 96.98116 100.95909 ## [56,] 98.01870 101.70304 ## [57,] 98.72101 101.85579 ## [58,] 98.00421 101.09647 ## [59,] 98.74585 102.75957 ## [60,] 98.17111 101.70255 ## [61,] 96.85034 100.05706 ## [62,] 98.64236 101.28857 ## [63,] 98.48600 101.51806 ## [64,] 96.72221 100.04707 ## [65,] 97.48283 102.02177 ## [66,] 97.80905 101.52806 ## [67,] 98.59052 102.42064 ## [68,] 96.62794 100.78469 ## [69,] 98.16692 103.19445 ## [70,] 98.74735 101.92193 ## [71,] 98.47439 102.43675 ## [72,] 97.80507 103.37813 ## [73,] 98.08945 101.71979 ## [74,] 97.59548 101.56732 ## [75,] 99.27575 101.77415 ## [76,] 98.78832 103.31280 ## [77,] 98.03923 101.61297 ## [78,] 97.75492 101.80706 ## [79,] 96.73821 100.49016 ## [80,] 98.04057 101.32452 ## [81,] 100.14953 103.58346 ## [82,] 97.52403 101.41174 ## [83,] 98.78551 101.98031 ## [84,] 99.96627 103.85113 ## [85,] 98.08288 101.46587 ## [86,] 98.07201 102.43910 ## [87,] 98.23314 102.27805 ## [88,] 97.43116 101.39848 ## [89,] 96.98505 101.83068 ## [90,] 98.10350 101.12417 ## [91,] 97.07808 101.13576 ## [92,] 98.24305 102.80367 ## [93,] 98.66504 101.81490 ## [94,] 98.42403 102.05652 ## [95,] 98.36806 101.27982 ## [96,] 97.93204 101.63399 ## [97,] 98.16159 101.84841 ## [98,] 98.32940 101.61619 ## [99,] 97.76503 101.32396 ## [100,] 96.88525 100.71006 ## [101,] 98.88540 102.61397 ## [102,] 98.71331 102.55487 ## [103,] 97.22602 100.65805 ## [104,] 96.32333 101.49782 ## [105,] 97.31821 100.67423 ## [106,] 98.47951 101.42187 ## [107,] 96.38290 100.68400 ## [108,] 97.82259 102.02697 ## [109,] 97.89520 101.87982 ## [110,] 96.01319 99.95295 ## [111,] 96.67410 101.90246 ## [112,] 98.78404 103.01685 ## [113,] 97.93293 100.57411 ## [114,] 97.22210 102.04431 ## [115,] 97.95759 101.48794 ## [116,] 97.27196 101.72889 ## [117,] 97.58126 101.53805 ## [118,] 97.88236 101.30464 ## [119,] 96.05414 100.64334 ## [120,] 97.48471 100.64500 ## [121,] 97.05245 100.70169 ## [122,] 98.30137 101.48448 ## [123,] 98.24537 101.95462 ## [124,] 99.42717 102.10341 ## [125,] 98.52217 102.10319 ## [126,] 99.18047 103.05633 ## [127,] 98.12282 101.96117 ## [128,] 98.24997 103.23906 ## [129,] 97.91161 100.58974 ## [130,] 97.06792 100.35254 ## [131,] 97.53284 100.73287 ## [132,] 98.64181 101.87515 ## [133,] 98.97067 101.85570 ## [134,] 97.88426 101.59515 ## [135,] 96.76985 101.13523 ## [136,] 97.31872 100.35741 ## [137,] 99.81024 102.64314 ## [138,] 97.58572 101.72060 ## [139,] 97.61166 100.84906 ## [140,] 98.81339 101.78997 ## [141,] 98.44402 102.96016 ## [142,] 97.42736 101.77710 ## [143,] 100.36847 103.57794 ## [144,] 97.94443 101.38607 ## [145,] 96.49315 101.13692 ## [146,] 97.93708 101.72718 ## [147,] 98.49905 102.21448 ## [148,] 97.79938 102.05239 ## [149,] 96.76189 100.73645 ## [150,] 100.18462 103.66256 ## [151,] 99.30314 103.01699 ## [152,] 98.26891 102.25070 ## [153,] 96.63814 100.90758 ## [154,] 98.99440 101.84327 ## [155,] 97.60326 101.82903 ## [156,] 97.94063 102.29291 ## [157,] 97.52389 100.23695 ## [158,] 98.12797 101.19827 ## [159,] 98.29886 101.64092 ## [160,] 99.09060 102.37536 ## [161,] 98.38696 102.87952 ## [162,] 97.35133 101.23173 ## [163,] 98.39739 101.73483 ## [164,] 99.66700 102.62970 ## [165,] 98.68034 102.32030 ## [166,] 97.16198 101.61116 ## [167,] 99.09970 102.61614 ## [168,] 96.59528 101.07993 ## [169,] 97.72150 100.40076 ## [170,] 96.07047 100.42142 ## [171,] 99.20136 101.88035 ## [172,] 98.48836 102.27951 ## [173,] 97.76300 101.18446 ## [174,] 98.36771 102.92818 ## [175,] 97.19442 101.46784 ## [176,] 97.65987 101.20280 ## [177,] 98.13002 100.80726 ## [178,] 97.78375 101.56710 ## [179,] 98.01384 101.39078 ## [180,] 97.17770 102.00101 ## [181,] 99.45093 102.83199 ## [182,] 98.18715 101.61403 ## [183,] 98.10189 101.38541 ## [184,] 97.79076 100.96121 ## [185,] 97.29131 100.81726 ## [186,] 98.60918 102.72008 ## [187,] 98.12735 101.79672 ## [188,] 99.47315 103.01616 ## [189,] 98.03785 102.00430 ## [190,] 97.84320 100.36232 ## [191,] 100.16660 103.12043 ## [192,] 97.81694 102.13994 ## [193,] 99.44360 103.13890 ## [194,] 98.50795 102.21559 ## [195,] 97.52779 101.40388 ## [196,] 98.13332 101.77126 ## [197,] 97.59314 101.30578 ## [198,] 97.49318 101.35610 ## [199,] 98.68793 101.98173 ## [200,] 97.03166 101.60637 ## [201,] 98.43056 101.74683 ## [202,] 98.23627 102.40831 ## [203,] 98.00083 101.70799 ## [204,] 97.67522 101.94378 ## [205,] 98.70105 102.50019 ## [206,] 97.29210 100.91651 ## [207,] 97.29921 100.82858 ## [208,] 97.93912 100.96616 ## [209,] 97.48669 101.23347 ## [210,] 98.32970 101.51776 ## [211,] 97.80807 101.62227 ## [212,] 99.96396 102.21217 ## [213,] 98.21494 102.33017 ## [214,] 98.27965 102.35138 ## [215,] 97.74904 102.70158 ## [216,] 98.39562 101.79888 ## [217,] 97.87039 101.58498 ## [218,] 98.08763 101.46919 ## [219,] 98.63182 102.21521 ## [220,] 97.63228 101.15666 ## [221,] 98.13887 102.28179 ## [222,] 99.60568 103.75490 ## [223,] 99.75558 103.06582 ## [224,] 97.53562 101.41007 ## [225,] 98.41794 101.97063 ## [226,] 98.05192 102.07508 ## [227,] 97.84560 102.01222 ## [228,] 98.75334 102.27848 ## [229,] 98.15919 101.56291 ## [230,] 98.45942 102.09737 ## [231,] 98.06172 101.28639 ## [232,] 99.71749 102.63498 ## [233,] 99.53699 102.34325 ## [234,] 97.28565 102.41343 ## [235,] 99.14887 102.27012 ## [236,] 97.80609 101.80173 ## [237,] 97.98544 101.76492 ## [238,] 95.63405 98.98043 ## [239,] 100.28076 104.17715 ## [240,] 98.70651 101.95840 ## [241,] 97.75366 101.86077 ## [242,] 98.15075 102.10958 ## [243,] 97.57837 101.82561 ## [244,] 98.68056 101.66632 ## [245,] 97.69384 101.25020 ## [246,] 97.32102 101.21126 ## [247,] 98.25509 101.62483 ## [248,] 98.85910 101.30933 ## [249,] 98.64102 101.90628 ## [250,] 98.93121 102.43707 ## [251,] 96.82147 100.24682 ## [252,] 97.38994 101.83116 ## [253,] 96.81330 100.41346 ## [254,] 99.87446 102.75735 ## [255,] 97.20637 100.73990 ## [256,] 99.58574 102.97794 ## [257,] 99.27506 102.73468 ## [258,] 98.00424 102.05360 ## [259,] 99.28334 102.03586 ## [260,] 96.54144 101.35158 ## [261,] 96.23726 100.81287 ## [262,] 97.07681 100.40423 ## [263,] 97.08618 101.19289 ## [264,] 98.02508 102.02343 ## [265,] 98.83153 101.43715 ## [266,] 97.40602 100.24767 ## [267,] 100.51900 103.90574 ## [268,] 98.85489 102.30461 ## [269,] 98.72428 102.67601 ## [270,] 99.11679 102.53071 ## [271,] 97.38708 101.94909 ## [272,] 98.36379 102.47946 ## [273,] 98.62338 101.54905 ## [274,] 98.39175 101.80819 ## [275,] 97.98382 102.08409 ## [276,] 97.09722 101.30648 ## [277,] 97.44653 101.51837 ## [278,] 98.46221 102.26831 ## [279,] 98.76230 102.39242 ## [280,] 97.68951 101.25126 ## [281,] 98.91075 104.28194 ## [282,] 98.86898 103.10203 ## [283,] 97.98678 101.44046 ## [284,] 97.89830 100.96956 ## [285,] 100.57901 103.50298 ## [286,] 98.73408 101.82553 ## [287,] 96.76403 100.78172 ## [288,] 97.92136 101.43892 ## [289,] 98.27971 101.80084 ## [290,] 97.02265 100.80858 ## [291,] 96.51795 101.56482 ## [292,] 98.96415 102.21865 ## [293,] 97.17932 101.55331 ## [294,] 98.72345 102.30324 ## [295,] 97.59617 102.25070 ## [296,] 97.91110 102.34316 ## [297,] 97.37678 101.73115 ## [298,] 96.99783 101.61268 ## [299,] 100.50105 104.43754 ## [300,] 97.58650 101.74745 ## [301,] 97.00101 102.60129 ## [302,] 96.36919 101.50133 ## [303,] 98.65073 102.13591 ## [304,] 99.01709 101.91466 ## [305,] 98.14361 101.91260 ## [306,] 97.10323 101.75806 ## [307,] 98.26454 101.09560 ## [308,] 97.81609 101.27749 ## [309,] 98.09385 101.48241 ## [310,] 97.38864 101.99765 ## [311,] 98.18455 101.42133 ## [312,] 100.17009 103.06723 ## [313,] 97.20717 101.49044 ## [314,] 97.64502 101.88981 ## [315,] 98.26802 102.03249 ## [316,] 99.15383 102.40642 ## [317,] 98.59971 101.03896 ## [318,] 99.28399 103.01771 ## [319,] 100.20731 103.49707 ## [320,] 98.26513 100.86425 ## [321,] 97.91313 101.27472 ## [322,] 95.61845 101.28058 ## [323,] 97.99625 101.68687 ## [324,] 99.42248 101.88447 ## [325,] 98.02175 102.72944 ## [326,] 98.41052 102.38771 ## [327,] 99.67010 103.50634 ## [328,] 96.49284 101.05235 ## [329,] 97.91453 101.12747 ## [330,] 98.40423 102.99740 ## [331,] 98.27582 100.54117 ## [332,] 98.00001 102.41340 ## [333,] 98.27265 101.82178 ## [334,] 97.86094 102.13767 ## [335,] 97.51348 101.63197 ## [336,] 99.05089 103.35599 ## [337,] 97.63914 101.87974 ## [338,] 97.89718 102.15943 ## [339,] 98.61931 101.72007 ## [340,] 99.55064 102.10721 ## [341,] 96.46510 100.12411 ## [342,] 97.90590 102.26197 ## [343,] 97.79282 101.36867 ## [344,] 97.07281 101.80370 ## [345,] 96.83325 100.94022 ## [346,] 97.76695 102.23795 ## [347,] 98.57302 103.30512 ## [348,] 99.71784 102.27588 ## [349,] 96.96666 100.88208 ## [350,] 99.11812 103.28114 ## [351,] 97.48172 102.21466 ## [352,] 96.24248 100.32490 ## [353,] 99.25270 103.27418 ## [354,] 97.41054 101.21259 ## [355,] 97.60350 100.54316 ## [356,] 97.75682 102.19010 ## [357,] 98.59974 102.41622 ## [358,] 98.78352 102.56572 ## [359,] 97.05902 99.32148 ## [360,] 98.53476 101.75417 ## [361,] 96.45242 100.30059 ## [362,] 98.72689 103.38909 ## [363,] 99.01576 102.67656 ## [364,] 100.11690 104.09744 ## [365,] 99.37322 102.22098 ## [366,] 100.21814 103.48514 ## [367,] 98.88234 103.31237 ## [368,] 97.45969 101.17033 ## [369,] 99.35349 102.76601 ## [370,] 98.74618 102.32425 ## [371,] 99.95949 103.49741 ## [372,] 97.12776 101.20626 ## [373,] 98.90597 102.71989 ## [374,] 99.13268 102.66866 ## [375,] 96.17162 101.15006 ## [376,] 99.15689 102.97933 ## [377,] 98.89891 103.13026 ## [378,] 98.30883 102.47842 ## [379,] 98.04722 101.81835 ## [380,] 98.93976 102.29510 ## [381,] 97.65773 101.78546 ## [382,] 98.40766 102.17794 ## [383,] 99.35264 103.63116 ## [384,] 97.92315 101.76773 ## [385,] 98.51157 101.99420 ## [386,] 98.22010 102.09496 ## [387,] 97.93879 101.74260 ## [388,] 97.49782 102.33920 ## [389,] 99.02065 101.98022 ## [390,] 99.27641 102.86301 ## [391,] 97.27256 100.49714 ## [392,] 96.60143 101.61013 ## [393,] 99.61858 102.93457 ## [394,] 99.09088 102.35379 ## [395,] 98.17907 101.53544 ## [396,] 97.87406 101.42652 ## [397,] 96.82195 101.45687 ## [398,] 98.31819 102.49336 ## [399,] 99.23890 102.64951 ## [400,] 98.87756 101.63855 ## [401,] 97.66751 101.28559 ## [402,] 97.29297 101.10782 ## [403,] 97.77641 100.88701 ## [404,] 97.56794 102.13160 ## [405,] 97.35647 101.37978 ## [406,] 98.60386 101.82483 ## [407,] 97.82716 100.74685 ## [408,] 98.26587 100.91680 ## [409,] 99.30743 103.95238 ## [410,] 97.28092 100.51819 ## [411,] 96.31771 100.68427 ## [412,] 98.23145 102.23792 ## [413,] 99.47231 102.86021 ## [414,] 98.52760 102.36320 ## [415,] 98.01381 101.10754 ## [416,] 97.75076 102.93074 ## [417,] 97.22375 102.47943 ## [418,] 98.21190 102.23956 ## [419,] 99.52051 103.55852 ## [420,] 98.95222 102.94167 ## [421,] 98.93573 102.72944 ## [422,] 98.91906 102.77378 ## [423,] 97.64482 100.91377 ## [424,] 100.20101 103.48794 ## [425,] 98.87389 102.13151 ## [426,] 98.02239 101.97448 ## [427,] 98.28491 101.91477 ## [428,] 97.53484 101.76563 ## [429,] 97.49618 100.78512 ## [430,] 97.24204 100.56145 ## [431,] 97.20563 101.20690 ## [432,] 98.88804 103.32466 ## [433,] 99.54647 103.41675 ## [434,] 98.07880 101.59746 ## [435,] 97.75154 101.13808 ## [436,] 99.40909 102.41118 ## [437,] 97.86873 102.02562 ## [438,] 97.80562 102.19020 ## [439,] 97.85856 101.02441 ## [440,] 98.98223 103.09547 ## [441,] 98.48751 102.20003 ## [442,] 97.49335 102.13234 ## [443,] 98.87920 102.53289 ## [444,] 97.48375 100.38017 ## [445,] 97.36894 100.98181 ## [446,] 98.54655 101.67038 ## [447,] 98.93633 102.14071 ## [448,] 98.04020 101.80537 ## [449,] 98.90407 103.52259 ## [450,] 97.06135 100.12977 ## [451,] 96.92645 100.60029 ## [452,] 97.49276 101.24603 ## [453,] 97.96899 102.88295 ## [454,] 96.73755 99.86248 ## [455,] 97.40067 101.23028 ## [456,] 97.67378 100.67876 ## [457,] 96.48548 101.06763 ## [458,] 99.03122 102.83462 ## [459,] 98.51848 100.88142 ## [460,] 97.92917 102.03976 ## [461,] 97.20192 101.30997 ## [462,] 97.95717 101.87092 ## [463,] 98.21859 101.92773 ## [464,] 99.38719 102.00525 ## [465,] 98.18959 102.64420 ## [466,] 98.83301 102.15679 ## [467,] 97.84752 101.38714 ## [468,] 96.08895 101.03364 ## [469,] 97.86146 102.36142 ## [470,] 98.06530 101.62862 ## [471,] 97.40931 101.47524 ## [472,] 99.73159 102.71951 ## [473,] 97.97514 102.58271 ## [474,] 98.27585 101.98399 ## [475,] 99.00828 102.72609 ## [476,] 97.25986 100.07734 ## [477,] 97.59523 100.91508 ## [478,] 97.81233 101.39990 ## [479,] 98.43037 102.48357 ## [480,] 98.05175 101.22619 ## [481,] 98.12595 101.31969 ## [482,] 96.96191 102.16829 ## [483,] 97.92601 102.96981 ## [484,] 97.92911 102.32055 ## [485,] 96.74188 100.32025 ## [486,] 98.70458 102.78869 ## [487,] 97.70179 101.01183 ## [488,] 98.12817 101.37374 ## [489,] 96.32162 100.68439 ## [490,] 97.19187 101.46638 ## [491,] 99.52913 102.96787 ## [492,] 97.67272 101.48016 ## [493,] 98.58689 102.18700 ## [494,] 98.88817 102.39694 ## [495,] 97.93565 102.22592 ## [496,] 100.06862 103.51139 ## [497,] 98.31477 102.20526 ## [498,] 97.39725 101.24043 ## [499,] 98.67225 102.13229 ## [500,] 97.14057 101.87016 ``` ] --- ## Part 4 ### For each estimate of `\(E[Y \mid x=5]\)` in part 2, compute the `\(95\%\)` CI for the mean response **Question:** How many of these 500 intervals would you expect contain the true value of `\(E[Y \mid x=5]=100\)`? -- ```r sum((LB_mean_response<=100)&(UB_mean_response>=100)) ``` ``` ## [1] 476 ```