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.
##
## Pearson's product-moment correlation
##
## data: ProfMath and ProfLang
## t = 22.429, df = 106, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.8691196 0.9368943
## sample estimates:
## cor
## 0.9088269
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: