ASSIGNMENT 4, WFED 540

##  [1] "work"       "hoursw"     "child6"     "child618"   "agew"      
##  [6] "educw"      "hearnw"     "wagew"      "hoursh"     "ageh"      
## [11] "educh"      "wageh"      "income"     "educwm"     "educwf"    
## [16] "unemprate"  "city"       "experience"
##   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
## Warning in library(package, lib.loc = lib.loc, character.only = TRUE,
## logical.return = TRUE, : there is no package called 'corrlot'

1. Select four continuous variables from Mroz.

Mroz <- tbl_df(Mroz)
Mroz
## Source: local data frame [753 x 18]
## 
##      work hoursw child6 child618  agew educw hearnw wagew hoursh  ageh
##    (fctr)  (int)  (int)    (int) (int) (int)  (dbl) (dbl)  (int) (int)
## 1      no   1610      1        0    32    12 3.3540  2.65   2708    34
## 2      no   1656      0        2    30    12 1.3889  2.65   2310    30
## 3      no   1980      1        3    35    12 4.5455  4.04   3072    40
## 4      no    456      0        3    34    12 1.0965  3.25   1920    53
## 5      no   1568      1        2    31    14 4.5918  3.60   2000    32
## 6      no   2032      0        0    54    12 4.7421  4.70   1040    57
## 7      no   1440      0        2    37    16 8.3333  5.95   2670    37
## 8      no   1020      0        0    54    12 7.8431  9.98   4120    53
## 9      no   1458      0        2    48    12 2.1262  0.00   1995    52
## 10     no   1600      0        2    39    12 4.6875  4.15   2100    43
## ..    ...    ...    ...      ...   ...   ...    ...   ...    ...   ...
## Variables not shown: educh (int), wageh (dbl), income (int), educwm (int),
##   educwf (int), unemprate (dbl), city (fctr), experience (int)
roz <- Mroz %>%
  select(agew, income, hoursw, experience)
roz
## Source: local data frame [753 x 4]
## 
##     agew income hoursw experience
##    (int)  (int)  (int)      (int)
## 1     32  16310   1610         14
## 2     30  21800   1656          5
## 3     35  21040   1980         15
## 4     34   7300    456          6
## 5     31  27300   1568          7
## 6     54  19495   2032         33
## 7     37  21152   1440         11
## 8     54  18900   1020         35
## 9     48  20405   1458         24
## 10    39  20425   1600         21
## ..   ...    ...    ...        ...

2. Estimate Pearson Product-Moment Correlations for four pairs of variables.

## $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.

Alpha = .05

The p-value from the p-value table show that all the values are less than alpha except that for the hoursw and agew which means there is a coorelation only between these two variables (hoursw and income)

so, we reject the null hypthesise that there is no correlation except between these variable hoursw and income.

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

require (ggvis)
## Loading required package: ggvis
require (magrittr)
## Loading required package: magrittr
roz %>%
  ggvis (x=~hoursw, y= ~experience) %>%
  layer_points() %>%
  layer_smooths()

roz %>%
  ggvis (x=~hoursw, y= ~agew) %>%
  layer_points() %>%
  layer_smooths()

roz %>%
  ggvis (x=~hoursw, y= ~income) %>%
  layer_points() %>%
  layer_smooths()

roz %>%
  ggvis (x=~experience, y= ~income) %>%
  layer_points() %>%
  layer_smooths()

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

require(corrgram)
## Loading required package: corrgram
cor.roz <- cor(roz)
corrgram (cor.roz, upper.panel= NULL)

cormat<-rquery.cormat(roz, graphType="heatmap")