library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.6     v dplyr   1.0.7
## v tidyr   1.2.0     v stringr 1.4.0
## v readr   2.1.1     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(openintro)
## Loading required package: airports
## Loading required package: cherryblossom
## Loading required package: usdata
data('hfi', package='openintro')

Exercise 1

What are the dimensions of the dataset?

The dataset contains 1,448 observations with 123 variables.

hfi
## # A tibble: 1,458 x 123
##     year ISO_code countries region pf_rol_procedur~ pf_rol_civil pf_rol_criminal
##    <dbl> <chr>    <chr>     <chr>             <dbl>        <dbl>           <dbl>
##  1  2016 ALB      Albania   Easte~             6.66         4.55            4.67
##  2  2016 DZA      Algeria   Middl~            NA           NA              NA   
##  3  2016 AGO      Angola    Sub-S~            NA           NA              NA   
##  4  2016 ARG      Argentina Latin~             7.10         5.79            4.34
##  5  2016 ARM      Armenia   Cauca~            NA           NA              NA   
##  6  2016 AUS      Australia Ocean~             8.44         7.53            7.36
##  7  2016 AUT      Austria   Weste~             8.97         7.87            7.67
##  8  2016 AZE      Azerbaij~ Cauca~            NA           NA              NA   
##  9  2016 BHS      Bahamas   Latin~             6.93         6.01            6.26
## 10  2016 BHR      Bahrain   Middl~            NA           NA              NA   
## # ... with 1,448 more rows, and 116 more variables: pf_rol <dbl>,
## #   pf_ss_homicide <dbl>, pf_ss_disappearances_disap <dbl>,
## #   pf_ss_disappearances_violent <dbl>, pf_ss_disappearances_organized <dbl>,
## #   pf_ss_disappearances_fatalities <dbl>, pf_ss_disappearances_injuries <dbl>,
## #   pf_ss_disappearances <dbl>, pf_ss_women_fgm <dbl>,
## #   pf_ss_women_missing <dbl>, pf_ss_women_inheritance_widows <dbl>,
## #   pf_ss_women_inheritance_daughters <dbl>, pf_ss_women_inheritance <dbl>, ...

Exercise 2

What type of plot would you use to display the relationship between the personal freedom score, pf_score

Since we are plotting 2 numerical variables it would be best to use a scatter-plot to properly illsurate the relationship. The relationship in the graph looks linear.

hfi$pf_score
##    [1] 7.596281 5.281772 6.111324 8.099696 6.912804 9.184438 9.246948 5.676553
##    [9] 7.454538 6.136070 5.302600 7.706894 6.059028 8.987179 7.430864 7.496976
##   [17] 6.600973 7.206770 7.861447 6.876334 6.665977 4.663700 8.155539 7.455340
##   [25] 4.414134 7.238448 5.330774 9.151727 7.986583 5.465632 5.509541 8.216035
##   [33] 5.350820 7.021513 4.947257 6.777868 8.165429 7.062542 8.456176 8.514394
##   [41] 9.029761 9.325640 6.942575 7.550555 3.894554 6.917902 9.013701 5.064090
##   [49] 7.792204 9.294368 8.766803 5.315575 5.302685 7.576536 9.235191 7.872178
##   [57] 7.946768 6.548246 5.371202 6.859722 7.041796 7.184443 6.386483 8.583680
##   [65] 8.258946 9.083506 6.195871 6.381312 4.532449 3.116028 8.939129 7.544916
##   [73] 8.690446 7.268416 8.733771 6.238667 6.375676 6.445537 8.766350 5.630574
##   [81] 6.247013 5.863586 8.851068 6.429994 6.688444 6.403402 3.880566 8.821339
##   [89] 9.257402 7.413658 6.835124 7.445214 5.902980 6.060929 8.977997 4.987750
##   [97] 7.717466 6.796020 7.059030 7.998313 7.630104 5.986757 6.659207 5.463361
##  [105] 7.394916 6.911611 9.398842 9.284819 6.432495 5.714520 5.823617 9.342481
##  [113] 5.509055 5.324592 7.715240 7.254949 6.974598 7.720787 6.497527 8.353120
##  [121] 9.043712 5.525553 8.653232 5.714382 6.467739 4.438732 6.774188 7.847943
##  [129] 7.372524 7.044659 7.479424 8.536500 8.822791 7.695144 8.758214 6.040722
##  [137] 4.246047 7.788563 6.020329 9.334750 9.185518 2.511654 9.041394 5.652325
##  [145] 6.126419 6.399563 6.186450 6.729938 6.920446 6.577472 6.092465 6.128889
##  [153] 6.586270 5.073350 8.995836 8.747310 8.296142 5.521449 5.968008 2.166555
##  [161] 6.007699 5.170726 7.587078 5.335310 6.132958 8.025096 6.871773 9.214745
##  [169] 9.379794 5.552377 7.502983 6.118902 5.292209 7.821851       NA 9.185713
##  [177] 7.094584 7.581713 6.662791 7.351932 8.003267 6.790132 6.704300 4.609116
##  [185] 8.238405 7.367716 4.241065 7.314548 5.127940 9.130112 8.361806 5.619156
##  [193] 5.634996 8.265002 5.374700 6.905774 4.819612 6.862956 8.255308 6.952270
##  [201] 8.521920 8.669154 9.038707 9.336046 7.023368 7.452677 3.852272 7.119972
##  [209] 8.963080 5.156317 7.701291 9.407869 8.658781 5.318685 5.460142 7.776962
##  [217] 9.290914 7.711281 8.071835 6.530605 5.560062 6.831116 6.949567 7.210987
##  [225] 6.397629 8.745162 8.442994 9.149527 6.204729 6.428120 4.492074       NA
##  [233] 9.041050 7.822677 8.717216 7.236812 8.706370 6.293274 6.421995 6.323389
##  [241] 8.796927 5.455369 6.211922 5.916014 8.816254 6.117908 6.681331 6.370389
##  [249] 3.974236 8.839368 9.329334 7.470899 6.885250 7.456857 5.970135 5.971989
##  [257] 9.041407 5.041825 7.781033 6.912513 7.101188 8.038873 7.982973 5.980245
##  [265] 6.779523 5.582742 7.331469 6.951082 9.366518 9.273780 6.362252 5.604470
##  [273] 5.630883 9.388992 5.592812 5.304687 7.706969 7.194145 6.999922 7.760073
##  [281] 6.675529 8.620769 9.041336 5.594931 8.714023 5.686519 6.551657 4.404408
##  [289] 6.842267 7.980960 7.746148 7.176240 7.613531 8.604980 8.955761 7.673184
##  [297] 8.821933 6.037550       NA 7.750407 6.129929 9.319149 9.258916 2.861653
##  [305] 9.053254 5.762052 6.191475 6.453236 5.610710 6.700934 7.039935 6.601278
##  [313] 6.473634 6.119589 6.288703 5.100455 9.047408 8.827570 8.390694 5.523500
##  [321] 6.014983 2.336884 6.128980 5.155279 7.750166 5.378657 6.107928 7.924290
##  [329] 6.915972 9.324684 9.380256 5.823368 7.422161 5.988579 5.494260 7.880064
##  [337]       NA 9.101087 6.983818 7.562763 6.722924 7.342117 8.042957 6.802452
##  [345] 6.959999 4.678174 8.327566 7.314257 4.638075 7.325478 5.543957 9.219105
##  [353] 8.006755 5.453477 5.994091 8.195178 5.519759 6.947464 4.827701 6.765420
##  [361] 8.617715 6.971078 8.478890 8.701781 9.019314 9.405681 7.291729 7.387582
##  [369] 4.301382 7.491165 9.000505 5.179382 7.477389 9.486705 8.934746 5.229237
##  [377] 5.777930 7.771882 9.302399 7.870900 8.143171 6.954735 5.368115 6.657558
##  [385] 6.945261 7.474011 6.553164 8.784911 8.567299 9.246634 6.279888 6.398716
##  [393] 4.231371       NA 8.795600 7.461034 8.703630 7.358998 8.771444 6.298162
##  [401] 6.469997 6.211527 8.855441 5.754312 6.254568 5.971988 8.711074 6.175405
##  [409] 6.563231 6.457114 4.216496 8.729086 9.362281 7.144729 7.221221 7.408412
##  [417] 5.839001 5.853400 8.871254 5.129175 7.844266 6.992210 7.126151 8.097245
##  [425] 8.101436 6.086609 6.709491 5.796951 7.258532 7.086550 9.211358 9.362772
##  [433] 6.649156 5.878961 5.723368 9.526564 5.705957 5.045778 7.687835 6.951363
##  [441] 7.180369 7.565960 6.608041 8.833323 9.029433 5.684795 8.902438 5.972597
##  [449] 6.479574 4.723066 6.809732 8.060048 6.650740 7.287357 7.589062 8.656840
##  [457] 8.936067 7.499558 8.944538 5.754403       NA 7.263678 5.954273 9.253566
##  [465] 9.303864 3.077190 8.785285 5.968551 6.359931 6.567701 6.315424 6.671558
##  [473] 7.057789 6.665387 6.642302 6.159892 6.160398 5.278573 9.155805 8.850570
##  [481] 8.333961 5.867460 6.020682 2.519069 5.672964 5.305365 7.509193 5.146842
##  [489] 6.739678 8.261689 7.103881 9.167331 9.320219 5.972940 7.417698 5.742265
##  [497] 5.292128 7.901771       NA 9.041067 7.140413 7.375620 6.819091 7.647877
##  [505] 8.012689 6.516080 7.404761 5.940890 8.347520 7.700455 6.357713 7.192898
##  [513] 6.222504 9.225504 8.006589 4.890353 5.560528 8.108076 5.737562 6.470821
##  [521] 4.455993 6.779646 8.233029 6.680421 8.481888 8.634588 9.105149 9.519350
##  [529] 7.111907 7.626139 4.699170 7.207116 8.971011 5.857614 7.284248 9.456231
##  [537] 8.769471 6.189146 5.929838 7.758326 9.220923 7.918135 8.093893 6.617232
##  [545] 5.882375 6.185571 7.633296 7.118479 5.955376 8.983629 8.557804 9.249103
##  [553] 6.965229 6.931741 4.087617       NA 9.015572 7.864782 8.760080 7.166775
##  [561] 8.852600 6.120075 6.348148 6.349646 8.666065 6.187585 6.145123       NA
##  [569] 8.752911 6.065344 6.436335       NA 4.995930 8.672215 9.188029 7.943612
##  [577] 7.068669 7.513179 6.134829 5.974948 8.930327 5.348084 8.343368 6.790791
##  [585] 7.453997 8.105190 8.051799 6.243817 7.047283 5.031095 7.376982 7.414771
##  [593] 9.186037 9.257169 6.879121 6.216772 5.445457 9.560169 5.793055 4.790842
##  [601] 7.718085 6.895944 7.289304 7.453131 6.067960 8.891007 8.929406 5.689483
##  [609] 8.615619 6.269067 6.522739 4.361519 6.735443 7.626731 6.812436 6.378484
##  [617] 7.296985 8.757185 8.920481 7.203877 8.661795 5.834280       NA 7.285546
##  [625] 5.839567 9.271152 9.210524 4.120057 8.678233 6.625175 6.672414 6.880345
##  [633] 6.494581 5.939951 7.065859 5.926390 7.315975 6.095985 7.491269 5.236195
##  [641] 9.065507 8.634731 8.493607 6.707714 6.248651 3.295410 6.440869 5.395069
##  [649] 7.670382 5.244807 6.384360 8.098573 7.368595 9.155873 9.268544 6.001311
##  [657] 7.851875 5.848527 5.477917 8.037217       NA 9.033781 7.225155 7.102856
##  [665]       NA 7.602511 7.874977 6.408080 7.420760 6.590635 8.266662 7.441721
##  [673] 6.027682 7.343626 6.130546 9.206788 8.198471 4.728113 5.545431 8.629822
##  [681] 5.636779 6.395642 4.421329 6.279521 8.251476 6.270804 8.422989 8.507043
##  [689] 9.030405 9.487167 7.032943 7.332286 5.202573 7.196339 8.967745 5.507089
##  [697] 7.349026 9.440905 8.752234 6.092342 6.080054 7.378219 9.206540 7.627061
##  [705] 8.595543 6.583208       NA 5.950756 7.712620 7.048531 5.877339 9.038171
##  [713] 8.528692 9.270262 7.204515 6.921252 3.923565       NA 8.985665 7.770850
##  [721] 8.725522 6.980532 8.886950 6.213783 6.375663 6.344946 8.663341 6.097100
##  [729] 6.269650       NA 8.723644 6.375842 6.473314       NA       NA 8.683015
##  [737] 9.169140 8.261328 7.010602 7.604950 6.278362 5.943164 8.844048 5.827101
##  [745] 8.582331 6.635227 7.460099 8.023393 8.077698 6.413817 6.742088 5.100395
##  [753] 7.147315 7.271136 9.158976 9.099278 6.638626 6.565336 5.227435 9.568154
##  [761] 5.805576 4.926955 7.728516 6.275805 7.336954 7.691982 6.900288 8.910093
##  [769] 8.949400 5.254456 8.522985 6.303112 6.320318 4.380158 6.431042 7.472898
##  [777]       NA 6.024225 7.163451 8.758805 8.911970 7.157849 8.683587 5.721443
##  [785]       NA 7.623914 5.414325 9.448184 9.320210 4.463307 8.522833 6.736704
##  [793] 6.540723 7.186706 6.644455 5.501812 6.989158 6.140156 7.189370 5.762716
##  [801] 7.613971 4.865616 9.034968 8.622446 8.578156 6.631301 6.291366 3.381012
##  [809] 6.577187 5.109619 7.764088 5.362339 5.549902 8.130653 7.410680 9.182501
##  [817] 9.176560 6.085698 7.942748 6.101845 5.616966 8.028648       NA 9.071863
##  [825] 7.395807 7.173281       NA 7.560832 7.993419 6.544255 7.631088 6.655830
##  [833] 8.359973 7.547067 6.113624 7.508288 6.128264 9.265986 8.251562 4.879459
##  [841] 5.655279 8.670305 5.738971 6.528019 4.796654 6.300028 8.269709 6.026988
##  [849] 8.477837 8.657318 9.019294 9.474775 6.971973 7.476097 5.291870 6.835688
##  [857] 8.956664 5.618283 7.355811 9.479371 8.764232 6.159744 6.193399 7.456488
##  [865] 9.244978 7.647471 8.727118 6.571394       NA 6.251189 7.851696 7.189368
##  [873] 6.074197 9.065782 8.715524 9.303933 7.287817 7.008588 4.054964       NA
##  [881] 9.061253 7.935495 8.746320 7.000108 8.896011 6.201937 6.386743 6.553068
##  [889] 8.630075 6.226252 6.190304       NA 8.802701 6.687906 6.571596       NA
##  [897]       NA 8.735453 9.204896 8.351364 7.368192 7.467499 6.485079 6.268739
##  [905] 9.004442 5.879231 8.581384 6.763573 7.463974 7.981010 8.149663 6.459090
##  [913] 6.880181 5.118472 7.317269 7.480462 9.217586 9.193461 6.737904 6.686819
##  [921] 5.340308 9.365398 5.866622 5.087155 7.726443 6.358829 7.268874 7.746133
##  [929] 7.026289 9.098542 9.000258 5.232194 8.576851 6.381338 6.349864 4.435566
##  [937] 6.458420 7.491859       NA 6.011410 7.211082 8.803042 8.870551 7.243796
##  [945] 8.800843 5.948040       NA 7.730232 5.471813 9.442889 9.324332 5.078535
##  [953] 8.605639 6.818178 6.675361 7.423516 6.800981 5.613306 7.013735 6.153702
##  [961] 7.407545 5.832225 7.701820 4.839355 9.088762 8.712934 8.692857 6.754916
##  [969] 6.415083 3.231188 6.640517 5.171471 7.757250 5.208712 5.175390 8.181316
##  [977] 7.416263 9.265386 9.023048 6.652655 7.894137 6.321461 5.538410 8.029702
##  [985]       NA 9.097983 7.379314 6.779762       NA 7.384301 8.204545 6.799652
##  [993] 7.768350 6.377936 8.299025 7.584140 6.352196 7.746637 5.698524 9.270230
## [1001] 8.312047 5.387513 5.699936 8.652734 5.563644 6.883967 5.515803 6.665292
## [1009] 8.084008 5.816050 8.148327 8.938169 9.091980 9.488762 6.971664 7.411652
## [1017] 5.538519 7.228299 9.066637 5.347053 7.563436 9.500482 8.784171 6.060273
## [1025] 5.576208 8.136609 9.106744 7.581635 8.619477 7.273042       NA 6.331051
## [1033] 7.194589 7.021834 6.488554 9.036896 8.882872 9.193639 6.574172 7.162843
## [1041] 4.489005       NA 9.069072 8.476937 8.762426 7.224410 8.789731 5.935704
## [1049] 6.910899 6.464775 8.833318 6.244275 6.188584       NA 8.657641 6.453066
## [1057] 5.687221       NA       NA 8.664016 9.202756 8.165920 6.822954 7.271030
## [1065] 6.304836 6.526071 9.032154 5.798658 8.506716 6.777854 7.450517 7.579833
## [1073] 8.208571 6.393932 6.399148 6.007950 7.242411 7.347654 9.197257 9.428153
## [1081] 7.400991 7.194329 5.881826 9.561851 5.433485 4.833934 7.683680 7.021329
## [1089] 7.318168 7.599118 7.319929 8.929675 8.999700 4.960796 8.749530 6.493733
## [1097] 6.710543 4.606060 6.460770 7.728383       NA 6.475251 7.445439 8.776370
## [1105] 8.620039 6.798161 9.172400 6.570650       NA 7.852177 5.852716 9.438605
## [1113] 9.336283 5.148592 8.294907 7.535268 6.479170 7.748105 7.487092 5.799787
## [1121] 6.840402 5.687479 7.152000 5.606187 7.696264 5.861769 9.012806 8.711692
## [1129] 8.817575 6.353238 6.679871 4.730448 6.087383 5.358830 7.860267 5.139881
## [1137] 5.273795 8.175462 7.408322 9.290626 9.031761 6.293471 8.000515 6.751321
## [1145] 5.533021 8.178830       NA 9.110864 7.359349 6.872947       NA 7.540680
## [1153] 8.226588 6.838069 7.751098       NA 8.406205 7.432165 6.804418       NA
## [1161] 5.737553 9.267999       NA 5.610116 5.545487 8.628272 5.565873 6.795143
## [1169] 5.608591 6.399806 8.265653 5.899114 8.409353 8.921275 9.153649 9.484657
## [1177] 7.038389 7.379937 5.551570 6.922049 9.057999 5.216424 7.556942 9.510538
## [1185] 8.999746 6.084612       NA 8.145426 9.142769 7.628736 8.766923 7.184947
## [1193]       NA 6.461521 7.335984 7.073770 6.556598 9.015306 8.898743 9.245503
## [1201] 6.591647 7.198304 4.353862       NA 9.045519 7.851206 8.792230 7.294271
## [1209] 8.862743 6.019213 6.768123 6.420323 8.753504 6.266073 6.641372       NA
## [1217] 8.451635       NA 5.705277       NA       NA 8.692407 8.982547 8.077733
## [1225] 6.819999 7.336294 6.548766 6.330020 9.080232 5.869709 8.360905 7.135360
## [1233] 7.727687 7.561840 8.000304 6.463867 6.243995 6.502495 7.187442 7.567099
## [1241] 9.222489 9.325434 7.308308 7.051861 5.888859 9.420202 5.585305 5.070443
## [1249] 7.787263 6.779836 7.140153 7.573309 7.240387 8.990015 8.860807       NA
## [1257] 8.668488 6.465113 7.574418       NA 6.616525 7.878666       NA 6.374351
## [1265] 7.619521 8.817191 8.632398 6.806230 8.932053 5.914972       NA       NA
## [1273]       NA 9.441831 9.324517 5.269188 8.236077       NA 6.455916 7.835613
## [1281]       NA 5.793766 6.919811 5.820344 7.137345 5.460617 7.771996 5.563103
## [1289] 9.100353 8.571688 8.800819 6.207029 6.680303       NA 6.110227 5.355347
## [1297] 7.777698 5.146131 5.237056 8.190240 7.320561 9.292040 9.027407 6.593344
## [1305] 8.146710 6.780238 5.526272 8.135015       NA 9.064172 7.350668 6.990275
## [1313]       NA 7.367289 8.004875 6.821652 7.718818       NA 8.242904 7.568461
## [1321] 6.282285       NA 5.804578 9.266003       NA 5.783164 5.585024 8.654430
## [1329] 5.721288 6.925207 5.543686 6.570636 8.295889 5.893142 8.076770 8.948103
## [1337] 9.131337 9.494348 6.878054 7.416109 5.579720 7.268472 9.039304 5.367709
## [1345] 7.786614 9.497741 8.969965 5.940088       NA 7.542609 9.144099 7.607686
## [1353] 8.771018 7.188651       NA 6.576988 6.954978 7.122098 6.730025 9.062626
## [1361] 8.894809 9.214496 6.569895 7.184828 4.882248       NA 9.059166 7.590547
## [1369] 8.793881 7.286042 8.828608 5.949624 6.868879 6.464595 8.838646 6.157210
## [1377] 6.782040       NA 8.644295       NA 5.837221       NA       NA 8.580363
## [1385] 9.108486 8.237437 7.041446 7.273545 6.296281 6.297124 9.035816 5.810717
## [1393] 8.469659 7.187200 7.507970 7.560718 8.149117 6.362837 6.393893 6.050606
## [1401] 7.179960 7.397345 9.241021 9.421085 7.406305 6.954829 6.272717 9.554284
## [1409] 5.854085 4.833701 7.748312 7.058135 7.301651 7.494997 7.391257 8.953865
## [1417] 8.986276       NA 8.737953 6.531378 7.149149       NA 6.527743 7.915282
## [1425]       NA 6.490277 7.439441 8.866865 8.641525 6.804749 9.124498 5.460755
## [1433]       NA       NA       NA 9.504694 9.308873 5.295031 8.094654       NA
## [1441] 6.477212 7.748565       NA 5.856729 6.871200 5.818116 6.976818 5.780542
## [1449] 7.727395 5.889732 9.082842 8.726531 8.775693 6.295759 6.650413       NA
## [1457] 6.145449 5.321141
plot(x=hfi$pf_score,y=hfi$pf_expression_control,
     xlim =c(0,11),
     ylim = c(0,11)
     )

### Exercise 3 Looking at your plot from the previous exercise, describe the relationship between these two variables. Make sure to discuss the form, direction, and strength of the relationship as well as any unusual observations.

The relationship with the scatterplot indicates a positive correlation since both the x and y values are increasing and it is strongly correlated since the dots are close together especially at around 10.

Exercise 4

Using plot_ss, choose a line that does a good job of minimizing the sum of squares

I ran the plot_ss a bunch of times and I got the a variety of sum of squares but the smallest sum of squares is probably 952

## I had to filter out the NAs for the graph to work properly 

hifi <- hfi %>%
  select(pf_expression_control,pf_score) %>%
  filter(pf_score != "NA" & pf_expression_control != "NA")


## I cant get the graph to print so I saved it as an image

Exercise 5

write the equation of the regression line. What does the slope tell us in the context of the relationship between human freedom and the amount of political pressure on media content?

The equation is y_hat = 5.153687 + 0.349862 * pf_expression_control and The slope tells us that the greater the human freedom there is the greater the amount of political pressure on media content.

m1 <- lm(hf_score ~ pf_expression_control, data = hfi)
summary(m1)
## 
## Call:
## lm(formula = hf_score ~ pf_expression_control, data = hfi)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.6198 -0.4908  0.1031  0.4703  2.2933 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)           5.153687   0.046070  111.87   <2e-16 ***
## pf_expression_control 0.349862   0.008067   43.37   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.667 on 1376 degrees of freedom
##   (80 observations deleted due to missingness)
## Multiple R-squared:  0.5775, Adjusted R-squared:  0.5772 
## F-statistic:  1881 on 1 and 1376 DF,  p-value: < 2.2e-16

Exercise 6

what is the residual for this prediction?

The residual may underestimate the pf score so the predicted value is below the expected value. We can expect the residual to be a positive value.

y_hat <- 5.153687 + 0.349862 * 6.7
y_hat
## [1] 7.497762

Exercise 7

Is there any apparent pattern in the residuals plot? What does this indicate about the linearity of the relationship between the two variables?

It is really difficult to see any linear trends here. This may indicate that there is no relationship between the two variables.

ggplot(data = m1, aes(x = .fitted, y = .resid)) +
  geom_point() +
  geom_hline(yintercept = 0, linetype = "dashed") +
  xlab("Fitted values") +
  ylab("Residuals")

Exercise 8

Based on the histogram and the normal probability plot, does the nearly normal residuals condition appear to be met? It is difficult to tell from the histogram but from the probablity plot it does seem to be linear and thus we can say that the conditions are met.

Exercise 9

Based on the residuals vs. fitted plot, does the constant variability condition appear to be met?

Yes there are no crazy points fanning out and the points all seem to stay together.

Exercise 10

Choose another freedom variable and a variable you think would strongly correlate with it.. Produce a scatterplot of the two variables and fit a linear model. At a glance, does there seem to be a linear relationship?

It seems like there is a linear relationship

ggplot(data = hfi, aes(x=pf_religion,y=hf_score)) +
  geom_point() +
  stat_smooth(method = "lm", se = FALSE)
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 90 rows containing non-finite values (stat_smooth).
## Warning: Removed 90 rows containing missing values (geom_point).

### Exercise 11 How does this relationship compare to the relationship between pf_expression_control and pf_score? Use the R2 values from the two model summaries to compare. Does your independent variable seem to predict your dependent one better? Why or why not? This relationship doesnt seem to compare well compared to the other reslationship. The R2 value is approximately 14.92% while the other relationship is 57.75% varability.

m2 <- lm(hf_score ~ pf_religion, data = hfi)
summary(m2)
## 
## Call:
## lm(formula = hf_score ~ pf_religion, data = hfi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -3.10229 -0.58501 -0.04865  0.77466  2.00693 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   4.7081     0.1502   31.34   <2e-16 ***
## pf_religion   0.2917     0.0188   15.51   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9377 on 1366 degrees of freedom
##   (90 observations deleted due to missingness)
## Multiple R-squared:  0.1497, Adjusted R-squared:  0.1491 
## F-statistic: 240.6 on 1 and 1366 DF,  p-value: < 2.2e-16
summary(m1)
## 
## Call:
## lm(formula = hf_score ~ pf_expression_control, data = hfi)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.6198 -0.4908  0.1031  0.4703  2.2933 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)           5.153687   0.046070  111.87   <2e-16 ***
## pf_expression_control 0.349862   0.008067   43.37   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.667 on 1376 degrees of freedom
##   (80 observations deleted due to missingness)
## Multiple R-squared:  0.5775, Adjusted R-squared:  0.5772 
## F-statistic:  1881 on 1 and 1376 DF,  p-value: < 2.2e-16

Exercise 12

What’s one freedom relationship you were most surprised about and why? Display the model diagnostics for the regression model analyzing this relationship. I found this relationship between government and personal freedom score pretty interesting.

ggplot(data = hfi, aes(x=ef_government,y=pf_score)) +
  geom_point() +
  stat_smooth(method = "lm", se = FALSE)
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 80 rows containing non-finite values (stat_smooth).
## Warning: Removed 80 rows containing missing values (geom_point).

m3 <- lm(pf_score ~ ef_government, data = hfi)
summary(m3)
## 
## Call:
## lm(formula = pf_score ~ ef_government, data = hfi)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.7533 -0.9556  0.1408  1.1908  2.5672 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    8.74374    0.18774  46.573   <2e-16 ***
## ef_government -0.23892    0.02854  -8.372   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.342 on 1376 degrees of freedom
##   (80 observations deleted due to missingness)
## Multiple R-squared:  0.04847,    Adjusted R-squared:  0.04778 
## F-statistic:  70.1 on 1 and 1376 DF,  p-value: < 2.2e-16