#Title: Assignment 4 for WFED540
#Author: Andrew Leigey
#Date: 11/19/15
#Output: html_document


# ************************************
#  ASSIGNMENT 4, WFED 540            *
# ************************************

# ************************************
# READING Mroz Labor Supply Dataset  *
# from Ecdat Package                 *
#                                    *
# The Mroz dataset contains 753      *
# observations of individuals in the *
# United States. The code below      *
# installs the Ecdat package         *
# containing the Mroz dataset, loads *
# Ecdat, accesses the Mroz dataset,  *
# lists the names of variables in    *
# Mroz dataset, and summarizes each  *
# variable in the Mroz dataset. Mroz *
# variables do not include missing   *
# data. Your entry of the command,   *
# "?Mroz", displays documentation    *
# for the Mroz dataset.              *
# ************************************


require(Ecdat)
## Loading required package: Ecdat
## Loading required package: Ecfun
## 
## Attaching package: 'Ecdat'
## 
## The following object is masked from 'package:datasets':
## 
##     Orange
data(Mroz)
names(Mroz)
##  [1] "work"       "hoursw"     "child6"     "child618"   "agew"      
##  [6] "educw"      "hearnw"     "wagew"      "hoursh"     "ageh"      
## [11] "educh"      "wageh"      "income"     "educwm"     "educwf"    
## [16] "unemprate"  "city"       "experience"
summary(Mroz)
##   work         hoursw           child6          child618    
##  yes:325   Min.   :   0.0   Min.   :0.0000   Min.   :0.000  
##  no :428   1st Qu.:   0.0   1st Qu.:0.0000   1st Qu.:0.000  
##            Median : 288.0   Median :0.0000   Median :1.000  
##            Mean   : 740.6   Mean   :0.2377   Mean   :1.353  
##            3rd Qu.:1516.0   3rd Qu.:0.0000   3rd Qu.:2.000  
##            Max.   :4950.0   Max.   :3.0000   Max.   :8.000  
##       agew           educw           hearnw           wagew     
##  Min.   :30.00   Min.   : 5.00   Min.   : 0.000   Min.   :0.00  
##  1st Qu.:36.00   1st Qu.:12.00   1st Qu.: 0.000   1st Qu.:0.00  
##  Median :43.00   Median :12.00   Median : 1.625   Median :0.00  
##  Mean   :42.54   Mean   :12.29   Mean   : 2.375   Mean   :1.85  
##  3rd Qu.:49.00   3rd Qu.:13.00   3rd Qu.: 3.788   3rd Qu.:3.58  
##  Max.   :60.00   Max.   :17.00   Max.   :25.000   Max.   :9.98  
##      hoursh          ageh           educh           wageh        
##  Min.   : 175   Min.   :30.00   Min.   : 3.00   Min.   : 0.4121  
##  1st Qu.:1928   1st Qu.:38.00   1st Qu.:11.00   1st Qu.: 4.7883  
##  Median :2164   Median :46.00   Median :12.00   Median : 6.9758  
##  Mean   :2267   Mean   :45.12   Mean   :12.49   Mean   : 7.4822  
##  3rd Qu.:2553   3rd Qu.:52.00   3rd Qu.:15.00   3rd Qu.: 9.1667  
##  Max.   :5010   Max.   :60.00   Max.   :17.00   Max.   :40.5090  
##      income          educwm           educwf         unemprate     
##  Min.   : 1500   Min.   : 0.000   Min.   : 0.000   Min.   : 3.000  
##  1st Qu.:15428   1st Qu.: 7.000   1st Qu.: 7.000   1st Qu.: 7.500  
##  Median :20880   Median :10.000   Median : 7.000   Median : 7.500  
##  Mean   :23081   Mean   : 9.251   Mean   : 8.809   Mean   : 8.624  
##  3rd Qu.:28200   3rd Qu.:12.000   3rd Qu.:12.000   3rd Qu.:11.000  
##  Max.   :96000   Max.   :17.000   Max.   :17.000   Max.   :14.000  
##   city       experience   
##  no :269   Min.   : 0.00  
##  yes:484   1st Qu.: 4.00  
##            Median : 9.00  
##            Mean   :10.63  
##            3rd Qu.:15.00  
##            Max.   :45.00
# ************************************
# Assignment 4                       *
# ************************************

require(ggvis)
## Loading required package: ggvis
require(corrplot)
## Loading required package: corrplot
require(dplyr)
## Loading required package: dplyr
## 
## Attaching package: 'dplyr'
## 
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
require(knitr)
## Loading required package: knitr
require(rmarkdown)
## Loading required package: rmarkdown
# 1. Select four continuous variables from Mroz.

Mroz4var<-Mroz%>% select(hoursw, agew, income, experience)
Mroz4var
##     hoursw agew income experience
## 1     1610   32  16310         14
## 2     1656   30  21800          5
## 3     1980   35  21040         15
## 4      456   34   7300          6
## 5     1568   31  27300          7
## 6     2032   54  19495         33
## 7     1440   37  21152         11
## 8     1020   54  18900         35
## 9     1458   48  20405         24
## 10    1600   39  20425         21
## 11    1969   33  32300         15
## 12    1960   42  28700         14
## 13     240   30  15500          0
## 14     997   43  16860         14
## 15    1848   43  31431          6
## 16    1224   35  19180          9
## 17    1400   43  18600         20
## 18     640   39  19151          6
## 19    2000   45  18100         23
## 20    1324   35  20300          9
## 21    2215   42  30419          5
## 22    1680   30  14090         11
## 23    1600   48  22679         18
## 24     800   45  12160         15
## 25    1955   31  12487          4
## 26     660   43  29850         21
## 27     525   59  18100         31
## 28    1904   32  26000          9
## 29    1516   31  26100          7
## 30     346   42  17730          7
## 31    1040   50   6719         32
## 32     732   59  18550         11
## 33    1880   36  24600         16
## 34    1680   51  23100         14
## 35    2081   45  24656         27
## 36     690   42  15897          0
## 37    4210   46  20320         17
## 38    2205   46  21384         28
## 39    1952   51  25561         24
## 40    1302   30  36550         11
## 41     112   30  15810          1
## 42     893   57  25500         14
## 43     583   31  24000          6
## 44     480   48  22172         10
## 45    1900   30  17930          6
## 46     576   34   7000          4
## 47    2056   48  25300         10
## 48    1984   45  16212         22
## 49    2640   51  22650         16
## 50     240   30   6985          6
## 51    1173   46  30000         12
## 52    3640   58  18500         32
## 53     340   37  16658         15
## 54     500   52  10300         17
## 55    1599   52  11000         34
## 56    1830   31  19900          9
## 57    1920   55  32500         37
## 58    2052   34  37300         10
## 59    2312   55  30018         35
## 60     196   39  12807          6
## 61    2500   40  39500         19
## 62    1980   43  22050         10
## 63    1840   48  15500         11
## 64     320   47  13810         15
## 65     419   41  11950         12
## 66    1880   36  19175         12
## 67      72   46  17900         14
## 68     120   34  15850         11
## 69    1885   41  27017          9
## 70     240   51  18900         24
## 71    1729   33  21800         12
## 72    1850   52  33552         13
## 73    2033   58  22650         29
## 74     608   34  15200         11
## 75    1153   31  13120         13
## 76    2208   48  21660         19
## 77     252   32  18190          2
## 78     337   49   9600         24
## 79      90   32  13755          9
## 80    1174   58  35350          6
## 81     372   50  12405         22
## 82      30   60  12180         30
## 83    1800   50  22962         10
## 84     282   56  25700          6
## 85     720   51   3305         29
## 86    1440   54  32950         29
## 87    2100   59  17000         36
## 88    1000   46  13250         19
## 89     952   46  50750          8
## 90    1413   39  15632         13
## 91    2100   44  28316         16
## 92     120   33  17290         11
## 93    3000   33  33600         15
## 94    1000   48  29200          6
## 95     336   31  19870         13
## 96    1216   45  16225         22
## 97     988   45  28600         24
## 98    2581   32  30800          2
## 99    2030   47  25700          6
## 100    413   34  27000          2
## 101    782   37  12077          2
## 102   1388   36  29612         14
## 103   1450   47  24479          9
## 104   1720   48  79750         11
## 105    800   42  20050          9
## 106    360   33  21500          6
## 107   2000   46  16120         19
## 108   1176   47  24686         26
## 109   2058   44  24669         19
## 110    900   36  26400          3
## 111    215   31  16245          7
## 112   2000   55  23300         28
## 113    757   45  27200         13
## 114   1264   47  51000          9
## 115   2064   46  55000         15
## 116   1280   49  15389         20
## 117   1715   49  23150         29
## 118   2000   45  29774          9
## 119     12   38  91044          1
## 120   1528   47  28200          8
## 121    561   54  36150         19
## 122   2058   41  15652         23
## 123   1823   43  18900          3
## 124   1680   31  23600         13
## 125   1440   47  36200          8
## 126   4950   35  18700         17
## 127   1176   45  24125          4
## 128   1100   33  15800         15
## 129   1516   54  19742         11
## 130    900   35  22600          7
## 131   1080   31  17500          0
## 132    480   55  19820          0
## 133    288   34  20155         10
## 134   1875   38  37300          8
## 135    630   45  24860          2
## 136    234   47  21450          4
## 137   1600   39  29650          6
## 138    960   36  23000         18
## 139    120   33  21120          3
## 140   2025   50  26000         22
## 141   1809   58  28000         33
## 142   3087   49  45500         28
## 143    910   41  16000         23
## 144   1840   51  18232         27
## 145    784   53  28160         11
## 146    400   36   5965          6
## 147   1000   46  19000         11
## 148   1904   36  36872         14
## 149   1771   53  42000         17
## 150   1486   40  26900         17
## 151    740   42  30800         14
## 152   1820   33  21520         11
## 153   1275   43  24795          7
## 154    450   31  12900          8
## 155   1221   47  42700          6
## 156   1550   54  38800          8
## 157    180   33   2500          4
## 158   2090   43  26921         25
## 159   1960   46  18300         24
## 160   1440   35  17200         11
## 161    794   37  14209         19
## 162    993   37  32300          9
## 163    160   34  21400         19
## 164    105   43  14700         14
## 165   1200   46  25516         22
## 166    450   35  13300          6
## 167    996   46  31000         23
## 168   1052   46  48800         15
## 169   1128   43  15519          6
## 170   1840   30  19500         11
## 171   1910   41  14545          2
## 172    980   54  22897         22
## 173   2317   31  14300         10
## 174   1089   44  14884         14
## 175    800   32  27400         12
## 176   1230   47  16400          9
## 177   1158   46  25704         13
## 178   2272   37  12800         18
## 179    528   51  40000          8
## 180   1000   49  47000         11
## 181    520   36  25872          9
## 182    760   39  26868          9
## 183   1920   48  18000         14
## 184   1220   38  30200          9
## 185    200   40  26220          2
## 186   2480   39  40500         12
## 187   2750   37  33570         15
## 188   2014   49  16917         11
## 189   1355   33  18000          7
## 190     80   30   8337          9
## 191   1670   54  17100         19
## 192    520   39  17800         11
## 193    288   43  13740          8
## 194   2014   31  27000         13
## 195    800   33  32600          4
## 196   1984   40  28030          7
## 197   1823   36  23100         19
## 198   1500   51  24580         14
## 199   2261   44  29000         14
## 200   1728   42  42430          3
## 201   1960   40  41800          9
## 202   1578   34  39100          7
## 203   1316   30  31800          7
## 204   1530   54  22200         14
## 205   2220   51  19500         29
## 206   1336   44  14027         19
## 207   1008   43  21195         14
## 208   1944   34  19013         16
## 209   2000   45  20900         10
## 210    258   39  26820         12
## 211   1785   50  12800         24
## 212    480   52   7850          6
## 213    772   41  18600          9
## 214    900   59   5380         14
## 215   1428   52   6114         26
## 216    210   46   8234          7
## 217    239   41  20646          4
## 218   1878   33  16640         15
## 219    215   45  13900         23
## 220   2340   36  11500          1
## 221   1960   48  34000         29
## 222    532   47  28700          9
## 223    394   45   9563          6
## 224    675   37  20960         11
## 225   1515   46  38590         17
## 226   1030   43  27900          6
## 227   1250   42  25633          7
## 228   1158   34  35200          2
## 229    112   52  29500         24
## 230    336   37  10000          4
## 231   1984   37  19800         11
## 232    716   52  12900         25
## 233   1410   30  26080         11
## 234   1300   31  13066          2
## 235   1640   38  12500         19
## 236   1202   43  35600          7
## 237    489   49  19424          2
## 238   2076   55  26250         20
## 239    526   38  36525         10
## 240   1721   52  34700         19
## 241   1327   48   8311         17
## 242    584   32  28626         12
## 243   1376   32  24400         11
## 244   1040   38  14025          6
## 245    548   46  21367         10
## 246     15   40  14136          4
## 247   1980   31  19900          2
## 248   1520   43  37000         13
## 249   1880   51  18500         21
## 250   1260   30  34550          9
## 251   1092   52  49620          4
## 252   1587   30  10400          2
## 253    156   51  33000         19
## 254   1939   31  16200          4
## 255   1250   34  22660          9
## 256    610   49  16000         14
## 257    270   35  25780          6
## 258    660   53  20675         24
## 259   1000   32  40213          1
## 260   1920   38  15500         13
## 261    200   54  35207          3
## 262   1500   47  35702         10
## 263    868   45  17800         16
## 264   2318   47  50900          9
## 265   2000   59  17280         19
## 266     60   32  15150          4
## 267   1715   45  36200         10
## 268    550   40  17465          5
## 269   1960   47  45205          7
## 270     44   36  14500          3
## 271   1920   56  32011         38
## 272   2540   41  35200         16
## 273    156   48  13579         13
## 274    780   36  10455          1
## 275   3120   41  32600          7
## 276   2040   41  19150         15
## 277   1610   36  24400         10
## 278    215   37  21700          2
## 279   1120   38  26201         19
## 280    846   43  11920         25
## 281   3225   54  16300         25
## 282   1376   38  16500          7
## 283    980   30  30000         15
## 284   1838   49  62500         11
## 285   1494   45  58500         25
## 286    450   51  40900         19
## 287   1976   34  16308          4
## 288   2012   34   9300         14
## 289    561   41  35700         19
## 290   1715   49  35700         18
## 291   1912   32  24500         14
## 292   3686   32  13000         11
## 293   1080   32  52600          4
## 294   1799   47  25360         29
## 295   1984   39   9400         21
## 296   1839   49  26800         24
## 297   1579   37  33040         19
## 298     96   59  26350         31
## 299   1920   50  39000         28
## 300   1688   32  35100         15
## 301   1589   46  22502         27
## 302    345   43  21950         13
## 303   1521   37  13000          4
## 304   1490   32  18180         10
## 305    989   39  20957          8
## 306    600   34  13700          4
## 307   2646   39  20000         18
## 308   2149   45  12260          3
## 309    320   50  24850         11
## 310   1600   40  29150          8
## 311   2419   30  23591         10
## 312   2005   57  24717         33
## 313   1960   39  30455         19
## 314   2147   53  19600         35
## 315   1207   48  31875         21
## 316   2000   46  24055          7
## 317   1260   47  18795         18
## 318     90   43  12198          4
## 319   1800   47  52645         12
## 320    573   47  16600         16
## 321   1825   47  32590         14
## 322     75   46  10020          3
## 323   1348   34  12048          1
## 324   1880   48  39750         27
## 325   1240   30  15700         12
## 326    848   51  24250          6
## 327    150   52  43210          9
## 328   2000   37  37100          2
## 329   1952   32  23820          6
## 330   1456   36  31600          9
## 331   1740   35  24000         16
## 332   1400   45  30750         22
## 333   2000   56  11050         26
## 334   1750   40  12239         11
## 335   1101   45  12870         11
## 336   2000   32  17200         15
## 337   1877   45  23980         13
## 338    160   40  18600          6
## 339   1886   38  23920         20
## 340   1446   49  16084         17
## 341   1500   47  31100          8
## 342    860   52  20460         13
## 343   1848   34  36000         15
## 344   1678   44  17302         14
## 345    160   36  16450         14
## 346    108   50  41170          6
## 347   1738   45  20130         24
## 348   1170   44   9200         10
## 349     15   57  24751          2
## 350   2088   35  57300          9
## 351   2490   46  37200         23
## 352    135   30  14000         12
## 353   1944   42  20610          8
## 354    690   34  14800         16
## 355    608   45  40005         10
## 356     63   35  23750          7
## 357    154   40  35300         19
## 358    420   32  17350          2
## 359    651   54  21650          9
## 360    675   38   6740         14
## 361   1663   43  32275          9
## 362   1680   54  33220         16
## 363    180   39  26500          7
## 364   1581   37  38700          6
## 365   1200   46  15400         22
## 366    450   56  19007          9
## 367    547   41  16771          9
## 368    300   45  31100         14
## 369    975   44  66300         17
## 370   1621   50  43550         12
## 371    300   37  37250         13
## 372   1868   44  24900          8
## 373   1803   32  24200         10
## 374   2143   34  16200         16
## 375   1080   32  11431          1
## 376   1352   37  13200          6
## 377    537   44  15420          4
## 378    352   34  18400          8
## 379    200   33  43500          4
## 380   2045   43  21972         15
## 381   1253   35   7774          7
## 382   1960   43  24470         14
## 383   2000   34  13600         16
## 384   1960   36  22500         15
## 385   2000   41  13600         23
## 386   1568   41  90800         19
## 387   1225   35  10776          4
## 388    780   32  19007         12
## 389    480   30  23900         12
## 390   1923   43  26060         25
## 391   2000   54  13300         14
## 392   2110   35  15620         14
## 393   1664   50  16500         11
## 394     48   34  20880          7
## 395   1791   52  30600         18
## 396   1404   35  39000          4
## 397   1920   55  15428         37
## 398   2141   35  23300         13
## 399   1720   49  42100         14
## 400   3533   38  36430         17
## 401   2000   42  26000          5
## 402    800   48  62060          2
## 403   3000   51  28300          0
## 404    293   43  24149          3
## 405   1872   43  28141         21
## 406   2058   38  23057         20
## 407   1832   44  28900         19
## 408    120   36  24000          4
## 409   1632   38  13900         19
## 410    778   47  31810         11
## 411   1984   34  19840         14
## 412    225   40  25490          8
## 413   1960   31  20800         13
## 414    444   46   2400         24
## 415    384   36  32650          1
## 416   1170   39  16370          1
## 417   1330   36  35500          3
## 418   1350   37  15100          4
## 419    480   39  14100         21
## 420   1984   36  19600         10
## 421   1944   49  19434         13
## 422     50   45  23882          9
## 423    460   32  17300         14
## 424    680   36  19772          2
## 425   2450   40  35641         21
## 426   2144   43  34220         22
## 427   1760   33  30000         14
## 428    490   30  18000          7
## 429      0   49  21025          2
## 430      0   30  23600          5
## 431      0   30  22800         12
## 432      0   41  35910          1
## 433      0   45  21700         12
## 434      0   43  21823          4
## 435      0   42  31000          9
## 436      0   60  15300          9
## 437      0   57  12925          6
## 438      0   38  15830          5
## 439      0   56  30200          5
## 440      0   32  16600          8
## 441      0   49  11000          2
## 442      0   55  15000          6
## 443      0   36  20528          0
## 444      0   44  13126          3
## 445      0   44  15550          7
## 446      0   35  18010          3
## 447      0   44  18874         10
## 448      0   45  24800          3
## 449      0   34  17500          2
## 450      0   30  16150         12
## 451      0   39  15189         15
## 452      0   36   6000          5
## 453      0   38  37250          4
## 454      0   53  27760         10
## 455      0   36   9090          1
## 456      0   32  14500          8
## 457      0   51  19700         20
## 458      0   38  16788          4
## 459      0   33  18520          7
## 460      0   54  20950         10
## 461      0   38   7574          3
## 462      0   30  10027          5
## 463      0   34   5000         10
## 464      0   34   7040          0
## 465      0   50  40800          3
## 466      0   30  16050         10
## 467      0   38  33100          2
## 468      0   54  33856         10
## 469      0   30  20500          4
## 470      0   55  28600          0
## 471      0   51  18750         10
## 472      0   44  20300          5
## 473      0   53  13420          0
## 474      0   42  18400          0
## 475      0   38  16682         19
## 476      0   38  32685          2
## 477      0   41   7050         12
## 478      0   35  10867          5
## 479      0   33  18220          5
## 480      0   48  26613          5
## 481      0   47  25000         10
## 482      0   34  15700          0
## 483      0   33  40250          4
## 484      0   31  73600          3
## 485      0   58  10592          2
## 486      0   49   8000          1
## 487      0   55  13400          0
## 488      0   44  23700          1
## 489      0   44  18900          1
## 490      0   36  48300          6
## 491      0   38  24470         12
## 492      0   37  28630          6
## 493      0   47  25320          9
## 494      0   47  13530         14
## 495      0   32  14800         13
## 496      0   43  17400          8
## 497      0   42  15980          0
## 498      0   56  16576          1
## 499      0   38  21850          3
## 500      0   52  14600         13
## 501      0   50  21600          3
## 502      0   33  24000          8
## 503      0   44  20883          8
## 504      0   41  19500         18
## 505      0   45  42800          2
## 506      0   53  41500          3
## 507      0   53  18965          5
## 508      0   42  16100          2
## 509      0   32  14700         10
## 510      0   56  18800         30
## 511      0   37  14750          1
## 512      0   40  21000          5
## 513      0   54  35400          8
## 514      0   53  10700          0
## 515      0   48  24500          4
## 516      0   36  17045          2
## 517      0   57  18800         30
## 518      0   51  14000         25
## 519      0   33  18214          3
## 520      0   52  20177         20
## 521      0   56   8300         20
## 522      0   36  14200          0
## 523      0   36  21768         15
## 524      0   46  29553         10
## 525      0   31   4350          4
## 526      0   52  24000          3
## 527      0   46  18300         10
## 528      0   35  17200          9
## 529      0   59  16476          7
## 530      0   36  13400         12
## 531      0   51  44988          0
## 532      0   31  18200         16
## 533      0   31  28000          4
## 534      0   32  11550          7
## 535      0   35  28450          7
## 536      0   40  15096         14
## 537      0   33   8009          2
## 538      0   54  10040         20
## 539      0   36  16700          5
## 540      0   50   8400         10
## 541      0   54  13000         20
## 542      0   48  17970         10
## 543      0   41  18450          8
## 544      0   50  31000         11
## 545      0   46  24135          3
## 546      0   42  31700          6
## 547      0   31  10190          4
## 548      0   53  21574          4
## 549      0   51  26680          9
## 550      0   47  17700         10
## 551      0   50  29400          3
## 552      0   37  22159          2
## 553      0   30  35000          2
## 554      0   49   8630          0
## 555      0   52  17080          8
## 556      0   47  32500          6
## 557      0   49  16000         15
## 558      0   44  18850         15
## 559      0   53  17500          9
## 560      0   30  19392          8
## 561      0   54  14450         18
## 562      0   47  21800          3
## 563      0   56   7700         10
## 564      0   49  31800          6
## 565      0   48  17258         20
## 566      0   49  13399          8
## 567      0   56  16073          3
## 568      0   46  23260          4
## 569      0   45  37300         13
## 570      0   32  11000          4
## 571      0   43  13075         17
## 572      0   34  13700          4
## 573      0   30  25100          0
## 574      0   38  18600         15
## 575      0   33  29000         11
## 576      0   52  19237         23
## 577      0   43  19855          1
## 578      0   33   9450          5
## 579      0   45  30000          1
## 580      0   36  15000          5
## 581      0   34  24701          3
## 582      0   37  15900          3
## 583      0   46  16240         19
## 584      0   47  21100         20
## 585      0   31  23000          5
## 586      0   57   6340          0
## 587      0   30  42250          3
## 588      0   30  14694          3
## 589      0   44  21417          7
## 590      0   53  20200          7
## 591      0   51  12090          1
## 592      0   39  24760         13
## 593      0   52  23000          0
## 594      0   46  19365          0
## 595      0   47   5550         12
## 596      0   52  68035          0
## 597      0   45  29300          5
## 598      0   60  18500         45
## 599      0   41  22582         10
## 600      0   39  21500          2
## 601      0   49  28070          3
## 602      0   32  50300          1
## 603      0   33  23500          5
## 604      0   36  15500         10
## 605      0   37  13440          4
## 606      0   30   8100          7
## 607      0   44   9800          9
## 608      0   48  20300          5
## 609      0   40  15000          4
## 610      0   47  56100         11
## 611      0   36  22846          9
## 612      0   40  22225          4
## 613      0   46  17635          2
## 614      0   52  18500         23
## 615      0   44  13390          3
## 616      0   45  15150         15
## 617      0   30  16200          8
## 618      0   40  33920          3
## 619      0   43  14000         25
## 620      0   49  16736          2
## 621      0   46  30650          0
## 622      0   52  12400         19
## 623      0   31  19022          3
## 624      0   42  11203          7
## 625      0   33  19876          1
## 626      0   57  57000          9
## 627      0   49  18290          3
## 628      0   45  20220          8
## 629      0   56  22150          0
## 630      0   41  30623          5
## 631      0   56   9380         20
## 632      0   48  22000          3
## 633      0   52  23675         12
## 634      0   51  33671          5
## 635      0   35  12367          1
## 636      0   45  21950          0
## 637      0   54  32000          7
## 638      0   54  22610         13
## 639      0   31  12092          3
## 640      0   53   3777          0
## 641      0   35  36000          2
## 642      0   36  26900          0
## 643      0   59  32242          2
## 644      0   54  35020          1
## 645      0   37  37600         10
## 646      0   44   1500         10
## 647      0   34  96000          1
## 648      0   49  18150          3
## 649      0   49  15500         32
## 650      0   60  14000          0
## 651      0   51  14756          7
## 652      0   30  22000          5
## 653      0   47  24466          2
## 654      0   36  24400          5
## 655      0   35  24000          3
## 656      0   58  15500         25
## 657      0   41  30800          0
## 658      0   51  10660          3
## 659      0   47  13350         10
## 660      0   45  10090         10
## 661      0   60  55600          7
## 662      0   30  25700          5
## 663      0   55  29000         15
## 664      0   32   7286          1
## 665      0   36  37752          5
## 666      0   55  13072          9
## 667      0   47   7044         18
## 668      0   47  18200          1
## 669      0   37  27000          0
## 670      0   50  30300          6
## 671      0   30  12000          1
## 672      0   48  31500          2
## 673      0   43  27092         15
## 674      0   48  20968         25
## 675      0   41  27000          1
## 676      0   50  11225          0
## 677      0   58  37700          0
## 678      0   38  28200          0
## 679      0   37  34000          8
## 680      0   50  63200         22
## 681      0   42   7500          5
## 682      0   37  17410         10
## 683      0   41  51000          1
## 684      0   31  12916          1
## 685      0   51  21900          6
## 686      0   36  17640          4
## 687      0   54  20000          6
## 688      0   49  15000          0
## 689      0   48  14060          1
## 690      0   42  15825          3
## 691      0   41  16510         15
## 692      0   55  13000         33
## 693      0   42  10000          2
## 694      0   32  22000          1
## 695      0   43  29800         10
## 696      0   33  15000          0
## 697      0   48  22300         14
## 698      0   43  14550         15
## 699      0   47  19730         15
## 700      0   54  35000         10
## 701      0   51  21014          6
## 702      0   51  10876         18
## 703      0   43  27850         15
## 704      0   53   9560         30
## 705      0   34  30300         15
## 706      0   31   7720         10
## 707      0   56  10550          0
## 708      0   42  24106          0
## 709      0   32  22995          4
## 710      0   35   6000          0
## 711      0   30  24350          3
## 712      0   51   7608         20
## 713      0   47  28200          3
## 714      0   54  16150          1
## 715      0   31  51200          5
## 716      0   47  12646          7
## 717      0   47  19000          6
## 718      0   40  19000          2
## 719      0   48  14400          0
## 720      0   34   7232         10
## 721      0   38  21943          6
## 722      0   32  47500          4
## 723      0   48  28900          8
## 724      0   41  12400         18
## 725      0   49   6531          7
## 726      0   59  22422         15
## 727      0   58  22200          7
## 728      0   41  77000          8
## 729      0   45  88000          8
## 730      0   30  26040          3
## 731      0   41  63500         10
## 732      0   30  12100          9
## 733      0   53  17505         24
## 734      0   31  18000         12
## 735      0   43  28069          2
## 736      0   31  14000          6
## 737      0   51   8117         18
## 738      0   43  11895         17
## 739      0   31  45250          7
## 740      0   48  31106          6
## 741      0   31   4000         10
## 742      0   44  40500          5
## 743      0   48  21620          7
## 744      0   53  23426         11
## 745      0   42  26000         14
## 746      0   39   7840          5
## 747      0   32   6800          2
## 748      0   36   5330          4
## 749      0   40  28200          5
## 750      0   31  10000         14
## 751      0   43   9952          4
## 752      0   60  24984         15
## 753      0   39  28363         12
# 2. Estimate Pearson Product-Moment Correlations
#    for four pairs of variables.
# Load the cormat functions
# Loaded this way because the cormat
# package is not available (for R version 3.2.2).
source("http://www.sthda.com/upload/rquery_cormat.r")

rquery.cormat(Mroz4var)
## $r
##            hoursw experience  agew income
## hoursw          1                        
## experience    0.4          1             
## agew       -0.033       0.33     1       
## income       0.15     -0.028 0.052      1
## 
## $p
##             hoursw experience agew income
## hoursw           0                       
## experience       0          0            
## agew          0.36          0    0       
## income     5.6e-05       0.45 0.15      0
## 
## $sym
##            hoursw experience agew income
## hoursw     1                            
## experience .      1                     
## agew              .          1          
## income                            1     
## attr(,"legend")
## [1] 0 ' ' 0.3 '.' 0.6 ',' 0.8 '+' 0.9 '*' 0.95 'B' 1
# 3. Test null hypotheses that the population
#    correlations = 0 for the four pairs of
#    variables you selected.


#The null hypotheses is that the four pairs of variables selected will have 
#correlations of zero for all the correlation coefficients tested.  Therefore,
# since none of the correlation coefficients equal zero then we must reject the null
#hypotheses that there is no correlation between the four pairs of variables we 
#selected.  Instead we must accept the alternative hypotheses that there is a
#correlation between all the four pairs of variables selected, even though some of 
#the relations are small in size. 


# 4. Using ggvis, plot scatterplots containing
#    points and a smooth line for the four pairs of
#    variable you selected.

require(ggvis)

#experience and hoursw scatterplots and smooth line
Mroz4var%>%ggvis(~experience, ~hoursw)%>%layer_points()%>%layer_smooths()

#experience and agew scatterplots and smooth line
Mroz4var%>%ggvis(~experience, ~agew)%>%layer_points()%>%layer_smooths()

#income and hoursw scatterplots and smooth line
Mroz4var%>%ggvis(~income, ~hoursw)%>%layer_points()%>%layer_smooths()

#income and agew scatterplots and smooth line
Mroz4var%>%ggvis(~income, ~agew)%>%layer_points()%>%layer_smooths()

# 5. Produce correlograms and heat maps for the
#    four pairs of variables you selected.

#correlogram
rquery.cormat(Mroz4var)

## $r
##            hoursw experience  agew income
## hoursw          1                        
## experience    0.4          1             
## agew       -0.033       0.33     1       
## income       0.15     -0.028 0.052      1
## 
## $p
##             hoursw experience agew income
## hoursw           0                       
## experience       0          0            
## agew          0.36          0    0       
## income     5.6e-05       0.45 0.15      0
## 
## $sym
##            hoursw experience agew income
## hoursw     1                            
## experience .      1                     
## agew              .          1          
## income                            1     
## attr(,"legend")
## [1] 0 ' ' 0.3 '.' 0.6 ',' 0.8 '+' 0.9 '*' 0.95 'B' 1
#heatmap
cormat<-rquery.cormat(Mroz4var, graphType="heatmap")

# 6. Create an RMarkdown .Rmd file that documents the
#    processes and outcomes for steps (1) through (5).
# 7. Create an RPubs html site from your .Rmd file.
# 8. In a private Piazza message to your instructors,
#    post the URL to your RPubs file and upload your
#    .Rmd file.

```