Semester 3 Mathematics Applied Statistics Linear Regression When measured two things on each individual, such as temperature and pressure and You want to know whether knowing x x x helps you predict y y y , and by how much, regression can be used.
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.
For the i i i th data point (x i , y i x_i, y_i x i , y i )
y i = α + β x i + ε i y_i = \alpha + \beta x_i + \varepsilon_i y i = α + β x i + ε i
Symbol Meaning α \alpha α intercept, the predicted y y y when x = 0 x=0 x = 0 β \beta β slope, the average change in y y y for a 1-unit increase in x x x ε i \varepsilon_i ε i error, how far person i i i sits from the line
The ε i \varepsilon_i ε 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) ε ∼ N ( 0 , σ 2 )
ESS = ∑ i = 1 n ( y i − α − β x i ⏟ error i ) 2 \text{ESS}=\sum_{i=1}^{n}\big(\underbrace{y_i-\alpha-\beta x_i}_{\text{error}_i}\big)^2 ESS = i = 1 ∑ n ( error i y i − α − β x i ) 2
E S S ESS E S S - Error Sum of Squares
E S S ESS E S S is a bowl-shaped function of α \alpha α and β \beta β . Its lowest point is where both partial derivatives are zero. That gives the normal equations
To get α \alpha α and β \beta β , calculus can be used since E S S ESS E S S will be minimum at derivative is 0 0 0
ESS ( α , β ) = ∑ ( y i − α − β x i ) 2 \text{ESS}(\alpha,\beta)=\sum(y_i-\alpha-\beta x_i)^2 ESS ( α , β ) = ∑ ( y i − α − β x i ) 2
to get normal equations ;
∂ ESS ∂ α = 0 and ∂ ESS ∂ β = 0 \frac{\partial\text{ESS}}{\partial\alpha} = 0 \qquad \text{and} \qquad \frac{\partial\text{ESS}}{\partial\beta} = 0 ∂ α ∂ ESS = 0 and ∂ β ∂ ESS = 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} α ^ = y ˉ − β ^ x ˉ
∑ x i y i = α ^ ∑ x i + β ^ ∑ x i 2 \boxed{\sum x_iy_i=\hat\alpha\sum x_i+\hat\beta\sum x_i^2} ∑ x i y i = α ^ ∑ x i + β ^ ∑ x i 2
after solving,
β ^ = n ∑ 1 n x i y i − ∑ 1 n x i ∑ 1 n y i n ∑ 1 n x i 2 − ( ∑ 1 n x i ) 2 β ^ = ∑ ( x i − x ˉ ) ( y i − y ˉ ) ∑ ( x i − 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} β ^ = n ∑ 1 n x i 2 − ( ∑ 1 n x i ) 2 n ∑ 1 n x i y i − ∑ 1 n x i ∑ 1 n y i β ^ = ∑ ( x i − x ˉ ) 2 ∑ ( x i − x ˉ ) ( y i − y ˉ )
α ^ = y ˉ − β ^ x ˉ β ^ = S P x y S S x x \quad\boxed{\hat\alpha=\bar y-\hat\beta\,\bar x} \qquad\boxed{\hat\beta=\frac{SP_{xy}}{SS_{xx}}} α ^ = y ˉ − β ^ x ˉ β ^ = S S xx S P x y
y ˉ \bar y y ˉ - mean of y y y
x ˉ \bar x x ˉ - mean of x x x
below formula can be used when using calculator since the right side parts are calculated.
S P x y = ∑ x y − ∑ x ∑ y n S S x x = ∑ x 2 − ( ∑ x ) 2 n \boxed{SP_{xy} = \sum xy - \frac{\sum x\sum y}{n}} \\
\boxed{SS_{xx} = \sum x^2 - \frac{(\sum x)^2}{n}} S P x y = ∑ x y − n ∑ x ∑ y S S xx = ∑ x 2 − n ( ∑ x ) 2
β ^ = ∑ ( x i − x ˉ ) ( y i − y ˉ ) ∑ ( x i − x ˉ ) 2 \hat\beta = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2} β ^ = ∑ ( x i − x ˉ ) 2 ∑ ( x i − x ˉ ) ( y i − y ˉ )
sample variances relate to the S S SS S S
sample variance s x = ∑ ( x i − x ˉ ) 2 n − 1 \text{sample variance} \quad s_x = \frac{\sum(x_i-\bar x)^2}{n-1} sample variance s x = n − 1 ∑ ( x i − x ˉ ) 2
\
\text{sum of squares} \quad SS_{xx} = \sum (x_i-\bar x)
\ \
\boxed {SS_{xx} = s_x \cdot (n-1) }
r r r - Sample Correlation Coefficient
r = s x y s x s y r=\frac{s_{xy}}{s_x\,s_y} r = s x s y s x y
- $s_{xy}$ - Sample Covariance
- $s_x, s_y$ - sample standard deviations
ρ \rho ρ - Population Correlation Coefficient (Pearson Correlation Coefficient)
ρ X Y = Cov ( X , Y ) σ X σ Y \rho_{XY}=\frac{\operatorname{Cov}(X,Y)}{\sigma_X\,\sigma_Y} ρ X Y = σ X σ Y Cov ( X , Y )
β \beta β - Regression Coefficient
Under the normal error assumption ε i ∼ N ( 0 , σ 2 ) \varepsilon_i \sim N(0, \sigma^2) ε i ∼ N ( 0 , σ 2 ) :
β ^ ∼ N ( β , σ 2 S S x x ) \hat{\beta} \sim N\left(\beta, \frac{\sigma^2}{SS_{xx}}\right) β ^ ∼ N ( β , S S xx σ 2 )
where σ 2 = Var ( ε i ) \sigma^2=\text{Var}(\varepsilon_i) σ 2 = Var ( ε i )
If σ 2 \sigma^2 σ 2 is unknown, it is estimated by:
σ ^ 2 = E S S n − 2 \hat{\sigma}^2 = \frac{ESS}{n-2} σ ^ 2 = n − 2 E S S
Usual Null Hypothesis is "the regression coefficient is significantly different from 0"
H 0 : β = 0 H 1 : β ≠ 0 H_0: \beta = 0 \qquad H_1: \beta \neq 0 H 0 : β = 0 H 1 : β = 0
But it can be H 1 : β > 0 H_1: \beta > 0 H 1 : β > 0 or H 1 : β < 0 H_1: \beta < 0 H 1 : β < 0 like as well
β ^ − β σ ^ 2 / S x x ∼ t n − 2 \frac{\hat{\beta} - \beta}{\sqrt{\hat{\sigma}^2 / S_{xx}}} \sim t_{n-2} σ ^ 2 / S xx β ^ − β ∼ t n − 2