library(tidyverse)
## Warning: package 'ggplot2' was built under R version 4.4.1
## Warning: package 'dplyr' was built under R version 4.4.1
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(stats)
all_countries <- read.csv("all_countries.csv")
as.data.frame(na.omit(all_countries))
## Country Code LandArea Population Density GDP Rural CO2
## 2 Albania ALB 27.4000 2.866 104.6 5254 39.7 1.98
## 3 Algeria DZA 2381.7400 42.228 17.7 4279 27.4 3.74
## 6 Angola AGO 1246.7000 30.810 24.7 3432 34.5 1.29
## 8 Argentina ARG 2736.6900 44.495 16.3 11653 8.1 4.78
## 9 Armenia ARM 28.4700 2.952 103.7 4212 36.9 1.90
## 11 Australia AUS 7692.0200 24.992 3.2 57305 14.0 15.39
## 12 Austria AUT 82.5230 8.847 107.2 51513 41.7 6.87
## 13 Azerbaijan AZE 82.6700 9.942 120.3 4721 44.3 3.93
## 16 Bangladesh BGD 130.1700 161.356 1239.6 1698 63.4 0.47
## 18 Belarus BLR 202.9880 9.485 46.7 6290 21.4 6.70
## 21 Benin BEN 112.7600 11.485 101.9 902 52.7 0.61
## 24 Bolivia BOL 1083.3000 11.353 10.5 3549 30.6 1.91
## 26 Botswana BWA 566.7300 2.254 4.0 8259 30.6 3.37
## 27 Brazil BRA 8358.1400 209.469 25.1 8921 13.4 2.61
## 30 Bulgaria BGR 108.5600 7.024 64.7 9273 25.0 5.87
## 34 Cambodia KHM 176.5200 16.250 92.1 1512 76.6 0.44
## 35 Cameroon CMR 472.7100 25.216 53.3 1527 43.6 0.31
## 41 Chile CHL 743.5320 18.729 25.2 15923 12.4 4.65
## 43 Colombia COL 1109.5000 49.649 44.7 6651 19.2 1.79
## 46 Congo, Rep. COG 341.5000 5.244 15.4 2148 33.1 0.65
## 47 Costa Rica CRI 51.0600 4.999 97.9 12027 20.7 1.62
## 48 Cote d'Ivoire CIV 318.0000 25.069 78.8 1716 49.2 0.49
## 52 Cyprus CYP 9.2400 1.189 128.7 28159 33.2 5.26
## 53 Czech Republic CZE 77.2200 10.626 137.6 22973 26.2 9.17
## 54 Denmark DNK 41.9900 5.797 138.1 60596 12.1 5.94
## 57 Dominican Republic DOM 48.3100 10.627 220.0 7650 18.9 2.12
## 58 Ecuador ECU 248.3600 17.084 68.8 6345 36.2 2.75
## 59 Egypt, Arab Rep. EGY 995.4500 98.424 98.9 2549 57.3 2.23
## 60 El Salvador SLV 20.7200 6.421 309.9 4058 28.0 1.00
## 63 Estonia EST 43.4700 1.321 30.4 22928 31.1 14.85
## 65 Ethiopia ETH 1000.0000 109.225 109.2 772 79.2 0.12
## 69 France FRA 547.5570 66.987 122.3 41464 19.6 4.57
## 71 Gabon GAB 257.6700 2.119 8.2 8030 10.6 2.76
## 73 Georgia GEO 69.4900 3.731 65.3 4345 41.4 2.42
## 74 Germany DEU 349.3600 82.928 237.4 48196 22.7 8.89
## 75 Ghana GHA 227.5400 29.767 130.8 2202 43.9 0.53
## 77 Greece GRC 128.9000 10.728 83.2 20324 20.9 6.18
## 81 Guatemala GTM 107.1600 17.248 161.0 4549 48.9 1.15
## 85 Haiti HTI 27.5600 11.123 403.6 868 44.7 0.27
## 86 Honduras HND 111.8900 9.588 85.7 2483 42.9 1.06
## 88 Hungary HUN 90.5300 9.769 107.9 15939 28.6 4.27
## 90 India IND 2973.1900 1352.617 454.9 2016 66.0 1.73
## 91 Indonesia IDN 1811.5700 267.663 147.8 3894 44.7 1.82
## 94 Ireland IRL 68.8900 4.854 70.5 77450 36.8 7.31
## 97 Italy ITA 294.1400 60.431 205.5 34318 29.6 5.27
## 98 Jamaica JAM 10.8300 2.935 271.0 5356 44.3 2.58
## 99 Japan JPN 364.5600 126.529 347.1 39287 8.4 9.54
## 101 Kazakhstan KAZ 2699.7000 18.276 6.8 9331 42.6 14.36
## 102 Kenya KEN 569.1400 51.393 90.3 1711 73.0 0.31
## 107 Kuwait KWT 17.8200 4.137 232.2 34244 0.0 25.85
## 108 Kyrgyz Republic KGZ 191.8000 6.316 32.9 1281 63.6 1.65
## 111 Lebanon LBN 10.2300 6.849 669.5 8270 11.4 3.84
## 116 Lithuania LTU 62.6420 2.790 44.5 19090 32.3 4.38
## 117 Luxembourg LUX 2.4300 0.608 250.1 114340 9.0 17.36
## 121 Malaysia MYS 328.5500 31.529 96.0 11239 24.0 8.13
## 128 Mexico MEX 1943.9500 126.191 64.9 9698 19.8 3.99
## 132 Mongolia MNG 1553.5600 3.170 2.0 4104 31.6 7.09
## 133 Montenegro MNE 13.4500 0.622 46.3 8761 33.2 3.56
## 134 Morocco MAR 446.3000 36.029 80.7 3238 37.5 1.75
## 135 Mozambique MOZ 786.3800 29.496 37.5 490 64.0 0.32
## 136 Myanmar MMR 653.0800 53.708 82.2 1326 69.4 0.41
## 137 Namibia NAM 823.2900 2.448 3.0 5931 50.0 1.65
## 139 Nepal NPL 143.3500 28.088 195.9 1026 80.3 0.30
## 140 Netherlands NLD 33.6900 17.231 511.5 52978 8.5 9.92
## 142 New Zealand NZL 263.3100 4.886 18.6 41966 13.5 7.69
## 143 Nicaragua NIC 120.3400 6.466 53.7 2029 41.5 0.79
## 144 Niger NER 1266.7000 22.443 17.7 412 83.6 0.11
## 145 Nigeria NGA 910.7700 195.875 215.1 2028 49.7 0.55
## 146 North Macedonia MKD 25.2200 2.083 82.6 6084 42.0 3.61
## 148 Norway NOR 365.1230 5.314 14.6 81807 17.8 9.27
## 150 Pakistan PAK 770.8800 212.215 275.3 1473 63.3 0.85
## 152 Panama PAN 74.3400 4.177 56.2 15575 32.3 2.26
## 154 Paraguay PRY 397.3000 6.956 17.5 5871 38.4 0.86
## 155 Peru PER 1280.0000 31.989 25.0 6947 22.1 2.05
## 156 Philippines PHL 298.1700 106.652 357.7 3103 53.1 1.05
## 158 Portugal PRT 91.6056 10.282 112.2 23146 34.8 4.33
## 161 Romania ROU 230.0800 19.474 84.6 12301 46.0 3.52
## 162 Russian Federation RUS 16376.8700 144.478 8.8 11289 25.6 11.86
## 168 Senegal SEN 192.5300 15.854 82.3 1522 52.8 0.62
## 169 Serbia SRB 87.4600 6.982 79.8 7234 43.9 5.28
## 174 Slovak Republic SVK 48.0800 5.447 113.3 19547 46.3 5.66
## 175 Slovenia SVN 20.1420 2.067 102.6 26234 45.5 6.21
## 178 South Africa ZAF 1213.0900 57.780 47.6 6340 33.6 8.98
## 180 Spain ESP 499.5640 46.724 93.5 30524 19.7 5.03
## 181 Sri Lanka LKA 62.7100 21.670 345.6 4102 81.5 0.89
## 192 Tanzania TZA 885.8000 56.318 63.6 1051 66.2 0.23
## 193 Thailand THA 510.8900 69.429 135.9 7274 50.1 4.62
## 195 Togo TGO 54.3900 7.889 145.0 672 58.3 0.37
## 197 Trinidad and Tobago TTO 5.1300 1.390 270.9 16844 46.8 33.97
## 198 Tunisia TUN 155.3600 11.565 74.4 3447 31.1 2.61
## 204 Ukraine UKR 579.2900 44.623 77.0 3095 30.6 5.02
## 208 Uruguay URY 175.0200 3.449 19.7 17278 4.7 1.98
## PumpPrice Military Health ArmedForces Internet Cell HIV Hunger Diabetes
## 2 1.36 4.08 9.51 9 71.8 123.7 0.1 5.5 10.1
## 3 0.28 13.81 10.73 317 47.7 111.0 0.1 4.7 6.7
## 6 0.97 9.40 5.43 117 14.3 44.7 1.9 23.9 3.9
## 8 1.10 2.05 13.56 105 75.8 139.8 0.4 3.8 5.5
## 9 0.77 20.86 6.05 49 69.7 119.0 0.2 4.3 7.1
## 11 0.93 5.12 17.42 58 86.5 112.7 0.1 2.5 5.1
## 12 1.20 1.52 14.93 21 87.9 170.8 0.1 2.5 6.4
## 13 0.56 10.99 3.88 82 79.0 103.0 0.1 2.5 7.1
## 16 1.12 10.16 3.38 221 18.0 91.7 0.1 15.2 8.4
## 18 0.60 31.90 8.47 155 74.4 120.6 0.4 2.5 5.2
## 21 0.72 3.72 3.72 12 14.1 78.5 1.0 10.4 1.0
## 24 0.71 3.88 11.33 71 43.8 99.2 0.3 19.8 6.9
## 26 0.71 8.56 9.15 9 41.4 141.4 22.8 28.5 4.8
## 27 1.02 3.90 9.90 730 67.5 113.0 0.6 2.5 8.1
## 30 1.11 4.81 11.90 31 63.4 120.4 0.1 3.0 5.8
## 34 0.90 9.17 6.16 191 34.0 116.0 0.5 18.5 4.0
## 35 1.03 6.03 2.95 24 23.2 83.7 3.7 7.3 7.2
## 41 1.03 7.41 19.74 122 82.3 127.5 0.6 3.3 8.5
## 43 0.68 11.63 13.37 481 62.3 126.8 0.5 6.5 7.4
## 46 0.97 10.44 3.92 12 8.7 96.1 3.1 37.5 7.2
## 47 0.98 0.00 29.19 10 71.6 180.2 0.4 4.4 8.8
## 48 0.93 5.98 4.88 27 43.8 130.7 2.8 20.7 2.4
## 52 1.23 4.26 7.53 16 80.7 138.5 0.1 4.6 9.2
## 53 1.17 2.76 14.83 23 78.7 119.0 0.1 2.5 6.8
## 54 1.55 2.31 16.25 15 97.1 121.7 0.1 2.5 6.4
## 57 1.07 4.14 16.00 71 65.0 81.4 0.9 10.4 8.2
## 58 0.61 6.37 10.99 41 57.3 88.1 0.3 7.8 5.6
## 59 0.40 4.14 4.22 836 45.0 105.5 0.1 4.8 17.3
## 60 0.83 4.24 20.93 42 31.3 156.5 0.6 10.3 8.9
## 63 1.14 5.13 12.41 6 88.1 145.4 0.7 2.8 4.0
## 65 0.75 3.85 6.02 138 18.6 37.7 0.9 21.4 7.5
## 69 1.39 4.10 16.97 307 80.5 106.2 0.5 2.5 4.8
## 71 0.92 9.17 9.20 7 50.3 131.5 4.2 9.4 7.2
## 73 0.76 6.61 10.29 26 60.5 140.7 0.4 7.4 7.1
## 74 1.39 2.82 21.36 180 84.4 133.6 0.2 2.5 8.3
## 75 0.92 1.56 6.54 16 37.9 127.5 1.7 6.1 5.0
## 77 1.54 4.92 10.32 146 69.9 115.9 0.2 2.5 4.6
## 81 0.79 2.88 17.94 43 40.7 118.2 0.4 15.8 10.2
## 85 0.81 0.00 4.42 0 12.3 57.4 1.9 45.8 6.7
## 86 0.98 6.46 14.04 23 32.1 88.9 0.3 15.3 7.2
## 88 1.18 2.23 10.42 40 76.8 113.5 0.1 2.5 7.6
## 90 0.97 8.74 3.14 3031 34.5 87.3 0.2 14.8 10.4
## 91 0.63 4.29 8.31 676 32.3 164.9 0.4 7.7 6.3
## 94 1.37 1.26 19.65 9 84.5 102.9 0.2 2.5 3.3
## 97 1.61 2.77 13.47 347 61.3 141.3 0.2 2.5 4.8
## 98 1.11 4.37 12.85 4 48.8 107.0 1.8 8.9 11.3
## 99 1.06 2.53 23.39 261 90.9 135.5 0.1 2.5 5.7
## 101 0.42 4.77 9.40 71 76.4 146.6 0.2 2.5 7.1
## 102 0.95 4.81 6.06 29 17.8 86.1 4.8 24.2 2.9
## 107 0.35 11.01 6.21 25 98.0 172.6 0.1 2.5 15.8
## 108 0.56 4.39 6.60 21 38.2 121.9 0.2 6.5 7.1
## 111 0.74 15.56 14.33 80 78.2 72.3 0.1 10.9 12.7
## 116 1.16 5.84 12.80 34 77.6 150.9 0.2 2.5 3.7
## 117 1.19 1.40 11.88 2 97.8 136.1 0.3 2.5 4.4
## 121 0.45 4.26 8.23 136 80.1 133.9 0.4 2.9 16.7
## 128 0.73 2.08 10.41 336 63.9 88.5 0.3 3.8 13.1
## 132 0.72 2.51 5.33 18 23.7 126.4 0.1 18.7 4.8
## 133 1.16 3.24 12.06 12 71.3 166.1 0.1 2.5 10.1
## 134 0.99 10.48 9.07 246 61.8 122.9 0.1 3.9 7.1
## 135 0.65 3.18 8.35 11 20.8 40.0 12.5 30.5 3.3
## 136 0.54 15.20 4.79 513 30.7 89.8 0.7 10.5 4.6
## 137 0.76 8.80 13.80 16 36.8 105.8 12.1 25.4 3.9
## 139 0.91 4.50 5.31 112 21.4 123.2 0.2 9.5 7.3
## 140 1.68 2.90 19.31 41 93.2 120.5 0.2 2.5 5.3
## 142 1.40 3.03 22.48 9 90.8 136.0 0.1 2.5 8.1
## 143 0.91 2.17 20.04 12 27.9 131.6 0.2 16.2 11.5
## 144 0.88 9.49 5.69 10 10.2 40.9 0.3 14.4 2.4
## 145 0.46 4.05 5.01 215 27.7 75.9 2.8 11.5 2.4
## 146 1.11 3.06 13.05 16 76.3 96.4 0.1 4.1 10.1
## 148 1.78 3.41 17.59 23 96.5 107.9 0.1 2.5 5.3
## 150 0.79 18.51 3.86 936 15.5 73.4 0.1 20.5 8.4
## 152 0.74 0.00 21.44 26 57.9 126.7 1.0 9.2 8.3
## 154 1.04 4.82 16.18 27 61.1 109.6 0.5 11.2 8.3
## 155 0.99 5.57 15.71 158 48.7 121.0 0.3 8.8 6.0
## 156 0.86 5.44 7.10 153 60.1 110.4 0.1 13.7 7.1
## 158 1.54 4.08 13.40 52 73.8 113.9 0.6 2.5 9.9
## 161 1.16 5.96 11.32 126 63.7 113.8 0.1 2.5 9.7
## 162 0.59 11.40 8.23 1454 76.0 157.9 1.2 2.5 6.2
## 168 1.14 8.80 6.15 19 29.6 99.4 0.4 11.3 2.4
## 169 1.16 4.38 12.34 32 70.3 124.0 0.1 5.6 10.1
## 174 1.32 3.01 13.71 16 81.6 130.7 0.1 2.7 7.3
## 175 1.32 2.48 13.52 7 78.9 117.5 0.1 2.5 7.3
## 178 0.92 2.95 13.32 80 56.2 156.0 18.8 6.1 5.5
## 180 1.26 3.09 15.14 196 84.6 113.3 0.4 2.5 7.2
## 181 0.88 10.14 8.56 317 34.1 135.1 0.1 10.9 10.7
## 192 0.87 6.91 9.52 28 16.0 69.7 4.5 32.0 5.8
## 193 0.71 6.34 15.26 455 52.9 176.0 1.1 9.0 7.0
## 195 0.71 7.11 4.25 10 12.4 77.8 2.1 16.2 6.2
## 197 0.54 2.41 9.66 4 77.3 148.3 1.1 4.9 11.0
## 198 0.73 6.89 13.72 48 55.5 124.3 0.1 4.9 8.5
## 204 0.83 8.71 7.03 297 57.1 133.5 0.9 3.3 7.1
## 208 1.50 5.76 19.49 22 68.3 147.5 0.6 2.5 6.9
## BirthRate DeathRate ElderlyPop LifeExpectancy FemaleLabor Unemployment
## 2 11.7 7.5 13.6 78.5 55.9 13.9
## 3 22.3 4.8 6.4 76.3 16.4 12.1
## 6 41.3 8.4 2.5 61.8 76.4 7.3
## 8 17.0 7.6 11.3 76.7 57.1 9.5
## 9 13.1 9.7 11.4 74.8 55.8 17.7
## 11 12.4 6.5 15.7 82.5 72.5 5.4
## 12 10.0 9.5 19.4 81.6 71.8 4.8
## 13 14.6 5.8 6.2 72.1 69.2 5.2
## 16 18.6 5.3 5.1 72.8 38.1 4.3
## 18 10.8 12.6 15.0 74.1 74.6 5.7
## 21 36.6 9.0 3.3 61.2 70.6 2.1
## 24 23.0 7.3 6.8 69.5 58.1 3.3
## 26 23.2 6.4 4.1 67.6 69.1 17.9
## 27 13.9 6.2 8.9 75.7 60.6 12.5
## 30 9.0 15.5 21.1 74.8 67.5 5.3
## 34 22.9 6.0 4.6 69.3 77.2 1.0
## 35 35.8 9.8 3.2 58.6 72.1 3.4
## 41 13.1 6.2 11.5 79.7 58.2 7.2
## 43 14.9 6.1 8.0 74.6 63.7 9.1
## 46 34.1 7.1 3.4 65.1 68.1 10.4
## 47 14.1 5.0 9.8 80.0 51.8 8.1
## 48 36.6 11.9 2.9 54.1 49.3 2.5
## 52 10.7 7.0 13.7 80.7 68.9 8.1
## 53 10.8 10.5 19.5 79.5 69.3 2.4
## 54 10.6 8.2 19.8 81.0 76.2 5.0
## 57 19.8 6.1 7.2 74.0 55.0 5.8
## 58 19.9 5.1 7.3 76.6 59.8 3.9
## 59 25.7 5.9 5.2 71.7 24.7 11.4
## 60 18.4 6.8 8.5 73.8 50.0 4.4
## 63 10.5 11.8 19.7 77.6 75.3 5.5
## 65 31.3 6.7 3.5 65.9 76.9 1.8
## 69 11.4 9.0 20.1 82.5 67.5 9.2
## 71 28.9 7.4 4.4 66.5 45.4 19.5
## 73 13.2 13.2 15.0 73.4 63.4 14.1
## 74 9.5 11.3 21.7 81.0 74.1 3.4
## 75 30.5 8.0 3.4 63.0 65.3 6.7
## 77 8.2 11.6 20.6 81.4 60.5 19.2
## 81 24.9 4.8 4.8 73.7 43.1 2.7
## 85 23.8 8.5 4.9 63.6 64.8 13.5
## 86 21.4 4.8 4.8 73.8 49.3 4.1
## 88 9.7 13.5 19.2 76.1 64.7 3.7
## 90 18.8 7.3 6.2 68.8 24.8 2.6
## 91 18.6 7.2 5.5 69.4 54.3 4.3
## 94 12.9 6.3 14.3 82.0 66.7 5.7
## 97 7.6 10.7 23.3 83.2 55.7 10.2
## 98 16.4 7.0 9.9 76.1 66.9 9.4
## 99 7.6 10.8 27.5 84.1 69.8 2.4
## 101 21.6 7.2 7.2 73.0 73.7 4.9
## 102 30.9 5.7 2.7 67.3 64.1 9.3
## 107 16.0 2.8 2.5 74.8 58.8 2.1
## 108 24.8 5.4 4.7 71.2 51.6 7.2
## 111 15.5 4.7 8.7 79.8 26.3 6.2
## 116 10.1 14.2 19.2 74.7 74.8 6.0
## 117 10.4 7.1 14.5 82.7 65.8 5.5
## 121 17.0 5.0 6.5 75.5 54.9 3.4
## 128 17.8 4.9 7.1 77.3 47.1 3.3
## 132 23.1 6.3 4.1 69.5 56.5 6.3
## 133 11.2 9.9 15.3 77.3 53.7 15.5
## 134 19.5 5.1 7.0 76.1 23.1 9.0
## 135 38.6 9.8 3.2 58.9 78.0 3.2
## 136 17.6 8.2 6.0 66.7 51.7 1.6
## 137 28.7 7.1 3.6 64.9 58.7 23.1
## 139 19.5 6.2 6.0 70.6 84.5 1.3
## 140 9.9 8.8 19.2 81.6 75.4 3.9
## 142 12.4 7.0 15.6 81.7 76.4 4.5
## 143 19.1 4.8 5.7 75.7 53.9 4.5
## 144 47.8 9.5 2.6 60.4 68.9 0.3
## 145 38.4 12.2 2.7 53.9 50.5 6.0
## 146 11.2 9.9 13.7 75.9 51.8 21.6
## 148 10.7 7.7 17.0 82.5 75.2 3.9
## 150 27.7 7.2 4.5 66.6 25.2 3.0
## 152 19.2 5.0 8.1 78.2 57.4 3.9
## 154 20.7 5.8 6.6 73.2 60.5 4.7
## 155 18.9 5.7 7.3 75.2 73.3 2.8
## 156 23.0 6.5 4.9 69.2 47.7 2.5
## 158 8.4 10.6 21.9 81.1 71.8 6.9
## 161 9.7 13.3 18.3 75.3 58.2 4.3
## 162 12.9 12.9 14.6 72.1 68.9 4.7
## 168 35.0 5.7 3.0 67.5 36.5 6.5
## 169 9.2 14.8 17.9 76.1 59.3 13.5
## 174 10.7 9.9 15.6 77.2 66.4 6.8
## 175 9.8 9.9 19.7 81.2 71.4 5.5
## 178 20.7 9.6 5.5 63.4 53.4 27.0
## 180 8.4 9.0 19.7 83.3 68.8 15.5
## 181 15.0 7.0 10.4 75.5 38.2 4.4
## 192 37.8 6.5 3.1 66.3 81.0 1.9
## 193 10.1 8.0 11.8 75.5 67.2 0.7
## 195 33.5 8.6 2.9 60.5 77.7 1.7
## 197 13.3 9.7 10.3 70.8 58.0 2.8
## 198 17.9 6.3 8.3 75.9 27.1 15.5
## 204 9.4 14.5 16.8 71.8 60.5 9.4
## 208 13.9 9.4 14.8 77.6 68.4 8.0
## Energy Electricity Developed
## 2 808 2309 1
## 3 1328 1363 1
## 6 545 312 1
## 8 2030 3075 2
## 9 1016 1962 1
## 11 5335 10071 3
## 12 3763 8356 3
## 13 1502 2202 1
## 16 229 320 1
## 18 2929 3680 2
## 21 417 100 1
## 24 778 743 1
## 26 1301 1816 1
## 27 1496 2620 2
## 30 2478 4709 2
## 34 417 271 1
## 35 335 275 1
## 41 2033 3880 2
## 43 724 1312 1
## 46 555 203 1
## 47 1023 1942 1
## 48 613 275 1
## 52 1712 3625 2
## 53 3915 6259 3
## 54 2873 5859 3
## 57 752 1616 1
## 58 889 1376 1
## 59 827 1683 1
## 60 646 937 1
## 63 4593 6732 3
## 65 493 69 1
## 69 3659 6940 3
## 71 2694 1168 1
## 73 1180 2694 2
## 74 3779 7035 3
## 75 332 351 1
## 77 2124 5063 3
## 81 830 578 1
## 85 394 39 1
## 86 598 620 1
## 88 2314 3966 2
## 90 637 805 1
## 91 884 812 1
## 94 2742 5672 3
## 97 2414 5002 3
## 98 977 1051 1
## 99 3471 7820 3
## 101 4435 5600 3
## 102 506 164 1
## 107 9179 15591 3
## 108 650 1941 1
## 111 1197 2588 2
## 116 2387 3821 2
## 117 6861 13915 3
## 121 3003 4652 2
## 128 1562 2157 1
## 132 1828 2006 1
## 133 1538 4612 2
## 134 555 904 1
## 135 443 479 1
## 136 369 215 1
## 137 794 1653 1
## 139 434 146 1
## 140 4326 6713 3
## 142 4560 9026 3
## 143 596 568 1
## 144 150 51 1
## 145 764 145 1
## 146 1262 3497 2
## 148 5596 23000 3
## 150 460 448 1
## 152 1080 2064 1
## 154 783 1552 1
## 155 790 1346 1
## 156 474 696 1
## 158 2035 4663 2
## 161 1592 2584 2
## 162 4943 6603 3
## 168 279 229 1
## 169 1859 4272 2
## 174 2943 5137 3
## 175 3236 6728 3
## 178 2695 4198 2
## 180 2465 5356 3
## 181 516 531 1
## 192 497 104 1
## 193 1969 2539 2
## 195 462 155 1
## 197 14364 7093 3
## 198 950 1455 1
## 204 2334 3419 2
## 208 1386 3085 2
cor(all_countries$Population, all_countries$GDP, use='complete.obs')
## [1] -0.0449688
A higher population is not correlated to a higher GDP within a country. As one increases, the other decreases.
lm_model <- lm(LifeExpectancy ~ GDP, data = all_countries)
lm_model
##
## Call:
## lm(formula = LifeExpectancy ~ GDP, data = all_countries)
##
## Coefficients:
## (Intercept) GDP
## 6.842e+01 2.476e-04
The linear regression model is
LifeExpectancy = 0.0002(GDP) + 68.42
This means that when a country’s GDP is 0, their life expectancy is 68.42 years. The slope of the model is 0.0002, meaning that for every additional unit of GDP, the life expectancy increases by 0.0002. We can plug in different GDP numbers to predict a country’s life expectancy. Since the slop of the equation is positive, as the GDP increases, so does the life expectancy.
lm_model2 <- lm(Health ~ CO2, data = all_countries)
summary(lm_model2)
##
## Call:
## lm(formula = Health ~ CO2, data = all_countries)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.413 -4.176 -0.980 3.210 26.729
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 9.84685 0.52417 18.786 <2e-16 ***
## CO2 0.17481 0.06872 2.544 0.0118 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.688 on 183 degrees of freedom
## (32 observations deleted due to missingness)
## Multiple R-squared: 0.03416, Adjusted R-squared: 0.02888
## F-statistic: 6.471 on 1 and 183 DF, p-value: 0.01179
summary_lm <- summary(lm_model2)
summary_lm$r.squared
## [1] 0.03415519
The regression line is a good fit. The p-value is 0.01 which is statistically significant since it is less than 0.05. The residual median is close to 0 and very strong at -0.98, meaning the data points are -0.98 units below the regression line on average. However, only about 3.4% of the variability of the health can be explained by the CO2 level.
ggplot(all_countries, aes(x = Health, y = CO2)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "green") +
labs(x = "Health Prevalence By Country",
y = "CO2 Level",
title = "Linear Regression: Health vs. CO2") +
theme_bw()
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 32 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 32 rows containing missing values or values outside the scale range
## (`geom_point()`).