The base R cor() function computes correlation coefficients between numeric variables. Use it to ask practical questions such as whether playing time, games played, or win shares move together. Select continuous variables first; passing noncontinuous data can produce an error. section 2.5.4
A typical correlation workflow is:
- Subset the data to continuous variables such as Age, G, MP, WS, and WS48. section 2.5.4
- Pass the resulting data frame to cor() to calculate every pairwise coefficient. section 2.5.4
- Inspect the matrix: coefficients range from negative to positive, diagonal values equal 1, and each pair appears twice. section 2.5.4
- Reshape the matrix with reshape2::melt() when a heat map needs one row per variable pair. section 2.5.4
Comparing hustle statistics with wins
Running cor(hustle2) returns a correlation matrix for selected hustle variables. The coefficient between deflections and wins is 0.24, indicating a positive but unremarkable association. A separate comparison of annual salary and win shares returns 0.76, indicating a strong positive correlation. section 5.6.1 section 4.5.3
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 an executable correlation-matrix call and its printed coefficients for five continuous draft variables. section 2.5.4
