A correlation matrix is a square table that records the pairwise correlation coefficient for every selected variable combination. Coefficients range from -1 to +1: positive values indicate positive association, negative values indicate negative association, and values near zero indicate little meaningful association. section 2.5.4 section 5.6
Build and interpret a matrix in R with this workflow:
- Select continuous variables before computing correlations; the example uses Age, G, MP, WS, and WS48. section 2.5.4
- Pass the selected data to cor() to create the tabular matrix. Each variable correlates perfectly with itself, producing 1.00 on the diagonal. section 2.5.4
- Notice that each pair appears twice because the matrix is symmetric; melt() can stack the combinations into Var1, Var2, and value columns for plotting. section 2.5.4
- Map the reshaped values to a ggplot2 tile heat map, using color and labels to display coefficient strength. section 2.5.4
Choosing regression predictors
After checking outliers and normality, compare wins with candidate hustle variables. The matrix helps identify promising predictors rather than adding every available variable to a regression model. In the example, deflections, contested_2pt, and screen_assists_pts emerge as comparatively stronger candidates, while other hustle measures show weaker relationships with wins. section 5.6 section 5.6.2
cor_matrix <- cor(cor_draft) print(cor_matrix) ## Age G MP WS WS48 ## Age 1.0000000 -0.2189601 -0.2327846 -0.2509647 -0.1801535 ## G -0.2189601 1.0000000 0.7921621 0.8004797 0.6165429 ## MP -0.2327846 0.7921621 1.0000000 0.7758876 0.6597869 ## WS -0.2509647 0.8004797 0.7758876 1.0000000 0.6942061 ## WS48 -0.1801535 0.6165429 0.6597869 0.6942061 1.0000000
Inspect the printed R matrix to see diagonal self-correlations, duplicated pairwise values, and relationships such as MP with WS48. section 2.5.4




