1. Select four continuous variables from Mroz.
require(Ecdat)
## Loading required package: Ecdat
## Loading required package: Ecfun
## 
## Attaching package: 'Ecdat'
## 
## The following object is masked from 'package:datasets':
## 
##     Orange
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
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
Mroz <- tbl_df(Mroz)
morz <- Mroz %>% select(hoursh, income, experience, wageh)
morz
## Source: local data frame [753 x 4]
## 
##    hoursh income experience   wageh
## 1    2708  16310         14  4.0288
## 2    2310  21800          5  8.4416
## 3    3072  21040         15  3.5807
## 4    1920   7300          6  3.5417
## 5    2000  27300          7 10.0000
## 6    1040  19495         33  6.7106
## 7    2670  21152         11  3.4277
## 8    4120  18900         35  2.5485
## 9    1995  20405         24  4.2206
## 10   2100  20425         21  5.7143
## ..    ...    ...        ...     ...
  1. Estimate Pearson Product-Moment Correlations for four pairs of variables.
source("http://www.sthda.com/upload/rquery_cormat.r")
rquery.cormat(morz) 

## $r
##            income wageh hoursh experience
## income          1                        
## wageh        0.73     1                  
## hoursh       0.13 -0.24      1           
## experience -0.028  -0.1 -0.099          1
## 
## $p
##             income   wageh hoursh experience
## income           0                          
## wageh            0       0                  
## hoursh     0.00042 5.4e-11      0           
## experience    0.45  0.0045 0.0064          0
## 
## $sym
##            income wageh hoursh experience
## income     1                             
## wageh      ,      1                      
## hoursh                  1                
## experience                     1         
## attr(,"legend")
## [1] 0 ' ' 0.3 '.' 0.6 ',' 0.8 '+' 0.9 '*' 0.95 'B' 1
  1. Test null hypotheses that the population correlations = 0 for the four pairs of variables you selected.

If alpha = .05, the table of p-value indicates that the p-values are less than alpha except for the p-value between income and experience. Therefore, we reject the null hypothesis that there are no correlations except for the pair of income and experience.

  1. 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
morz %>%
  ggvis(x = ~wageh, y = ~income) %>%
  layer_points() %>% layer_smooths()

morz %>%
  ggvis(x = ~hoursh, y = ~income) %>%
  layer_points() %>% layer_smooths()

morz %>%
  ggvis(x = ~wageh, y = ~hoursh) %>%
  layer_points() %>% layer_smooths()

morz %>%
  ggvis(x = ~wageh, y = ~experience) %>%
  layer_points() %>% layer_smooths()

  1. Produce correlograms and heat maps for the four pairs of variables you selected.
require(corrgram)
## Loading required package: corrgram
cor.morz<-cor(morz)
corrgram(cor.morz, upper.panel = NULL)

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