3.17 Coding

To conclude this section, we’ll use R to compute the features of the joint distribution of income and education that we have discussed above.

# create vectors of income and educ
income <- us_data$incwage
educ <- us_data$educ

# mean of income
mean(income)
#> [1] 58605.75

# mean of education
mean(educ)
#> [1] 13.96299

# variance
var(income)
#> [1] 4776264026
var(educ)
#> [1] 8.345015

# standard deviation
sd(income)
#> [1] 69110.52
sd(educ)
#> [1] 2.888774

# covariance
cov(income,educ)
#> [1] 63766.72

# correlation
cor(income, educ)
#> [1] 0.3194011