STAT 360: Computational Methods in STAT

Lab 1: Data Extraction, Correlations, and Bootstrapping

Load R Libraries, Import and Attach Relevant Data, and Specify Seed

library(rmarkdown); library(knitr)

library(dplyr)
library(psych); library(corrplot); library(GPArotation)
library(lavaan); library(semPlot); library(moments)

POVERTYDATA <- read.csv("https://www.dropbox.com/s/2hfzxyj3623v2fq/?dl=1")
attach(POVERTYDATA)

set.seed(37)

Use some of the available variables to calculate, adjust, and evaluate correlations between various measures of poverty from across the world

Exercise 01:

Identify the likely population of interest

The likely population of interest of this data would be world leaders. They could use this data to help identify what leads to high poverty rates in specific areas and addressing these issues leading to lower poverty rates in the future.

Exercise 02:

Identify if this sample is random, systematic, or voluntary

This sample appears to be a random sample of countries.

Exercise 03:

What command would you use to extract the percent of the population deprived of ELECTRICITY for each country?

POVERTYDATA$ELECTRICITY
##  [1]  0.1  0.0  0.0  1.9  0.0  0.3  0.0  0.0  0.0  0.0 39.8  0.5  0.0  0.0
## [15]  0.0  8.6  0.0  0.0  0.0  0.0  0.0  0.2  0.0 58.7  0.0  0.0  0.0  0.0
## [29]  0.0  0.0  0.0 27.4  0.0  0.0  0.0  0.0  0.1

Exercise 04:

Compute the mean and standard deviation of the percent of the population deprived of ELECTRICITY

mean(POVERTYDATA$ELECTRICITY)
## [1] 3.718919
sd(POVERTYDATA$ELECTRICITY)
## [1] 12.1869

Exercise 05:

Use the mean and standard deviation above to compute the z-scores for the percent of the population deprived of ELECTRICITY

zelec = (POVERTYDATA$ELECTRICITY-mean(POVERTYDATA$ELECTRICITY))/sd(POVERTYDATA$ELECTRICITY)
zelec
##  [1] -0.2969516 -0.3051572 -0.3051572 -0.1492520 -0.3051572 -0.2805406
##  [7] -0.3051572 -0.3051572 -0.3051572 -0.3051572  2.9606454 -0.2641295
## [13] -0.3051572 -0.3051572 -0.3051572  0.4005188 -0.3051572 -0.3051572
## [19] -0.3051572 -0.3051572 -0.3051572 -0.2887461 -0.3051572  4.5114913
## [25] -0.3051572 -0.3051572 -0.3051572 -0.3051572 -0.3051572 -0.3051572
## [31] -0.3051572  1.9431592 -0.3051572 -0.3051572 -0.3051572 -0.3051572
## [37] -0.2969516

Exercise 06:

Explain what the z-scores above mean in terms of the presence or absence of outliers among these countries

Outliers are Z scores with a high absolute value. In this data there appears to be an outlier with a z score of over 4.5.

Exercise 07:

Explain what the z-score for the first country (Albania) means in terms of standard deviations

There Zscore is about -.3 which means that Albania has a slightly lower than average rate of people deprivedd of electricity.

Exercise 08:

Use subset() to create a new data frame that only includes countries that are outliers in the percent of the population deprived of ELECTRICITY

subset(POVERTYDATA, abs(zelec)>3.29, select = NAME:HEMISPHERE)
##       NAME CODE WATER ELECTRICITY SANITATION EDUCATION HEMISPHERE
## 24 Lesotho  LSO  13.7        58.7       55.1      18.1          1

Exercise 09:

Use matrix notation to create a new data frame that only includes the four continuous numeric measures of poverty

povertymatrix1<- POVERTYDATA[1:37,c(1,3,4,5,6)]
povertymatrix1
##                     NAME WATER ELECTRICITY SANITATION EDUCATION
## 1                Albania   9.3         0.1        7.0       0.3
## 2                Austria   0.5         0.0        0.7       0.0
## 3                Belgium   0.3         0.0        0.9       1.9
## 4                 Bhutan   0.4         1.9       13.7      40.8
## 5               Bulgaria   9.4         0.0       15.3       0.7
## 6                  Chile   0.1         0.3        0.6       4.0
## 7                Croatia   1.2         0.0        1.3       0.3
## 8                 Cyprus   0.5         0.0        0.5       1.4
## 9         Czech Republic   0.3         0.0        0.5       0.0
## 10               Denmark   1.9         0.0        0.4       0.4
## 11              Djibouti   7.1        39.8       45.4      30.1
## 12      Egypt, Arab Rep.   0.8         0.5        3.2      10.6
## 13               Estonia   6.6         0.0        5.3       0.0
## 14               Finland   0.4         0.0        0.4       1.5
## 15                France   0.6         0.0        0.5       1.5
## 16                 Gabon  11.5         8.6       68.2      11.3
## 17                Greece   0.5         0.0        0.3       1.7
## 18               Hungary   3.6         0.0        3.8       0.0
## 19    Iran, Islamic Rep.   1.6         0.0        2.0       4.4
## 20                 Italy   0.5         0.0        0.6       1.3
## 21            Kazakhstan   1.5         0.0        0.9       0.0
## 22                Kosovo   0.7         0.2        1.4       0.5
## 23                Latvia  11.9         0.0       10.0       0.1
## 24               Lesotho  13.7        58.7       55.1      18.1
## 25             Lithuania   9.9         0.0       10.6       0.2
## 26            Luxembourg   0.2         0.0        0.0       0.8
## 27                 Malta   0.1         0.0        0.1       0.2
## 28               Moldova   0.5         0.0        0.0       0.1
## 29           Netherlands   0.1         0.0        0.0       1.1
## 30                Norway   0.3         0.0        0.0       2.1
## 31              Portugal   0.9         0.0        0.8       2.4
## 32 Sao Tome and Principe   8.8        27.4       62.1      20.2
## 33              Slovenia   0.2         0.0        0.2       0.0
## 34                 Spain   0.2         0.0        0.2       3.4
## 35                Sweden   0.1         0.0        0.0       0.9
## 36           Switzerland   0.1         0.0        0.0       0.0
## 37              Thailand   0.9         0.1        0.2      14.8

Exercise 10:

Use cbind() to create a new data frame that only includes measures of ELECTRICITY and SANITATION for each country

cbind(ELECTRICITY,SANITATION)
##       ELECTRICITY SANITATION
##  [1,]         0.1        7.0
##  [2,]         0.0        0.7
##  [3,]         0.0        0.9
##  [4,]         1.9       13.7
##  [5,]         0.0       15.3
##  [6,]         0.3        0.6
##  [7,]         0.0        1.3
##  [8,]         0.0        0.5
##  [9,]         0.0        0.5
## [10,]         0.0        0.4
## [11,]        39.8       45.4
## [12,]         0.5        3.2
## [13,]         0.0        5.3
## [14,]         0.0        0.4
## [15,]         0.0        0.5
## [16,]         8.6       68.2
## [17,]         0.0        0.3
## [18,]         0.0        3.8
## [19,]         0.0        2.0
## [20,]         0.0        0.6
## [21,]         0.0        0.9
## [22,]         0.2        1.4
## [23,]         0.0       10.0
## [24,]        58.7       55.1
## [25,]         0.0       10.6
## [26,]         0.0        0.0
## [27,]         0.0        0.1
## [28,]         0.0        0.0
## [29,]         0.0        0.0
## [30,]         0.0        0.0
## [31,]         0.0        0.8
## [32,]        27.4       62.1
## [33,]         0.0        0.2
## [34,]         0.0        0.2
## [35,]         0.0        0.0
## [36,]         0.0        0.0
## [37,]         0.1        0.2

Exercise 11:

Use plot() to generate a scatter plot of the association between ELECTRICITY and SANITATION

plot(ELECTRICITY,SANITATION)

Exercise 12:

Explain what the scatter plot above means in terms of the strength, direction, and shape of the association between ELECTRICITY and SANITATION

there is a large cluster of points at electricity =0 and then four outliers when electricity<10. To me this shows very little association between the two, Except if Electricity is high so is Sanitation.

Exercise 13:

Use cor() to compute the correlation coefficient between ELECTRICITY and SANITATION

cor(ELECTRICITY,SANITATION)
## [1] 0.7828934

Exercise 14:

Explain what the correlation coefficient above means in terms of the strength and direction of the association between ELECTRICITY and SANITATION

The correlation coefficient of over .78 indicates a strong relation between electricity and sanitation. this means that if the poverty rate of electricity is high then it is likely that their poverty rate for sanitation is high and vice a versa.

Exercise 15:

Use sample_n() to take a random sample, with replacement, of the sampled countries and compute the correlation between ELECTRICITY and SANITATION for this bootstrap sample

samp<- slice_sample(POVERTYDATA,n=37,replace=TRUE)
cor(samp$ELECTRICITY,samp$SANITATION)
## [1] 0.9136431

Exercise 16:

Use replicate() to repeat the process above 1000 times and display the resulting 1000 correlation coefficients for each of the 1000 bootstrap samples

boot<-replicate(n=1000,{samp<- slice_sample(POVERTYDATA,n=37,replace=TRUE)
cor(samp$ELECTRICITY,samp$SANITATION)
                  })
boot
##    [1]  0.913700674  0.968497661  0.908322031  0.846288881  0.736694578
##    [6]  0.798753945  0.958300936  0.965081942  0.934225231  0.694299538
##   [11]  0.953528111  0.879349449  0.759921304  0.810844438  0.794480413
##   [16]  0.870002163  0.893703902  0.973230241  0.734091180  0.646473078
##   [21]  0.767898814  0.926073043  0.669867490  0.682079737  0.808200382
##   [26]  0.769975970  0.893746000  0.820969705  0.778956677  0.956559179
##   [31]  0.683537479  0.737577163  0.875333357  0.892431152  0.700529165
##   [36]  0.886186955  0.843827519  0.883302249  0.971955916  0.897236397
##   [41]  0.716493991  0.757949129  0.779297144  0.967313894  0.877979196
##   [46]  0.942206408  0.826622555  0.791441000  0.743091329  0.676270620
##   [51]  0.921307679  0.804006699  0.795953334  0.792477558  0.800948634
##   [56]  0.770796666  0.821036235  0.747116045  0.849964406  0.785013508
##   [61]  0.680674377  0.771686963  0.757433476  0.895761217  0.962746473
##   [66]  0.893527344  0.865180108  0.921530491  0.756518938  0.808842043
##   [71]  0.676256744  0.748032893  0.775012132  0.807461162  0.789648607
##   [76]  0.820943199  0.772427519  0.747098229  0.839259399  0.749966187
##   [81]  0.974879903  0.975201755  0.746904472  0.842303559  0.614037933
##   [86]  0.797781566  0.957779766  0.816536815  0.949460130  0.915358402
##   [91]  0.811173316  0.902132100  0.926889327  0.713218254  0.744387919
##   [96]  0.774236101  0.897862966  0.829285799  0.926225417  0.804769810
##  [101]  0.829750499  0.688411376  0.634302746  0.816327026  0.925647673
##  [106]  0.609344328  0.935540952  0.627939388  0.752048348  0.639211849
##  [111]  0.787986498  0.905484940  0.791489810  0.897152944  0.905853075
##  [116]  0.838306879  0.818223589  0.877592891  0.829331017  0.783218442
##  [121]  0.966673729  0.903895474  0.717322027  0.673673607  0.952361211
##  [126]  0.820298783  0.933289043  0.825415118  0.758033374  0.914097694
##  [131]  0.840147614  0.863088774  0.782717633  0.894854063  0.914811324
##  [136]  0.882735031  0.885501379  0.983579703  0.763423870  0.790422917
##  [141]  0.816849387  0.861796780  0.927777415  0.881041253  0.829537255
##  [146]  0.889424297  0.826840066  0.695148736  0.986913941  0.728771444
##  [151]  0.824332220  0.817215014  0.970832701  0.692791811  0.842162627
##  [156]  0.819275619  0.692965953  0.746049429  0.889262359  0.776929007
##  [161]  0.810755750  0.970108002  0.948018799  0.961390625  0.779429774
##  [166]  0.778718900  0.777360162  0.821233385  0.425852391  0.918720921
##  [171]  0.768226700  0.632530907  0.798898089  0.911722438  0.637882490
##  [176]  0.748946155  0.974356748  0.981281955  0.911983647  0.962168761
##  [181]  0.675784845  0.942679268  0.892738429  0.683196066  0.853478990
##  [186]  0.688090046  0.809545166  0.924397988  0.764579457  0.621791617
##  [191]  0.889387965  0.802398899  0.829574937  0.782751194  0.644122988
##  [196]  0.983046140  0.936684980  0.969487142  0.778283230  0.893935975
##  [201]  0.940609988  0.956740252  0.712671106  0.812869603  0.753846637
##  [206]  0.450586920  0.906224412  0.719874130  0.764967313  0.948618340
##  [211]  0.797378114  0.671351811  0.927908979  0.783019465  0.898179509
##  [216]  0.898957427  0.757563186  0.826085743  0.743714964  0.699606565
##  [221]  0.671016173  0.892873178  0.628081239  0.706218745  0.752640268
##  [226]  0.889131142  0.767950940  0.864317034  0.796970415  0.966360076
##  [231]  0.903951216  0.634360693  0.942357680  0.922440723  0.812007682
##  [236]  0.914281884  0.831833361  0.930769082  0.718703934 -0.021530900
##  [241]  0.877504454  0.785162659  0.698131288  0.981237141  0.958012860
##  [246]  0.758866188  0.728669238  0.895977438  0.771272043  0.817637615
##  [251]  0.892742101  0.841223884  0.917763481  0.832646186  0.770839519
##  [256]  0.900465422  0.802952586  0.789329222  0.933417658  0.927484418
##  [261]  0.887701382  0.940887156  0.639602621  0.910965611  0.913364838
##  [266]  0.875827928  0.740330433  0.628168981  0.906162967  0.716518364
##  [271]  0.744833220  0.836486678  0.879607748  0.903615570  0.903141352
##  [276]  0.833503433  0.934766097  0.959575025  0.759619982  0.784306933
##  [281]  0.733297377  0.631840488  0.897044880  0.992255299  0.764007910
##  [286]  0.760365640  0.681286758  0.744640990  0.985158664  0.959137753
##  [291]  0.805101017  0.702037535  0.773733683  0.748058843  0.952438218
##  [296]  0.883514005  0.676505886  0.848737423  0.724272993  0.624069179
##  [301]  0.709804936  0.779009636  0.686322823  0.654623968  0.840903682
##  [306]  0.836137831  0.778512486  0.814158005  0.660941438  0.900420661
##  [311]  0.836197791  0.940448835  0.888627619  0.973676900  0.721773329
##  [316]  0.753781843  0.727411174  0.922571796  0.811012072  0.931693657
##  [321]  0.675526065  0.795752469  0.902688312  0.978803508  0.755039619
##  [326]  0.977516127  0.889508102  0.898138104  0.600375806  0.928329815
##  [331]  0.835061481  0.914806188  0.811934389 -0.011218171  0.878944434
##  [336]  0.829595798  0.759277557  0.790468185  0.748537926  0.834305476
##  [341]  0.757562072  0.897749120  0.708394551  0.919800288  0.825368530
##  [346]  0.758876497  0.801045356  0.868183412  0.915016308  0.767267405
##  [351]  0.616984089  0.460645701  0.734528174  0.936572893  0.906150123
##  [356]  0.780997849  0.824398368  0.820842443  0.802620792  0.933974774
##  [361]  0.898053858  0.857406874  0.960583105  0.796132561  0.815837456
##  [366]  0.976854002  0.709152122  0.723729649  0.803168511  0.698761116
##  [371]  0.948553696  0.827789834  0.811604121  0.718828659  0.697731016
##  [376]  0.921102610  0.972712028  0.629894225  0.688884650  0.956393640
##  [381]  0.975659287  0.903476183  0.822525212  0.936185705  0.600265704
##  [386]  0.829286999  0.792468237  0.898163055  0.763681087  0.952831839
##  [391]  0.683035204  0.913568337  0.810531247  0.927122710  0.776996888
##  [396]  0.941811198  0.879793418  0.825597244  0.846544911  0.875622740
##  [401]  0.746280327  0.920738798  0.639584859  0.696005201  0.682231269
##  [406]  0.788341748  0.669901129  0.796619596  0.680006250  0.935955727
##  [411]  0.778368450  0.628357027  0.796033182  0.905443218  0.935670189
##  [416]  0.628584670  0.915928523  0.629970742  0.777810841  0.963129352
##  [421]  0.828071980  0.665956640  0.830535302  0.959565673  0.912099469
##  [426]  0.841414772  0.892659245  0.920573687  0.843543396  0.916486473
##  [431]  0.744189587  0.745593684  0.688038973  0.663189318  0.760994638
##  [436]  0.742454582  0.904413616  0.791707237  0.811050321  0.670784001
##  [441]  0.844793003  0.665417411  0.733606652  0.978959642  0.773789716
##  [446]  0.708609472  0.762941012  0.950380694  0.739607794  0.889441020
##  [451]  0.894570220  0.761564142  0.872196468  0.758572830  0.628300783
##  [456]  0.761910882  0.741377261  0.931033705  0.817784298  0.900609925
##  [461]  0.915130014  0.811394184  0.888995109  0.966101123  0.940778660
##  [466]  0.913392051  0.845592563  0.685564290  0.752219499  0.905282055
##  [471]  0.762745552  0.798212116  0.888639290  0.819912542  0.748183359
##  [476]  0.782828855  0.681433897  0.856080810  0.967470003  0.893648858
##  [481]  0.944587452  0.964843085  0.649507966  0.843247943  0.977331437
##  [486]  0.911636584  0.907167631  0.729216365  0.934985053  0.924775073
##  [491]  0.868878559  0.900846147  0.794475808  0.593190263  0.894761062
##  [496]  0.693094463  0.748704835  0.971998045  0.691262314  0.796061418
##  [501]  0.756106672  0.826358488  0.675604474  0.756512115  0.827623927
##  [506]  0.707989768  0.887506692  0.849547545  0.964236513  0.755077005
##  [511]  0.691708858  0.784393571  0.741448986  0.786606474  0.716033609
##  [516]  0.691009470  0.939767496  0.843038329  0.887297177  0.744464433
##  [521]  0.976441364  0.777321410  0.821889600  0.879962890  0.758735667
##  [526]  0.841644430  0.826314628  0.775482809  0.630160561  0.690638380
##  [531]  0.833249185  0.816451466  0.827661216  0.763678742  0.927955511
##  [536]  0.801774572  0.693506576  0.934711134  0.752232211  0.812267404
##  [541]  0.884926958  0.882683864  0.879261234  0.754425434  0.797464349
##  [546]  0.805643305  0.825361521  0.856519429  0.822354986  0.978867406
##  [551]  0.705478967  0.930332745  0.753875235  0.746303682  0.909405578
##  [556]  0.899799998  0.886560073  0.753532409  0.825960102  0.914331766
##  [561]  0.888367326  0.824771599  0.896852850  0.679657497  0.852472081
##  [566]  0.831183439  0.893972795  0.876760565  0.916865065  0.829522473
##  [571]  0.880472467  0.724471855  0.934379530  0.919393978  0.824382964
##  [576]  0.850555152  0.755428647  0.760315090  0.895496264  0.774986009
##  [581]  0.753676284  0.830398839  0.731544355  0.765184645  0.819107224
##  [586]  0.758377272  0.802386632  0.797001149  0.907230314  0.832136565
##  [591]  0.889381892  0.747150547  0.813607413  0.818802845  0.918925690
##  [596]  0.001195636  0.717025032  0.820892220  0.778688782  0.958597148
##  [601]  0.808683406  0.718790477  0.741616415  0.772430675  0.948189696
##  [606]  0.981058551  0.930906257  0.808980384  0.888644139  0.829294341
##  [611]  0.973707230  0.680637007  0.908134101  0.624638322  0.701720414
##  [616]  0.712562990  0.963619255  0.905923414  0.757228875  0.839178768
##  [621]  0.706828072  0.770465276  0.921088237  0.777833276  0.746987282
##  [626]  0.737969681  0.944782372  0.782648939  0.842079055  0.902120619
##  [631]  0.915182716  0.770893294  0.917223629  0.898447948  0.794900041
##  [636]  0.719249223  0.878046339  0.867996289  0.725820160  0.746420370
##  [641]  0.902433676  0.817067424  0.804896375  0.893633916  0.925585787
##  [646]  0.658482132  0.939173764  0.894238244  0.822010923  0.742695734
##  [651]  0.677269124  0.912310035  0.943744928  0.989501622  0.977457825
##  [656]  0.815771131  0.973643551  0.811847327  0.743191377  0.768683767
##  [661]  0.861374265  0.755389318  0.663117606  0.756040795  0.751231858
##  [666]  0.944777538  0.878344413  0.826005417  0.792255531  0.978920579
##  [671]  0.781395019  0.881949751  0.913622767  0.873595750  0.677977424
##  [676]  0.884950214  0.787066940  0.917945068  0.808275712  0.923581426
##  [681]  0.755951809  0.855476468  0.895384677  0.788982357  0.974200703
##  [686]  0.732601507  0.981186877  0.755481974  0.892438986  0.831755775
##  [691]  0.631502986  0.952646610  0.916608400  0.915218451  0.771764690
##  [696]  0.965076845  0.808744699  0.883320755  0.932516155  0.730806028
##  [701]  0.798057327  0.820243901  0.774962039  0.710163870  0.146341256
##  [706]  0.944816945  0.677775788  0.903219676  0.915452231  0.678370002
##  [711]  0.745496818  0.931951459  0.865432216  0.693011023  0.821079735
##  [716]  0.837928819  0.634042157  0.691629865  0.974725668  0.799141760
##  [721]  0.947698239  0.893118491  0.820571622  0.634299888  0.850858796
##  [726]  0.920397461  0.921636475  0.732651519  0.745865421  0.867619896
##  [731]  0.974276897  0.782409974  0.727577081  0.626040957  0.924409480
##  [736]  0.904894403  0.943172023  0.787106394  0.808720307  0.932885534
##  [741]  0.761524620  0.907563434  0.871993829  0.830566049  0.746424846
##  [746]  0.699431313  0.658561325  0.951995402  0.908777215  0.696001993
##  [751]  0.766048890  0.788319976  0.752374023  0.651024786  0.912160217
##  [756]  0.937506253  0.782979159  0.919795103  0.876006326  0.759330515
##  [761]  0.812331143  0.677695708  0.941341763  0.697291291  0.774945406
##  [766]  0.817423711  0.792496600  0.771732431  0.698267211  0.897441088
##  [771]  0.977553396  0.840664418  0.702719678  0.770627752  0.820716128
##  [776]  0.960214299  0.831210888  0.872037503  0.731114495  0.690538916
##  [781]  0.737808865  0.725761277  0.892453794  0.773425704  0.621001185
##  [786]  0.915935918  0.952905774  0.879062943  0.770184793  0.698627663
##  [791]  0.884113817  0.806131006  0.849419492  0.930101626  0.892289901
##  [796]  0.924110763  0.836956565  0.932490731  0.804478775  0.725950005
##  [801]  0.625887548  0.773603406  0.949018539  0.659349775  0.946672164
##  [806]  0.952561927  0.793604170  0.835143922  0.773210200  0.820839307
##  [811]  0.801352105  0.739692227  0.829921308  0.950757911  0.756856483
##  [816]  0.939084256  0.740717546  0.810473730  0.829269718  0.833824315
##  [821]  0.629893681  0.784030438  0.813568214  0.609170329  0.842388030
##  [826]  0.907481375  0.818095360  0.953789296  0.623410448  0.655394406
##  [831]  0.664110201  0.707521050  0.721370348  0.965322324  0.817999754
##  [836]  0.667896415  0.733877164  0.930715769  0.944821273  0.911626023
##  [841]  0.783683317  0.978381799  0.940737138  0.769114100  0.765060761
##  [846]  0.914506121  0.626773573  0.934294659  0.914407761  0.924459767
##  [851]  0.628020623  0.937079808  0.813709202  0.669315815  0.878858871
##  [856]  0.787420906  0.916313067  0.819909433  0.719608193  0.702733951
##  [861]  0.638374801  0.917941655  0.812259786  0.939533022  0.792227172
##  [866]  0.930508388  0.814233394  0.897277817  0.933339692  0.967184575
##  [871]  0.729804009  0.762031585  0.969391417  0.694988387  0.824750178
##  [876]  0.833137664  0.978047106  0.819322943  0.903372409  0.912814991
##  [881]  0.840690068  0.665270156  0.679259998  0.713442928 -0.048411620
##  [886]  0.632615075  0.753316500  0.967381321  0.754247740  0.766767388
##  [891]  0.900957607  0.893376392  0.785686975  0.943271862  0.789950059
##  [896]  0.947029989  0.944872187  0.851607206  0.687539752  0.830435520
##  [901]  0.831961522  0.886102763  0.753003388  0.975038677  0.713906504
##  [906]  0.838997735  0.772872221  0.626684575  0.766587146  0.938467116
##  [911]  0.805875404  0.815829812  0.975486599  0.654713226  0.784743917
##  [916]  0.956253130  0.689170579  0.730570589  0.701384297  0.785760361
##  [921]  0.756250153  0.964206516  0.980487304  0.878247225  0.916107177
##  [926]  0.950044877  0.872473758  0.799284103  0.855208251  0.601687772
##  [931]  0.892457059  0.937195534  0.794466915  0.712514311  0.882409111
##  [936]  0.767108283  0.776401771  0.733726241  0.791553560  0.826020316
##  [941]  0.890926925  0.790482608  0.827570531  0.893330133  0.745704237
##  [946]  0.062712728  0.774501650  0.739521723  0.910724702  0.753130277
##  [951]  0.658603987  0.822269671  0.953123133  0.795986616  0.584159957
##  [956]  0.867166988  0.805724258  0.878017525  0.850878009  0.779521617
##  [961]  0.719248769  0.721812549  0.807364162  0.906325336  0.688426164
##  [966]  0.756727313  0.808120298  0.806576095  0.790605495  0.982882495
##  [971]  0.927099691  0.833901778  0.896455407  0.909085786  0.765901121
##  [976]  0.934353691  0.726976511  0.840346607  0.595033807  0.809538608
##  [981]  0.767859280  0.785208872  0.969852049  0.960242147  0.784860284
##  [986]  0.810376760  0.959416650  0.822423067  0.779982433  0.750933125
##  [991]  0.918162826  0.823485437  0.677178146  0.942307213  0.973410209
##  [996]  0.842286875  0.697967979  0.823612954  0.752918035  0.904962700

Exercise 17:

Compute the mean of the correlation coefficients of these 1000 bootstrap samples

mean(boot)
## [1] 0.816026

Exercise 18:

Use quantile() to compute an interval that encompasses 95% of the correlation coefficients of these 1000 bootstrap samples

quantile(boot,probs = c(.025,.975))
##      2.5%     97.5% 
## 0.6260371 0.9754909

Exercise 19:

Explain what the interval above means in terms of the likely correlation between the percent of the population deprived of ELECTRICITY and the percent deprived of SANITATION across all countries

We are 95% confident that the true correlation between people deprived of Elecetricity and people deprived of Sanitation across all countries is between .626 and .975.

Exercise 20:

Explain if the interval above implies that the percent of the population deprived of ELECTRICITY in each country has a significant and positive effect on the percent deprived of SANITATION

The interval above applies that the population of people deprived of Electricity in a country has a strong positvive effect on the population of people deprived of Sanitation. In fact with the interval going as high as .975 it would mean that an increase or decrease in one of the values would have almost the exact same effect on the other.