First I installed the necessary packages.
I selected four continuous variables from Mroz. The variables are agew, educw, hoursw, and wagew.
contvar <- Mroz %>%
select(hoursw, agew, educw, wagew)
tbl_df (contvar)
## Source: local data frame [753 x 4]
##
## hoursw agew educw wagew
## 1 1610 32 12 2.65
## 2 1656 30 12 2.65
## 3 1980 35 12 4.04
## 4 456 34 12 3.25
## 5 1568 31 14 3.60
## 6 2032 54 12 4.70
## 7 1440 37 16 5.95
## 8 1020 54 12 9.98
## 9 1458 48 12 0.00
## 10 1600 39 12 4.15
## .. ... ... ... ...
Then I estimated Pearson Product-Moment Correlations for four pairs of variables. I loaded the cormat functions.
## $r
## agew educw hoursw wagew
## agew 1
## educw -0.12 1
## hoursw -0.033 0.11 1
## wagew -0.058 0.27 0.61 1
##
## $p
## agew educw hoursw wagew
## agew 0
## educw 0.00095 0
## hoursw 0.36 0.0036 0
## wagew 0.11 8.2e-14 0 0
##
## $sym
## agew educw hoursw wagew
## agew 1
## educw 1
## hoursw 1
## wagew , 1
## attr(,"legend")
## [1] 0 ' ' 0.3 '.' 0.6 ',' 0.8 '+' 0.9 '*' 0.95 'B' 1
Next, I tested the null hypotheses that the population correlations = 0 for the four pairs of variables I selected.
The null hypothesis is that there is no correlation between agew, educw, hoursw, and wagew. The alpha is equal to 0.05. I would reject the null hypothesis that there is no correlation between educw and hoursw as well as educw and wagew because the p-value is less than 0.05. However, I would fail to reject the null hypothesis that there is no correlation between hourw and agew, agew and wagew because the p-value is greater than alpha.
Then, I Used ggvis to plot scatterplots containing points and a smooth line for the four pairs of variable I selected.
ggvis(Mroz, x = ~hoursw, y = ~agew) %>% layer_points()%>% layer_smooths()
ggvis(Mroz, x = ~hoursw, y = ~wagew) %>% layer_points()%>% layer_smooths()
ggvis(Mroz, x = ~hoursw, y = ~educw) %>% layer_points()%>% layer_smooths()
ggvis(Mroz, x = ~wagew, y = ~educw) %>% layer_points()%>% layer_smooths()
## Source: local data frame [753 x 2]
##
## hoursw agew
## 1 1610 32
## 2 1656 30
## 3 1980 35
## 4 456 34
## 5 1568 31
## 6 2032 54
## 7 1440 37
## 8 1020 54
## 9 1458 48
## 10 1600 39
## .. ... ...
## $r
## hoursw agew
## hoursw 1
## agew -0.033 1
##
## $p
## hoursw agew
## hoursw 0
## agew 0.36 0
##
## $sym
## hoursw agew
## hoursw 1
## agew 1
## attr(,"legend")
## [1] 0 ' ' 0.3 '.' 0.6 ',' 0.8 '+' 0.9 '*' 0.95 'B' 1
## Source: local data frame [753 x 2]
##
## hoursw wagew
## 1 1610 2.65
## 2 1656 2.65
## 3 1980 4.04
## 4 456 3.25
## 5 1568 3.60
## 6 2032 4.70
## 7 1440 5.95
## 8 1020 9.98
## 9 1458 0.00
## 10 1600 4.15
## .. ... ...
## $r
## hoursw wagew
## hoursw 1
## wagew 0.61 1
##
## $p
## hoursw wagew
## hoursw 0
## wagew 0 0
##
## $sym
## hoursw wagew
## hoursw 1
## wagew , 1
## attr(,"legend")
## [1] 0 ' ' 0.3 '.' 0.6 ',' 0.8 '+' 0.9 '*' 0.95 'B' 1
## Source: local data frame [753 x 2]
##
## hoursw educw
## 1 1610 12
## 2 1656 12
## 3 1980 12
## 4 456 12
## 5 1568 14
## 6 2032 12
## 7 1440 16
## 8 1020 12
## 9 1458 12
## 10 1600 12
## .. ... ...
## $r
## hoursw educw
## hoursw 1
## educw 0.11 1
##
## $p
## hoursw educw
## hoursw 0
## educw 0.0036 0
##
## $sym
## hoursw educw
## hoursw 1
## educw 1
## attr(,"legend")
## [1] 0 ' ' 0.3 '.' 0.6 ',' 0.8 '+' 0.9 '*' 0.95 'B' 1
## Source: local data frame [753 x 2]
##
## wagew educw
## 1 2.65 12
## 2 2.65 12
## 3 4.04 12
## 4 3.25 12
## 5 3.60 14
## 6 4.70 12
## 7 5.95 16
## 8 9.98 12
## 9 0.00 12
## 10 4.15 12
## .. ... ...
## $r
## wagew educw
## wagew 1
## educw 0.27 1
##
## $p
## wagew educw
## wagew 0
## educw 8.2e-14 0
##
## $sym
## wagew educw
## wagew 1
## educw 1
## attr(,"legend")
## [1] 0 ' ' 0.3 '.' 0.6 ',' 0.8 '+' 0.9 '*' 0.95 'B' 1