As I continue learning Power BI and healthcare analytics, I wanted to better understand the mathematics behind linear regression. Rather than simply memorizing formulas, my goal is to understand what each calculation means and how it helps build a prediction model.
These notes reflect my personal exploration of the basic calculations used in linear regression and connect them with practical healthcare analytics examples.
What Are X and Y?
In linear regression, we use two variables:
- X (Independent Variable) – the input or feature.
- Y (Dependent Variable) – the value we want to predict.
For example:
| Week (X) | Sales (Y) |
|---|---|
| 1 | 1.2 |
| 2 | 1.8 |
| 3 | 2.6 |
| 4 | 3.2 |
| 5 | 3.8 |
In healthcare analytics, the variables could represent:
- Number of chronic conditions → Annual healthcare cost.
- Patient age → Expected healthcare utilization.
- Number of HCCs → Predicted risk score.
Building the Calculation Table
To calculate the regression equation, we create a few additional columns:
| X | Y | X² | X × Y |
|---|---|---|---|
| 1 | 1.2 | 1 | 1.2 |
| 2 | 1.8 | 4 | 3.6 |
| 3 | 2.6 | 9 | 7.8 |
| 4 | 3.2 | 16 | 12.8 |
| 5 | 3.8 | 25 | 19.0 |
From this table, we can calculate totals and averages that are used in the regression formula.
Understanding X × Y
The expression X × Y simply means multiplying the X value and Y value for each row.
Examples:
- 1 × 1.2 = 1.2
- 2 × 1.8 = 3.6
- 3 × 2.6 = 7.8
The values are then added together to calculate the total and average.
What Is 𝑥̄𝑦̄ (Average X × Average Y)?
First, calculate the average of X and the average of Y.
- Average X = 3
- Average Y = 2.52
Then multiply the two averages:
(Average X) × (Average Y) = 3 × 2.52 = 7.56
This represents the product of the two average values.
What Is Average (X × Y)?
This is different.
First, multiply X and Y for each row. Then add all the products together and divide by the number of observations.
For the example above:
- Sum of (X × Y) = 44.4
- Average (X × Y) = 44.4 ÷ 5 = 8.88
My Memory Tip
These two expressions may look similar, but they are not the same:
- Average (X × Y) = Multiply first, then average.
- (Average X) × (Average Y) = Average first, then multiply.
Understanding this difference helped me make more sense of the regression formula.
Calculating the Slope and Intercept
Linear regression creates an equation that looks like this:
y = a₀ + a₁x
Where:
- a₀ = Intercept (where the line starts).
- a₁ = Slope (how much y changes when x increases by one unit).
The slope measures the relationship between X and Y, while the intercept adjusts where the prediction line begins.
The computer or statistical software performs these calculations automatically, but understanding the logic helps explain how the prediction model is built.
Healthcare Analytics Example
Suppose X represents the number of chronic conditions and Y represents annual healthcare cost.
A linear regression model can use historical patient data to learn the relationship between disease burden and healthcare spending. Once the model is built, it can estimate expected costs for future patients with similar characteristics.
The mathematics behind the model may seem complicated at first, but the goal is simple: use historical data to estimate a future numeric value.
📏 Mean Squared Error (MSE)
Mean Squared Error (MSE) is a measurement of how far the model’s predictions are from the actual values. It calculates the average of the squared differences between the predicted results and the real data.
- Lower MSE = Better predictions
- Higher MSE = Larger prediction errors
🌱 Simple way to remember:
MSE tells us how much the model “misses” the correct answer on average. Smaller is better.
Healthcare Example:
If a linear regression model predicts annual healthcare costs, MSE measures how close those predicted costs are to the actual costs observed in the data.
📊 R² Score (Coefficient of Determination)
R² Score measures how well the linear regression model explains the variation in the data. Its value ranges from 0 to 1.
- R² = 0 → The model explains almost none of the variation.
- R² = 1 → The model perfectly explains the variation.
- The closer R² is to 1, the better the model fits the data.
🌱 Simple way to remember:
R² tells us how well the prediction line fits the data points. Closer to 1 means a better fit.
Healthcare Example:
If a model is used to predict annual healthcare costs from the number of chronic conditions, an R² of 0.85 means that about 85% of the variation in healthcare costs can be explained by the model.
Summary box for your own memory:
| Term | Easy Definition |
|---|---|
| MSE | How much the model misses the correct answer. (Lower is better.) |
| R² Score | How well the prediction line fits the data. (Closer to 1 is better.) |
🌱 My Memory Tip:
MSE measures the size of the prediction errors. R² measures the quality of the overall fit. One tells us “How wrong are we?” and the other tells us “How well does the model explain the data?” 📊💚
What I Learned
When I first saw the formulas, they looked intimidating. However, I realized that linear regression is simply a step-by-step process of organizing data, finding relationships, and building a prediction line.
🌱 Study Note: I do not try to memorize every equation. Instead, I focus on understanding what each calculation represents and how it contributes to making a prediction.