Lawfare Academy · Complete Regression and Business Forecasting edition 6
Least squares, uncertainty and a reproducible output table
Fit is an optimization result; inference is a model result
For observed pairs, minimize S(a,b)=sum((yi-a-bxi)^2). Differentiating in a gives sum(ei)=0 and a=ybar-b*xbar. Substituting into the slope equation gives b=Sxy/Sxx when Sxx>0. The second derivative in the centered slope is 2*Sxx>0, so this stationary point is the unique slope minimum. The fitted line passes through the two sample means. With an intercept, its residuals sum to zero and their inner product with x is zero. Those identities hold for this optimizer even when the conditional mean is wrong; they cannot certify that the population errors are independent or have zero conditional mean.
Use the existing Academy four-, five- and six-point records as separate investigations. For this studio use the four-branch record x=(1,2,3,4), y=(2,4,5,7). Sxx=5, Sxy=8, Syy=13, giving b=1.6, a=.5, predictions (2.1,3.7,5.3,6.9) and residuals (-.1,.3,-.3,.1). SSE=.2. The fitted centered component and residual component are orthogonal, so SST=SSR+SSE=12.8+.2=13. R-squared=12.8/13. An intercept is essential to this centered decomposition; do not apply the same interpretation to a forced-zero fit without checking its definition.
For classical conditional inference write Y=Xbeta+epsilon with E(epsilon|X)=0 and Var(epsilon|X)=sigma² I. Treat the predictor design as fixed or condition on it. These assumptions give E(bhat|X)=beta and Var(bhat|X)=sigma²(X'X)^-1 for a full-rank model. Normal errors supply exact finite-sample t and F distributions. Constant variance and independence alone do not establish an exact normal-reference test, and a coefficient computed by least squares needs no normal assumption merely to exist. Time dependence and clustered measurements demand an appropriate covariance structure. A robust covariance estimate can change standard errors without repairing a wrong mean or a causal identification problem.
Build the coefficient table instead of trusting labels
Here n=4 and p=2 estimated coefficients. The unbiased residual variance estimate under the model is s²=SSE/(n-p)=.1. Thus s=sqrt(.1), slope SE=s/sqrt(Sxx)=sqrt(.02)=.141421356 and intercept SE=s*sqrt(1/n+xbar²/Sxx)=sqrt(.15)=.387298335. The coefficient covariance is -xbar*s²/Sxx=-.05. Its sign reflects the way estimated intercept and slope compensate around the observed center. At x=0 the intercept extrapolates beyond the observed range; its mathematical SE does not make that point operationally plausible.
Testing beta 1=0 gives t=1.6/sqrt(.02)=11.313708499 with df=2. For a two-sided 95% interval use the supplied t critical value 4.302652730. The slope margin is approximately .6084870, giving approximately [.991513,2.208487]. With one added slope, the regression ANOVA F is (SSR/1)/(SSE/2)=128=t². State the assumptions and degrees of freedom with the statistic. A very high R-squared in four synthetic observations says little about transportability; a significance result is not permission to spend money.
For a coefficient hypothesis beta 1=c, replace the numerator with b-c. If c=1.5, t=.1/sqrt(.02)=.707106781. The data's apparent rejection of zero does not imply precision sufficient to distinguish 1.6 from 1.5. A practical threshold and a statistical null are different questions. Construct the relevant contrast before reading a p-value column.
Predictions and intervals answer different questions
At x 0=2.5, yhat=4.5 and h 0=1/n+(x 0-xbar)^2/Sxx=.25. The estimated fitted-mean variance is s²h 0=.025 and new-individual prediction variance is s²(1+h 0)=.125. Under the same exact classical model, multiply their square roots by 4.302652730 to obtain margins approximately .68031 and 1.52122. The second is wider because a new individual's unexplained error remains even if coefficients are accurately estimated. An average of m independent new comparable observations instead adds s²/m, not s², to coefficient uncertainty. Dependence among those observations changes that term.
At x 0=5, h 0=.25+2.5²/5=1.5 and fitted outcome=8.5. Mean variance=.15 and individual variance=.25. This larger geometric uncertainty still omits the risk that the relationship changes beyond x=4. Never interpret the expanded interval as an automatic extrapolation safeguard. These intervals are pointwise; selecting many targets or a favorable target after looking at results changes simultaneous coverage and selection claims.
Optional Excel reproduction, with complete manual alternative
Enter x in A 2:A 5 and y in B 2:B 5. Preserve the unrounded original cells. In an empty region, use =LINEST(B 2:B 5,A 2:A 5,TRUE,TRUE). A supported dynamic-array Excel version spills a five-row, two-column result for one predictor. Older versions may require selecting the output block and entering an array formula. The first row is slope/intercept; row two their standard errors; row three R-squared/residual standard error; row four F/residual df; row five regression and residual sums of squares. Confirm labels against the manual values above rather than assuming row order is arbitrary. Do not let the spill overwrite the dataset.
For an independent worksheet check, calculate =AVERAGE(A 2:A 5), centered products, =SLOPE(B 2:B 5,A 2:A 5), =INTERCEPT(B 2:B 5,A 2:A 5), fitted values and residuals. Sum squared residuals, divide by COUNT(A 2:A 5)-2 and square-root. Use =T.INV.2 T(0.05,2) for the supplied two-sided critical value if that function is available. =CORREL(A 2:A 5,B 2:B 5)^2 should agree with this intercept-model R-squared. Preserve paired rows when sorting or filtering; deleting one missing cell without removing its paired row changes the observation definition. Menus, localization and decimal separators vary. These are optional procedures; all required learning and hand calculations are on site, and execution in a particular Excel installation is not claimed.
Optional practice
Guided model: a variance denominator changes
Dividing SSE=.2 by four gives .05, half the conventional residual estimate .1, because it ignores the two fitted coefficients. The resulting slope SE would be .1 instead of sqrt(.02). Changed fact: there are six independent observations and still two fitted coefficients, with SSE=.2. Then df=4 and s²=.05 is the correct model-based estimate. The denominator depends on the actual design and estimated parameter count, not on a rule that every sum must be divided by the number of rows.
Independent model: a future average
At x 0=2.5, an average of 100 independent new comparable outcomes has estimated prediction variance .025+.1/100=.026, SE=sqrt(.026). The fitted mean alone has variance .025. Changed fact: the 100 outcomes share a common shock. Their average's new-outcome variance need not be .001; include covariance terms or state that this reduction is unsupported. Increasing row count does not remove a common component.
Transfer model: a smaller p-value is an incomplete decision
The zero-slope t is 11.3137, but the slope-versus-1.5 t is .7071. A manager requiring an incremental effect clearly above 1.5 cannot use rejection of zero to assert the stronger threshold. Moreover these are observational records. Changed fact: a later randomized design justifies a causal contrast at the relevant scale. Recalculate its effect, uncertainty and actual costs using that design; do not transfer this tiny fixture's coefficients into the new study.
Unit rubric: 20 points
Award four points each for correct normal equations/fit, coefficient table and df, matched hypothesis and assumptions, mean/individual/average prediction distinction, and reproducible paired-data workflow with changed facts. Complete model: report (.5,1.6), SSE=.2, df 2, s²=.1, slope SE=sqrt(.02), intercept SE=sqrt(.15), t 0=11.3137 and t 1.5=.7071. At the center use variances .025 and .125; name pointwise, model and support limits. The optional worksheet is a reproducibility aid, not independent human review or a claim of device execution.
Optional source summary: NIST linear least squares was read for the distinction between linearity in parameters, estimation and extrapolation limitations. The branch data, calculations, workflow and practice here are original Academy teaching.
Optional software provenance: Microsoft LINEST documents the returned coefficient/statistics layout. It was consulted for this optional reproduction procedure; the manual derivation and numerical teaching are complete on site.