Skip to content

Relationships and Distributions

Once basic trends and group comparisons have been examined, an analyst will often want to explore relationships between variables. For example: do companies with more employees generate higher sales? Are more digitally mature firms associated with higher customer satisfaction? Do firms with higher marketing spending also tend to have higher sales?

A scatter plot helps examine the relationship between two numerical variables directly, but when there are many variables to consider, checking each possible pair one scatter plot at a time quickly becomes impractical. A correlation matrix provides a compact summary of many pairwise relationships at once, condensing what could be dozens of individual scatter plots into a single table (or a single heatmap image). These tools don't prove causality on their own, correlation is not causation, but they're extremely useful for identifying patterns that may deserve further, more rigorous investigation.

In economics, finance, and management, this kind of exploratory relationship analysis is very often carried out before any formal regression modelling or machine learning takes place. It helps the analyst genuinely understand the data first, rather than fitting a formal model to relationships that turn out, on closer inspection, not to exist or to behave very differently from what was assumed.

Python Code: Correlation Matrix and Heatmap

# Explore relationships between variables

correlation_matrix = data[
    ["sales_million", "employees", "profit_million",
     "marketing_spend_million", "rd_spend_million",
     "customer_satisfaction", "digital_score", "profit_margin"]
].corr()

print(correlation_matrix.round(2))

plt.figure(figsize=(8, 6))
plt.imshow(correlation_matrix, aspect="auto")
plt.colorbar(label="Correlation")
plt.xticks(range(len(correlation_matrix.columns)), correlation_matrix.columns, rotation=90)
plt.yticks(range(len(correlation_matrix.columns)), correlation_matrix.columns)
plt.title("Correlation Matrix for Business Indicators")
plt.tight_layout()
plt.show()

Expected output / interpretation

The matrix summarises the direction and strength of pairwise linear relationships between business indicators.

Making sense of the correlation matrix itself:

  • .corr() calculates the Pearson correlation coefficient between every pair of the selected numeric columns. Each value ranges from -1 to +1. A value close to +1 indicates a strong positive relationship (as one variable rises, so does the other), a value close to -1 indicates a strong negative relationship (as one rises, the other tends to fall), and a value close to 0 suggests little to no linear relationship between the two variables.
  • .round(2) simply rounds the printed values to two decimal places, purely for readability, since correlation coefficients rarely need more precision than that to be meaningfully interpreted.
  • The matrix is inherently symmetric: the correlation between sales_million and employees is identical to the correlation between employees and sales_million, and the diagonal (each variable correlated with itself) is always exactly 1.00. Recognising this symmetry means you only really need to read half the table (either above or below the diagonal) to see every distinct relationship.

Turning the matrix into a heatmap:

  • plt.imshow(correlation_matrix, aspect="auto") displays the matrix as a grid of coloured cells, where each cell's colour intensity reflects its underlying numeric value, this is what turns a plain table of numbers into a genuine heatmap.
  • plt.colorbar(label="Correlation") adds a colour scale alongside the chart, letting the reader translate colour back into an approximate correlation value without needing to consult the printed numbers directly.
  • plt.xticks(..., rotation=90) and plt.yticks(...) label each row and column with the actual variable names, rotating the x-axis labels by 90 degrees so that the (often fairly long) variable names don't overlap each other.

An important caution when reading this chart: a strong correlation between two variables, say, marketing_spend_million and sales_million, tells you they tend to move together, but it doesn't by itself tell you which one is driving the other, or whether some third, unmeasured factor (like overall company size) is driving both simultaneously. Treat a correlation matrix as a map pointing toward relationships worth investigating further, for example, through a scatter plot, a regression model, or additional domain knowledge, rather than as a final, standalone answer in itself.

Where this fits in a broader workflow: a correlation matrix like this is often one of the very last exploratory steps before moving on to formal statistical modelling. Having already examined individual trends (Section D) and group comparisons (Section E), this final relationship-focused view helps confirm which variables are worth carrying forward into more advanced analysis, and which show so little relationship to the outcome of interest that they're unlikely to be worth the added complexity.