Skip to content

Module 3 formulas

Back to Module 3.

Inner dimensions match; outer dimensions survive.

For real matrices AA of shape m×nm\times n and BB of shape n×pn\times p:

(m×n)(n×p)(m×p),(m\times n)(n\times p)\longrightarrow(m\times p), (AB)ij=k=1nAikBkj.(AB)_{ij}=\sum_{k=1}^{n}A_{ik}B_{kj}.
  • ii: output row; jj: output column.
  • kk: index along the matched row and column.
  • Aik,BkjA_{ik},B_{kj}: individual entries.
  • \sum: add the products as kk runs from 1 to nn.

One entry = row times column. Row [1,2][1,2] and column [2,1]T[2,1]^\mathsf T give 1(2)+2(1)=41(2)+2(1)=4.

Powers and identity

A2=AAA^2=AA; A3=(AA)AA^3=(AA)A. The identity II has diagonal entries 1 and other entries 0: AI=IA=AAI=IA=A when sizes match.

Algebra rules

  • Generally ABBAAB\ne BA.
  • (AB)C=A(BC)(AB)C=A(BC).
  • A(B+C)=AB+ACA(B+C)=AB+AC.

The transpose ATA^\mathsf T swaps rows and columns:

(AT)ij=Aji,(AT)T=A.(A^\mathsf T)_{ij}=A_{ji}, \qquad (A^\mathsf T)^\mathsf T=A. (A+B)T=AT+BT,(A+B)^\mathsf T=A^\mathsf T+B^\mathsf T, (AB)T=BTAT.(AB)^\mathsf T=B^\mathsf TA^\mathsf T.

Transposing a product reverses its order. All operations require compatible dimensions.

Inner = one number; outer = a grid. Let u,vu,v be column vectors with nn real entries.

uTv=k=1nukvk=vTu,u^\mathsf Tv=\sum_{k=1}^n u_kv_k=v^\mathsf Tu, (uvT)ij=uivj.(uv^\mathsf T)_{ij}=u_iv_j.

uk,vku_k,v_k are vector entries. The outer product is an n×nn\times n matrix; i,ji,j select its row and column.

Matrix times vector: for AA with mm rows and nn columns,

(Av)i=k=1nAikvk.(Av)_i=\sum_{k=1}^n A_{ik}v_k.

The result has mm entries. Each is one row of AA dotted with vv.

Squared length = sum of squared entries:

v2=vTv=k=1nvk2.\lVert v\rVert^2=v^\mathsf Tv=\sum_{k=1}^n v_k^2.

Invented example: u=[2,1]Tu=[2,1]^\mathsf T, v=[3,4]Tv=[3,4]^\mathsf T give inner product 2(3)+1(4)=102(3)+1(4)=10 and outer product [6834]\begin{bmatrix}6&8\\3&4\end{bmatrix}.

Multiply, then check for one common scaling factor.

Mv=λv,v0.Mv=\lambda v,\qquad v\ne0.
  • MM: square n×nn\times n matrix.
  • vv: nonzero eigenvector.
  • λ\lambda: eigenvalue, the multiplier.

Negative λ\lambda reverses direction; zero collapses the vector to zero. For invented M=[3002]M=\begin{bmatrix}3&0\\0&2\end{bmatrix} and v=[1,0]Tv=[1,0]^\mathsf T, Mv=[3,0]T=3vMv=[3,0]^\mathsf T=3v.

If MM is real and symmetric, M=MTM=M^\mathsf T, its eigenvalues are real and one can choose nn mutually perpendicular eigenvectors. Perpendicular means viTvj=0v_i^\mathsf Tv_j=0 for different chosen vectors. General real matrices may have complex eigenvalues/eigenvectors.

Prediction = baseline + input contributions.

Y=β0+j=1pβjXj+ε.Y=\beta_0+\sum_{j=1}^{p}\beta_jX_j+\varepsilon.
  • YY: response; XjX_j: input jj.
  • pp: number of predictors, excluding the intercept.
  • β0\beta_0: intercept, the baseline when all inputs are zero.
  • βj\beta_j: multiplier, or response change per unit of input jj, holding other inputs fixed.
  • ε\varepsilon: unexplained noise.

A hat means “estimated from the data.” For observation ii with recorded inputs xijx_{ij}:

y^i=β^0+j=1pβ^jxij.\widehat y_i=\widehat\beta_0+\sum_{j=1}^{p}\widehat\beta_jx_{ij}.

Unknown noise is left out of the prediction. Invented rule y^=10+3x\widehat y=10+3x at x=4x=4: contribution 3(4)=123(4)=12; add baseline 10+12=2210+12=22.

Probability story: draw inputs, then draw an output given those inputs.

fX,Y(x,y)=fYX(yx)fX(x).f_{X,Y}(x,y)=f_{Y\mid X}(y\mid x)f_X(x).

fXf_X is the input density, fYXf_{Y\mid X} the conditional output density, and fX,Yf_{X,Y} their joint density. x,yx,y are possible input and output values; the model plus noise distribution describes the conditional output.

Center → multiply → add → divide. Given nn observed pairs (xi,yi)(x_i,y_i), fit y^=β^0+β^1x\widehat y=\widehat\beta_0+\widehat\beta_1x with an intercept.

1. Means

xˉ=1ni=1nxi,yˉ=1ni=1nyi.\bar x=\frac1n\sum_{i=1}^n x_i, \qquad\bar y=\frac1n\sum_{i=1}^n y_i.

2. Centered totals

Sxy=i=1n(xixˉ)(yiyˉ),S_{xy}=\sum_{i=1}^n(x_i-\bar x)(y_i-\bar y), Sxx=i=1n(xixˉ)2.S_{xx}=\sum_{i=1}^n(x_i-\bar x)^2.

SxyS_{xy} measures joint movement; SxxS_{xx} measures input spread.

3. Slope and intercept

β^1=SxySxx,β^0=yˉβ^1xˉ.\widehat\beta_1=\frac{S_{xy}}{S_{xx}}, \qquad\widehat\beta_0=\bar y-\widehat\beta_1\bar x.

Require Sxx>0S_{xx}>0: identical inputs cannot identify a slope.

The intercept puts the line through the averages:

y^(xˉ)=(yˉβ^1xˉ)+β^1xˉ=yˉ.\begin{aligned} \widehat y(\bar x) &=(\bar y-\widehat\beta_1\bar x)+\widehat\beta_1\bar x\\ &=\bar y. \end{aligned}

Shared Q3: pairs (1,2),(0,0),(1,5)(-1,-2),(0,0),(1,5) give calculated means 0,10,1, Sxx=2S_{xx}=2, and Sxy=7S_{xy}=7. Thus slope =7/2=3.5=7/2=3.5; intercept =13.5(0)=1=1-3.5(0)=1.

One matrix fits every row at once.

  • MM: design matrix with nn rows and p+1p+1 columns; first column all ones, then pp predictor columns.
  • yy: column of nn observed outputs.
  • θ\theta: trial vector of p+1p+1 coefficients.
  • β^\widehat\beta: fitted coefficient vector, intercept first.
β^=argminθyMθ2.\widehat\beta=\operatorname*{argmin}_{\theta} \lVert y-M\theta\rVert^2.

Argmin selects the coefficients with smallest RSS. The squared length adds squared residual entries.

With linearly independent columns — no column an exact combination of others — use

β^=(MTM)1MTy,\widehat\beta=(M^\mathsf TM)^{-1}M^\mathsf Ty, y^=Mβ^.\widehat y=M\widehat\beta.

T\mathsf T means transpose. An inverse undoes a matrix: A1A=IA^{-1}A=I, with identity II. The displayed inverse requires independent design columns.

Choose the right comparison. For nn observed outputs yiy_i, predictions y^i\widehat y_i, and sample mean yˉ=1niyi\bar y=\frac1n\sum_i y_i:

Residual = observed − predicted

ei=yiy^i.e_i=y_i-\widehat y_i.

RSS = fitted model’s squared misses

RSS=i=1n(yiy^i)2.\mathrm{RSS}=\sum_{i=1}^{n}(y_i-\widehat y_i)^2.

TSS = mean-only guess’s squared misses

TSS=i=1n(yiyˉ)2.\mathrm{TSS}=\sum_{i=1}^{n}(y_i-\bar y)^2.

R² = fraction of baseline error removed

R2=1RSSTSS=TSSRSSTSS.R^2=1-\frac{\mathrm{RSS}}{\mathrm{TSS}} =\frac{\mathrm{TSS}-\mathrm{RSS}}{\mathrm{TSS}}.

Require TSS >0>0. For training-set least squares with an intercept, RSS \le TSS and 0R210\le R^2\le1.

RSE = estimated noise size in output units

RSE=RSSnp1.\mathrm{RSE}=\sqrt{\frac{\mathrm{RSS}}{n-p-1}}.

pp counts predictor coefficients, excluding the intercept. Require n>p+1n>p+1 and linearly independent design columns. RSS/TSS have squared output units; R2R^2 has no units.

Shared Q3: RSS =1.5=1.5, TSS =26=26, n=3n=3, p=1p=1. Then RSE =1.5/(311)=1.5=\sqrt{1.5/(3-1-1)}=\sqrt{1.5} and R2=11.5/260.94R^2=1-1.5/26\approx0.94.

RSE describes output misses; SE describes estimate spread. Smaller coefficient SE means a more precise estimate.

Assumptions: correct linear model y=Mβ+εy=M\beta+\varepsilon; zero-mean errors given inputs; independent errors with common variance σ2\sigma^2; linearly independent design columns.

  • MM: design matrix, including an intercept.
  • yy: observed-output vector; ε\varepsilon: error vector.
  • β\beta: true coefficient vector; β^\widehat\beta: least-squares estimate.
  • σ\sigma: noise standard deviation; if variance σ2\sigma^2 is supplied, take its square root.

Unbiased = centered on the truth

E[β^M]=β.\mathbb E[\widehat\beta\mid M]=\beta.

E\mathbb E averages estimates across repeated samples with design MM fixed. This does not make every estimate close.

Covariance = joint uncertainty

Cov(β^M)=σ2(MTM)1.\operatorname{Cov}(\widehat\beta\mid M) =\sigma^2(M^\mathsf TM)^{-1}.

Its diagonal entries are coefficient variances. Their square roots are standard deviations (SDs).

One-predictor formulas

For nn inputs xix_i, define xˉ=1nixi\bar x=\frac1n\sum_i x_i and Sxx=i(xixˉ)2>0S_{xx}=\sum_i(x_i-\bar x)^2>0.

SD(β^1)=σSxx,\operatorname{SD}(\widehat\beta_1) =\frac{\sigma}{\sqrt{S_{xx}}}, SD(β^0)=σ1n+xˉ2Sxx.\operatorname{SD}(\widehat\beta_0) =\sigma\sqrt{\frac1n+\frac{\bar x^2}{S_{xx}}}.

β1\beta_1 is the slope; β0\beta_0 is the intercept.

Unknown noise? Replace σ\sigma with RSE:

SE(β^1)=RSESxx,\operatorname{SE}(\widehat\beta_1) =\frac{\mathrm{RSE}}{\sqrt{S_{xx}}}, SE(β^0)=RSE1n+xˉ2Sxx.\operatorname{SE}(\widehat\beta_0) =\mathrm{RSE}\sqrt{\frac1n+\frac{\bar x^2}{S_{xx}}}.

For one predictor, RSE =RSS/(n2)=\sqrt{\mathrm{RSS}/(n-2)}, where RSS =i(yiy^i)2=\sum_i(y_i-\widehat y_i)^2 uses observed outputs yiy_i and predictions y^i\widehat y_i.

Calculation chain: RSS → RSE → coefficient SE. If the problem supplies a coefficient SE, use it directly.

Invented example: RSE =1=1 and Sxx=10S_{xx}=10 give slope SE =1/100.316=1/\sqrt{10}\approx0.316.

Interval = estimate ± margin. Test statistic = gap ÷ uncertainty.

  • β^j\widehat\beta_j: fitted coefficient jj.
  • sj=SE(β^j)>0s_j=\operatorname{SE}(\widehat\beta_j)>0: its standard error.
  • bb: proposed true coefficient value.

Quick approximately 95% interval

[β^j2sj, β^j+2sj].[\widehat\beta_j-2s_j,\ \widehat\beta_j+2s_j].

Calculate margin 2sj2s_j, then subtract/add it. Across repeated samples, about 95% of these intervals contain the fixed true coefficient βj\beta_j, under the normal approximation.

Two-sided test

H0:βj=b,Ha:βjb,H_0:\beta_j=b, \qquad H_a:\beta_j\ne b, t=β^jbsj.t=\frac{\widehat\beta_j-b}{s_j}.

H0H_0 is the null claim; HaH_a is the alternative. t|t| is the gap measured in SEs.

  • t>2|t|>2: reject under the approximate rule.
  • t2|t|\le2: fail to reject; the value remains consistent with this test.

Equivalently, reject values outside the interval. Endpoints count as inside for the practice convention. Failure to reject does not prove the null true.

Shared Q5(a): estimate 3-3, SE 11, claim b=1b=1 give t=(31)/1=4t=(-3-1)/1=-4. The gap is 4 SEs: reject. For estimate 2 and SE 1/21/2, the interval is [1,3][1,3], so neither 1 nor 2 is rejected under this convention.

Zero-slope question: use j=1j=1, b=0b=0. Significance α0.05\alpha\approx0.05 describes the repeated-test rejection rate when the null is true, not the probability the null is true.

Approximation: 2 rounds the normal cutoff 1.96. Under a correct linear model with independent, zero-mean normal errors of constant variance, estimated noise, and independent design columns, exact 95% intervals replace 2 with t0.975,np1t_{0.975,n-p-1}. This is the Student tt cutoff with np1n-p-1 degrees of freedom; nn counts observations and pp predictors excluding the intercept. The practice uses the approximate rule.

Definition

Read the full glossary entry →