No
Linear regression model is formally defined as \[ \begin{aligned} y_{i} = & \beta_{0} + \beta_{1}x_{1i} + \beta_{2}x_{2i} + \dots + \beta_{p}x_{pi} + \epsilon_{i} \text{, or}\\ \mathbb{y} = &\mathbb{\beta}\mathbb{X}+ \mathbb{\epsilon} \end{aligned} \]
Confidence Interval (CI) for the Mean Response:
Prediction Interval (PI) for a New Observation:
The following relationship holds \[TSS = ESS + RSS\] TSS (Total Sum of Squares): \[\sum (y_i - \bar{y})^2\] ESS (Explained Sum of Squares): \[\sum (\hat{y}_i - \bar{y})^2\] RSS (Residual Sum of Squares):\[\sum (y_i - \hat{y}_i)^2\]
\[ R^2 = \frac{ESS}{TSS} = 1 - \frac{RSS}{TSS} \]
-\(R^2 = 0\): the model explains none of the variance in the outcome (the regression line is flat at the mean, \(\bar{y}\)). - \(R^2 = 1\): the model explains 100% of the variance (every data point falls exactly on the regression line, meaning RSS is zero).
Even we have \(R^2\), we need to know if explained variance s statistically significant.
Null Hypothesis \[ H_0: \beta_1 = \beta_2 = \dots = \beta_p = 0 \]
Test statistics
\[ F = \frac{ESS / df_{ESS}}{RSS / df_{RSS}} \sim F_{df_{ESS},df_{RSS}} \]
Investigate each predictor makes statisticaly significant contribution toward outcome
Null Hypothesis \[ H_0: \beta_i = 0 \]
Test statistics
\[ \beta_i \sim t_{n-(p+1)}(0,\frac{s_{y\vert{}x}^{2}}{(n-1)s_{x_i}^{2}(1-r_{i}^{2})}) \]
The model assumes that the average value of the outcome changes linearly with each continuous predictor. Departures from linearity can be checked using Residual versus Predictor (RVP) plots or Component-Plus-Residual (CPR) plots. Applying a nonparametric smoother (like LOWESS) to these plots helps detect nonlinear trends in the residuals. If nonlinearity is found, you may need to apply transformations to the predictor (e.g., adding quadratic terms, log transformations) or categorize the continuous predictor.
The error term \(\epsilon\) is assumed to have a normal distribution. This can be assessed using histograms, boxplots, kernel density estimates, and normal quantile-quantile (Q-Q) plots applied to the residuals. In a normal Q-Q plot, upward curvature is diagnostic of right-skewness. Transforming the outcome variable (e.g., replacing \(y\) with \(log(y)\)) is often successful for reducing the skewness of residuals.
The model assumes that the variance of the error term, \(\sigma_{\epsilon}^{2}\), is constant across all observations. Violations of this assumption are known as heteroscedasticity, which can affect the validity of confidence intervals and P-values. Homoscedasticity is evaluated using RVP plots and Residual versus Fitted (RVF) plots. A horizontal funnel shape in these scatterplots is a signal of heteroscedasticity.
High leverage points are x-outliers with the potential to exert undue influence on regression coefficient estimates. Influential points are specific observations that have actually exerted an undue influence on the estimates. DFBETA statistics are recommended to quantify how much each coefficient would change if a specific observation were omitted from the dataset. IV. Code Illustrations: Python and RBelow are examples of how to fit a multiple linear regression model and generate the necessary diagnostic plots in both Python
OLS Regression Results
==============================================================================
Dep. Variable: Y R-squared: 0.810
Model: OLS Adj. R-squared: 0.808
Method: Least Squares F-statistic: 420.6
Date: Fri, 24 Jul 2026 Prob (F-statistic): 7.92e-72
Time: 16:58:45 Log-Likelihood: -821.84
No. Observations: 200 AIC: 1650.
Df Residuals: 197 BIC: 1660.
Df Model: 2
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
const 25.7620 7.528 3.422 0.001 10.917 40.607
X1 2.2881 0.114 20.148 0.000 2.064 2.512
X2 -1.2151 0.054 -22.687 0.000 -1.321 -1.110
==============================================================================
Omnibus: 1.716 Durbin-Watson: 1.916
Prob(Omnibus): 0.424 Jarque-Bera (JB): 1.565
Skew: 0.217 Prob(JB): 0.457
Kurtosis: 3.012 Cond. No. 822.
==============================================================================
Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
# 1. Generate Synthetic Data
set.seed(42)
n <- 200
X1 <- rnorm(n, mean=50, sd=10)
X2 <- rnorm(n, mean=100, sd=20)
# Create outcome with normal noise
Y <- 15 + 2.5*X1 - 1.2*X2 + rnorm(n, mean=0, sd=15)
data <- data.frame(Y, X1, X2)
# 2. Fit the Linear Regression Model
model <- lm(Y ~ X1 + X2, data=data)
# Print model summary (Contains F-test, RSS, and coefficients)
print(summary(model))
# 3. Residual Diagnostics
# R has built-in diagnostic plots that are generated by plotting the model object
par(mfrow=c(2,2)) # Set up a 2x2 grid for plots
# Plot 1: Residuals vs Fitted (checks linearity and constant variance)
# Plot 2: Normal Q-Q (checks normality of residuals)
# Plot 3: Scale-Location (checks homoscedasticity)
# Plot 4: Residuals vs Leverage (checks for influential points / high leverage)
plot(model)