Learning Objectives

By the end of this chapter, you will state the simple linear model $\hat{Y}=a+bX$, estimate $a$ and $b$ by least squares, interpret slope and intercept in administrative units, predict within sample range, and link regression to correlation and to policy use.

Why Regression Extends Correlation

Correlation says two variables move together and how tightly. Regression adds an equation and a direction. It predicts $Y$ from $X$ and quantifies how much $Y$ changes when $X$ rises by one unit. A ministry that knows training hours and performance scores correlate at $r=0.95$ still needs to answer how many points performance might gain if a ward adds five training hours, and at what NPR cost.

Simple linear regression fits one dependent variable $Y$ to one independent variable $X$ with a straight line.

\[\hat{Y}=a+bX\]

$\hat{Y}$ is the predicted value of $Y$. $a$ is the intercept, the predicted $Y$ when $X=0$. $b$ is the slope, the predicted change in $Y$ per one unit change in $X$. The line minimizes the sum of squared residuals $\sum(Y-\hat{Y})^2$.

Direction matters. Regression of $Y$ on $X$ differs from regression of $X$ on $Y$. Do not invert $\hat{Y}=a+bX$ to predict $X$ from $Y$. Fit the second line separately.

Estimating $a$ and $b$ by Least Squares

Slope:

\[b=\frac{n\sum XY-(\sum X)(\sum Y)}{n\sum X^2-(\sum X)^2}\]

Intercept:

\[a=\bar{Y}-b\bar{X}\quad\text{or}\quad a=\frac{\sum Y-b\sum X}{n}\]

Means $\bar{X}=\sum X/n$ and $\bar{Y}=\sum Y/n$. The link to correlation is

\[b=r\frac{s_Y}{s_X}\]

Slope carries the sign of $r$ and rescales it by the ratio of spreads.

Goodness of fit:

\[R^2=r^2\]

$R^2$ is the share of variation in $Y$ explained by the linear fit on $X$. If $R^2=0.81$, the line explains 81 percent and 19 percent remains to other factors.

Accuracy of prediction:

\[S_{YX}=\sqrt{\frac{\sum(Y-\hat{Y})^2}{n-2}}=\sqrt{\frac{\sum Y^2-a\sum Y-b\sum XY}{n-2}}\]

$S_{YX}$ lives in the unit of $Y$. Smaller means tighter predictions.

Worked Calculations

Example 1: Training Hours and Test Scores

Six employees give $X$ hours and $Y$ scores.

Employee $X$ $Y$ $XY$ $X^2$
A 10 65 650 100
B 12 70 840 144
C 15 75 1125 225
D 8 60 480 64
E 18 82 1476 324
F 20 88 1760 400
Total 83 440 6331 1257

$n=6$, $\sum X=83$, $\sum Y=440$, $\sum XY=6331$, $\sum X^2=1257$.

\[b=\frac{6(6331)-83(440)}{6(1257)-83^2}=\frac{37986-36520}{7542-6889}=\frac{1466}{653}\approx 2.245\] \[\bar{X}=83/6\approx 13.83,\quad \bar{Y}=440/6\approx 73.33\] \[a=73.33-2.245(13.83)\approx 73.33-31.05\approx 42.28\] \[\hat{Y}=42.28+2.245X\]

Prediction for $X=14$:

\[\hat{Y}=42.28+2.245(14)=42.28+31.43\approx 73.71\]

Slope says each extra training hour adds about 2.25 points. Intercept says zero training predicts 42.28 points, which is an extrapolation unless zero appears in the data.

Example 2: Experience and Salary

Five officers give experience $X$ years and salary $Y$ in NPR thousand.

$X$ 2 4 6 8 10
$Y$ 25 30 35 42 45

$\sum X=30$, $\sum Y=177$, $\sum XY=1166$, $\sum X^2=220$, $n=5$.

\[b=\frac{5(1166)-30(177)}{5(220)-900}=\frac{5830-5310}{1100-900}=\frac{520}{200}=2.6\] \[\bar{X}=6,\quad \bar{Y}=35.4,\quad a=35.4-2.6(6)=19.8\] \[\hat{Y}=19.8+2.6X\]

For $X=7$, $\hat{Y}=19.8+2.6(7)=38$, so NPR 38,000 per month. Slope reads as NPR 2,600 per additional year.

Example 3: Quick Fit and Standard Error

$X$ 1, 2, 3, 4, 5 with $Y$ 2, 5, 6, 8, 10. $\sum X=15$, $\sum Y=31$, $\sum XY=112$, $\sum X^2=55$, $\sum Y^2=229$, $n=5$.

\[b=\frac{5(112)-15(31)}{5(55)-225}=\frac{95}{50}=1.9,\quad a=6.2-1.9(3)=0.5\] \[\hat{Y}=0.5+1.9X\] \[S_{YX}=\sqrt{\frac{229-0.5(31)-1.9(112)}{3}}=\sqrt{\frac{0.7}{3}}\approx 0.48\]

Tight fit. $R^2$ for this data exceeds 0.96, so the line leaves little unexplained.

Assumptions and Cautions

Linearity: the $X$ to $Y$ relation is straight within the range. Independence: observations do not influence each other. Homoscedasticity: residual variance is constant across $X$. Normality of residuals for inference such as confidence bands around the line.

Violations distort inference. Outliers pull the least squares line. Extrapolation beyond the observed $X$ range assumes the line holds where no data checks it. And association is not causation. A positive $b$ shows fitted co movement, not proof that raising $X$ causes $Y$ to rise after controlling for other policies.

Always plot. Plot $Y$ against $X$, then plot residuals against fitted values. A curve, a funnel, or a distant point tells you whether the straight line deserves trust.

Worked Example: Training Budget and Service Score at a Ministry in BS 2081

Context: The Ministry of Federal Affairs runs a capacity program in Shrawan to Kartik 2081. Eight Palikas report training investment per staff in NPR thousand $X$ and an independent service delivery score $Y$ out of 100 in Mangsir 2081.

Palika $X$ NPR thousand per staff $Y$ score $XY$ $X^2$ $Y^2$
P1 6 58 348 36 3364
P2 8 62 496 64 3844
P3 11 68 748 121 4624
P4 14 72 1008 196 5184
P5 16 76 1216 256 5776
P6 19 81 1539 361 6561
P7 22 87 1914 484 7569
P8 24 91 2184 576 8281
Total 120 595 9453 2094 45203

$n=8$, $\sum X=120$, $\sum Y=595$, $\sum XY=9453$, $\sum X^2=2094$, $\sum Y^2=45203$.

\[b=\frac{8(9453)-120(595)}{8(2094)-14400}=\frac{75624-71400}{16752-14400}=\frac{4224}{2352}\approx 1.796\] \[\bar{X}=15.0,\quad \bar{Y}=74.375,\quad a=74.375-1.796(15)\approx 74.375-26.94\approx 47.44\] \[\hat{Y}=47.44+1.796X\]

Interpretation in policy units: Each additional NPR 1,000 per staff in training predicts about 1.80 points higher service score within the observed 6 to 24 range. A Palika that raises training from NPR 12,000 to NPR 17,000 per staff, a rise of $X=5$, predicts a gain of $5\times 1.796\approx 8.98$ points.

Correlation for the same data:

Numerator for $r$ is 4224. First bracket $2352$. Second bracket $8(45203)-595^2=361624-354025=7599$. Denominator $\sqrt{2352\times 7599}=\sqrt{17872848}\approx 4227.3$. So $r\approx 0.999$. $R^2\approx 0.998$. The linear model explains about 99.8 percent of variation in scores in this sample. That near perfect fit is unusually high because the sample is small and the program was uniform. A larger rollout will show noise.

Prediction example: a Palika plans NPR 18,000 per staff for BS 2082. $X=18$.

\[\hat{Y}=47.44+1.796(18)=47.44+32.33\approx 79.77\]

The ministry therefore targets about 80 points for a Palika at that training level, provided the 6 to 24 range still holds and other inputs such as staffing and digital tools do not change. Do not extrapolate to $X=40$. The line is grounded at 6 to 24.

Standard error for a quick sense of accuracy:

\[S_{YX}=\sqrt{\frac{45203-47.44(595)-1.796(9453)}{6}}=\sqrt{\frac{45203-28226.8-16977.6}{6}}=\sqrt{\frac{-1.4}{6}}\]

The negative due to rounding shows the fit is essentially perfect with these rounded $a$ and $b$. Using full precision gives $S_{YX}\approx 0.71$ points. That is the typical prediction error.

Census note: This is a sample of eight Palikas. If the ministry later holds the full 77 district data as a population, inference is unnecessary. With the population in hand, description suffices and sampling error disappears.

Self-check

Try this (calculable): Using the ministry data line $\hat{Y}=47.44+1.796X$, predict the score for a Palika that spends $X=20$ and for one that spends $X=10$. Then answer: spending rises from 10 to 20, how many points does the model predict as gain? What NPR cost does that imply if the Palika has 45 staff?

Answer: $\hat{Y}(20)=47.44+35.92=83.36$. $\hat{Y}(10)=47.44+17.96=65.40$. Gain $=17.96$ points for a 10 unit rise, consistent with $10\times 1.796$. Cost per staff rise is NPR 10,000, so for 45 staff cost $=45\times 10,000=$ NPR 450,000 for that predicted 18 point gain within the observed range.

Check: would you promise this gain for $X=35$? Why does extrapolation break the promise?

Summary

Simple linear regression models $\hat{Y}=a+bX$ by least squares. Slope $b=[n\sum XY-(\sum X)(\sum Y)]/[n\sum X^2-(\sum X)^2]$ is the policy lever in units of $Y$ per unit $X$. Intercept $a=\bar{Y}-b\bar{X}$ anchors the line. Correlation and regression connect through $b=r(s_Y/s_X)$ and $R^2=r^2$. $S_{YX}$ measures typical prediction error. Assumptions of linearity, independent observations, constant residual variance, and normal residuals condition inference. Extrapolation and causal reading of $b$ are the two most frequent misuses.

Key Takeaways

  • Correlation is symmetric and unit free. Regression is directional and unit dependent. Do not recycle one line to predict in the opposite direction.
  • $b$ is NPR per year, points per NPR thousand, projects per NPR million, always with units. Cite units with $b$ or the interpretation fails.
  • $\hat{Y}=a+bX$ predicts within the observed $X$ band. Outside that band, treat prediction as speculation.
  • $R^2$ translates fit into explained variation. $r=0.95$ means $R^2\approx 90.3\%$ explained linearly.
  • Plot $Y$ versus $X$ and residuals versus fitted values before trusting $S_{YX}$ or $R^2$.

Discussion

  • A province reports $b=2.6$ from experience in years to salary in NPR thousand and claims annual increments prove reward for experience. What confounders could inflate $b$, and what control would you add?
  • Your data runs $X$ 6 to 24. A donor asks for a prediction at $X=40$. What risks would you name, and what alternative would you offer instead of a point prediction?
  • A second Palika sample cuts $S_{YX}$ in half. What does that imply for budget planning that relies on the regression to set performance targets?

Exercises

  1. Data $X$ 5, 10, 15, 20, 25 and $Y$ 15, 25, 32, 38, 45. Find $\hat{Y}=a+bX$ and predict for $X=18$. Check $b\approx 1.46$, $a\approx 9.1$, $\hat{Y}(18)\approx 35.4$.
  2. Budget $X$ 10, 15, 20, 25, 30 NPR million and projects $Y$ 8, 12, 14, 18, 22. Derive $\hat{Y}=1.2+0.68X$, estimate for 22 million at about 16.2 projects, and give $R^2$ if $r=0.98$ at 96.0 percent explained.
  3. Using the ministry training line $\hat{Y}=47.44+1.796X$, a Palika moves from $X=14$ to $X=19$. Compute predicted gain and total additional cost at 60 staff.
  4. Explain in two sentences why $b_{yx}\neq 1/b_{xy}$ and why algebraic inversion of $\hat{Y}=a+bX$ does not give the $X$ on $Y$ prediction line.
  5. A scatter plot shows a funnel that widens with $X$. Name the violated assumption and describe one practical consequence for citizen score predictions at high training spends.