Linear Regression Notes
Linear Regression
- Used to predict variable based on the value of another variable .
- : Experimenter controls.
- : Experimenter measures.
Learning Objectives
- Explain the motivation and practical applications of linear regression in data analysis.
- Define residual as the difference between the observed and estimated values.
- Calculate the optimal estimates of the slope and intercept from given x and y data.
- Calculate and understand the relationship between SST, SSE, and SSR
- Calculate and interpret the coefficient of determination and correlation coefficient.
- Discuss possible explanations for the correlation between two variables.
- Understand how linear regression can be used to estimate nonlinear relationships
- Calculate the MSE and the uncertainty in the estimated slope and intercept
- Conduct a hypothesis test on the slope or intercept using confidence intervals
- List and assess the assumptions of least-squares regression using graphical techniques
Linear Regression Model
- Basic regression model that is linear and includes one predictor:
where:
- is the intercept.
- is the slope.
Optimal Estimates for β0 and β1
- Goal: Find optimal estimates for and so that the estimated line is closer to the data than any other line.
- Estimated line:
Method of Ordinary Least Squares (OLS)
- Used to find the optimal and .
- Measure of closeness:
- Error in the prediction: observed value minus estimated value.
- Difference between the observed values and the predicted values .
- Residuals:
- Square the residuals to avoid cancellation.
- Overall measure of closeness: Sum of Squared Errors (SSE).
- Minimize to find the closest line to the data.
Formulas for β̂0 and β̂1
- Alternative formulas:
Method of Ordinary Least Squares (OLS) Summary
- Given observations , find optimal estimates for and so that the estimated line is closer to the data than any other line
- For each , the estimated value is obtained by:
- This line has the lowest SSE for the given data
- SSE: Sum Squared Error
- The quantities are called residuals
Quantifying Goodness-of-Fit
- (Sum Squared Error): Remaining variation after accounting for the relationship between and .
- (Sum Squared Total): Total variation if the relationship between and is not accounted for.
- (Sum Squared Regression): Variation accounted for by the relationship between and .
Coefficient of Determination
- : Proportion of the total variation SST that is explained by the model SSR.
- Properties of .
- Unitless.
- Larger values suggest better fit.
Coefficient of Determination vs. Correlation
- The square root of the coefficient of determination is the sample correlation coefficient:
- The notation is meaningful: is an estimate of (just like is an estimate of )
- is based on observations , which are a sample
- is based on random variables and , which are the populations
Correlation vs. Causation
- Correlation does not imply causation.
- Possible explanations for correlation between and .
- caused .
- caused .
- and impact each other.
- A common third factor influences and simultaneously.
- Just a coincidence due to sampling variation.
Correlation & Outliers
- Correlation can be significantly affected by outliers.
- Some outliers are caused by data recording errors: these outliers can be corrected/deleted.
- Deleting outliers without a justification is not appropriate.
Nonlinear Models
- Correlation measures linear association.
- Lack of correlation suggests lack of linear association (there could be a nonlinear association).
- If we suspect a nonlinear relationship exists, then, in some cases, we can still use linear regression.
- Apply linear regression on a transformed set of variables.
- For example, if
Uncertainty in Regression Estimates
- The least-squares values and are estimates of the true unknown parameters and .
- Treat and as random variables
- Precision: uncertainty in and
Uncertainty in and
- Under the assumptions of linear regression (discussed later), the uncertainty in and as a function of is
- Where
- However, is a parameter, and hence, is typically unknown
- Use to estimate
- This is also called Mean Squared Error (MSE)
Uncertainty in β̂0 and β̂1: Summary
- and are estimators of the unknown parameters and
- The uncertainty in and is controlled by the variance of the error
- , where
- The unbiased estimator of is:
- Then, the uncertainty in and can be estimated as:
Confidence Intervals for β0 and β1
- Two-sided confidence intervals for and are given by:
Hypothesis Testing for β0 and β1
- One use of linear regression is to test whether or not there is a significant relationship between two variables.
- Does strength depend on cement content ?
- If there is no relationship between strength and cement content:
*
Assumptions For Least-Squares
- Everything we discussed (variances of and , confidence intervals, etc.) is only appropriate if the model assumptions are satisfied: LINE conditions
- Linear relationship between and
- Independent error terms (and therefore, independent observations)
- Normally distributed error terms
- Equal variance of along regression line
- If the assumptions are satisfied, the residuals, , should reflect these properties
Checking Assumptions
- Linear Relationship: Plot the residuals against (or against the estimated values ).
- Independent Errors: Plot the residuals against (or against the estimated values ).
- Normally Distributed Errors 𝜀𝑖 : Plot a histogram or Q-Q plot of the residuals
- Equal Variance: Plot the residuals against (or against the estimated values ).
- Outlier Check: Plot the residuals against (or against the estimated values ).
Remedial Measures
- If a simple linear regression model is not appropriate for the data:
- Use a more appropriate model
- Apply transformation on the data and then use linear regression
- Unequal variances and nonnormality of the errors frequently occur together
- To remedy these violations, we need a transformation on
- Such a transformation may also at the same time help to linearize a curvilinear relation
- At other times, a simultaneous transformation on along with may be needed