Dulranga's Notes
Semester 3MathematicsApplied Statistics

Linear Regression

When measured two things on each individual, such as temperature and pressure and You want to know whether knowing xx helps you predict yy, and by how much, regression can be used.

linear-regression-scatter.png

When plotted in a scatter diagram like this, if the data points tend to follow a line, we can use Linear Regression to get a good estimate.

The model

For the ii th data point (xi,yix_i, y_i)

yi=α+βxi+εiy_i = \alpha + \beta x_i + \varepsilon_i
SymbolMeaning
α\alphaintercept, the predicted yy when x=0x=0
β\betaslope, the average change in yy for a 1-unit increase in xx
εi\varepsilon_ierror, how far person ii sits from the line
Info

The εi\varepsilon_i is important because it tells everything else about the data distribution that the line doesn't explain, such as noise or other variables.

Its assumed, Error terms are independently and identically distributed as Normal with mean zero and variance σ\sigma.

ε∼N(0,σ2)\varepsilon \sim \mathcal N(0,\sigma^2)

Choosing the correct Line with Sum of Least Squares

ESS=∑i=1n(yi−α−βxi⏟errori)2\text{ESS}=\sum_{i=1}^{n}\big(\underbrace{y_i-\alpha-\beta x_i}_{\text{error}_i}\big)^2

ESSESS - Error Sum of Squares

ESSESS is a bowl-shaped function of α\alpha and β\beta. Its lowest point is where both partial derivatives are zero. That gives the normal equations ess-surface-contour.png

To get α\alpha and β\beta, calculus can be used since ESSESS will be minimum at derivative is 00

ESS(α,β)=∑(yi−α−βxi)2\text{ESS}(\alpha,\beta)=\sum(y_i-\alpha-\beta x_i)^2

to get normal equations;

∂ESS∂α=0and∂ESS∂β=0\frac{\partial\text{ESS}}{\partial\alpha} = 0 \qquad \text{and} \qquad \frac{\partial\text{ESS}}{\partial\beta} = 0

lets name the solutions of this as,

α^,β^\hat\alpha \quad, \quad\hat\beta

we get these,

α^=yˉ−β^ xˉ\quad\boxed{\hat\alpha=\bar y-\hat\beta\,\bar x} ∑xiyi=α^∑xi+β^∑xi2\boxed{\sum x_iy_i=\hat\alpha\sum x_i+\hat\beta\sum x_i^2}

after solving,

β^=n∑1nxiyi−∑1nxi∑1nyin∑1nxi2−(∑1nxi)2β^=∑(xi−xˉ)(yi−yˉ)∑(xi−xˉ)2\hat{\beta} = \frac{n \sum_{1}^{n} x_i y_i - \sum_{1}^{n} x_i \sum_{1}^{n} y_i}{n\sum_{1}^{n} x_i^2 - \left(\sum_{1}^{n} x_i\right)^2} \\ \\ \hat{\beta} = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2} α^=yˉ−β^ xˉβ^=SPxySSxx\quad\boxed{\hat\alpha=\bar y-\hat\beta\,\bar x} \qquad\boxed{\hat\beta=\frac{SP_{xy}}{SS_{xx}}}
  • yˉ\bar y - mean of yy
  • xˉ\bar x - mean of xx

Useful formulas

below formula can be used when using calculator since the right side parts are calculated.

SPxy=∑xy−∑x∑ynSSxx=∑x2−(∑x)2n\boxed{SP_{xy} = \sum xy - \frac{\sum x\sum y}{n}} \\ \boxed{SS_{xx} = \sum x^2 - \frac{(\sum x)^2}{n}} β^=∑(xi−xˉ)(yi−yˉ)∑(xi−xˉ)2\hat\beta = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}
Useful to keep in mind

sample variances relate to the SSSS

sample variancesx=∑(xi−xˉ)2n−1\text{sample variance} \quad s_x = \frac{\sum(x_i-\bar x)^2}{n-1}

\ \text{sum of squares} \quad SS_{xx} = \sum (x_i-\bar x)

\ \ \boxed {SS_{xx} = s_x \cdot (n-1) }

Terms

  • rr - Sample Correlation Coefficient
r=sxysx syr=\frac{s_{xy}}{s_x\,s_y}
- $s_{xy}$ - Sample Covariance
- $s_x, s_y$ - sample standard deviations
  • ρ\rho - Population Correlation Coefficient (Pearson Correlation Coefficient)
ρXY=Cov⁡(X,Y)σX σY\rho_{XY}=\frac{\operatorname{Cov}(X,Y)}{\sigma_X\,\sigma_Y}
  • β\beta - Regression Coefficient

Hypothesis testing on β\beta

Under the normal error assumption εi∼N(0,σ2)\varepsilon_i \sim N(0, \sigma^2):

β^∼N(β,σ2SSxx)\hat{\beta} \sim N\left(\beta, \frac{\sigma^2}{SS_{xx}}\right)

where σ2=Var(εi)\sigma^2=\text{Var}(\varepsilon_i)

If σ2\sigma^2 is unknown, it is estimated by:

σ^2=ESSn−2\hat{\sigma}^2 = \frac{ESS}{n-2}

Usual Null Hypothesis is "the regression coefficient is significantly different from 0"

H0:β=0H1:β≠0H_0: \beta = 0 \qquad H_1: \beta \neq 0

But it can be H1:β>0H_1: \beta > 0 or H1:β<0H_1: \beta < 0 like as well

β^−βσ^2/Sxx∼tn−2\frac{\hat{\beta} - \beta}{\sqrt{\hat{\sigma}^2 / S_{xx}}} \sim t_{n-2}

slope-t-test.png

On this page