GNGiseldo Neo and Alana NeoBooks
Linear Regression with Python5 / 19

Mathematical Foundations

4.1 Concept of Independent and Dependent Variables

In linear regression, variables play distinct roles and are categorized as independent or dependent:

  • Dependent Variable (Response): The variable we want to predict or explain. In the context of regression, it is denoted by yy.

  • Independent Variables (Predictors): The variables we use to make predictions about the dependent variable. They are denoted by x1,x2,…,xnx_1, x_2, \ldots, x_n. The premise is that these variables directly influence the value of yy.

The relationship between the variables is expressed by a linear equation, in which the value of yy is computed based on the independent variables.

4.2 Linear Function and the Equation of a Line

A linear function is a mathematical expression that describes a straight line. In its simplest form, for a single independent variable, the equation of a line is:

y=β0+β1xy = \beta_0 + \beta_1x

where:

  • β0\beta_0 is the intercept, representing the point where the line crosses the yy-axis.

  • β1\beta_1 is the slope coefficient, indicating the steepness of the line—that is, how yy changes as xx changes.

For multiple independent variables, the equation expands to:

y=β0+β1x1+β2x2+⋯+βnxny = \beta_0 + \beta_1x_1 + \beta_2x_2 + \cdots + \beta_nx_n

This equation represents a hyperplane in nn-dimensional space, where each coefficient β\beta shapes the orientation of the hyperplane.

4.3 The Method of Least Squares

The method of least squares is a technique used to estimate the coefficients β\beta that minimize the sum of the squared differences between the observed values yiy_i and the predicted values y^i\hat{y}_i:

Sum of Squared Residuals (SSR)=∑i=1m(yi−y^i)2\textit{Sum of Squared Residuals (SSR)} = \sum_{i=1}^{m} (y_i - \hat{y}_i)^2

where:

  • yiy_i is the observed value;

  • y^i\hat{y}_i is the value predicted by the regression equation.

The goal is to find the values of β\beta that minimize the SSR, leading to the line of best fit. The solution to this optimization problem is given by the formula:

β=(XTX)−1XTy\beta = (X^TX)^{-1}X^Ty

where XX is the data matrix including the constant term, XTX^T is the transpose of XX, and yy is the vector of response values.

4.4 Regression Coefficients and Interpretation

Regression coefficients are essential for interpreting a linear model. Each coefficient βi\beta_i represents the expected change in the dependent variable yy for a one-unit change in the independent variable xix_i, holding all other variables constant.

  • Intercept (β0\beta_0): Indicates the expected value of yy when all independent variables are equal to zero.

  • Coefficients (βi\beta_i): Represent the slope of the hyperplane with respect to each independent variable. A positive coefficient suggests that an increase in the independent variable leads to an increase in yy, whereas a negative coefficient suggests the opposite.

It is important to examine the statistical significance of each coefficient, often using tt-tests, to determine whether the relationship between the variables is genuinely significant or merely due to chance.