7.1 Correlation

To calculate the correlation coefficient (r) between two numeric variables, use the cor.test() function and specify the model as ~ Var1 + Var2. This structure is unusual in that both variables follow the ~, and the + separates the two.

  cor.test(~ ProfMath + ProfLang, dcps)
## 
##  Pearson's product-moment correlation
## 
## data:  ProfMath and ProfLang
## t = 22, df = 106, p-value <2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.8691 0.9369
## sample estimates:
##    cor 
## 0.9088

Perhaps not surprisingly, the results suggest that math and language proficiency are positively and strongly correlated (\(r=0.91\)). It is unlikely we observe this association by chance alone (\(t=22.4\), \(p<0.001\)).

Use a scatterplot (plot()) to visualize this bivariate association. Be sure to specify the formula as OutcomeVar ~ ExposureVar:

  plot(ProfMath ~ ProfLang, dcps)