📚 Least Squares Linear Regression | 最小二乘线性回归
In Edexcel A-Level Mathematics, least squares linear regression is a core statistical technique used to model the linear relationship between two variables. It gives the straight line that best fits a set of bivariate data by minimising the sum of the squared vertical distances from the data points to the line.
在Edexcel A-Level数学中,最小二乘线性回归是一种核心统计方法,用于建立两个变量之间线性关系的模型。它通过最小化数据点到直线的竖直距离的平方和,给出最适合一组双变量数据的直线。
1. What Is Least Squares Linear Regression? | 什么是最小二乘线性回归?
Least squares linear regression aims to find a line of the form y = a + bx that best describes how a response variable y depends on an explanatory variable x. ‘Best’ means that the sum of the squares of the residuals is made as small as possible.
最小二乘线性回归旨在找到一条形如 y = a + bx 的直线,用来最好地描述响应变量 y 如何依赖于解释变量 x。这里的“最好”是指残差的平方和被尽可能减小。
A residual is the vertical difference between an observed y-value and the value predicted by the regression line. If the predicted value is written as ŷ = a + bx, then the residual for the i-th point is yᵢ − (a + bxᵢ).
残差是指观测到的 y 值与回归直线预测值之间的竖直差。如果把预测值写成 ŷ = a + bx,那么第 i 个点的残差就是 yᵢ − (a + bxᵢ)。
The least squares method minimises the quantity Σ(yᵢ − (a + bxᵢ))². This gives a unique line for any data set with at least two distinct x-values, provided the points are not collinear in a vertical sense.
最小二乘法最小化的是 Σ(yᵢ − (a + bxᵢ))²。对于任何至少有两个不同 x 值的数据集,只要数据点不是竖直共线,它就会给出唯一的直线。
2. The Regression Line Equation | 回归直线方程
For the regression of y on x, the least squares regression line is usually written in the form:
对于 y 对 x 的回归,最小二乘回归直线通常写成如下形式:
y = a + bx
Here b is the gradient or slope of the line, and a is the y-intercept. The gradient b tells you the estimated change in y for each one-unit increase in x. The intercept a is the predicted value of y when x = 0.
其中 b 是直线的斜率或梯度,a 是 y 轴截距。斜率 b 表示 x 每增加一个单位时 y 的估计变化量。截距 a 是当 x = 0 时 y 的预测值。
In this context, x is called the explanatory or independent variable, while y is called the response or dependent variable. The phrase ‘regression of y on x’ means that y is being modelled as a function of x.
在这种情境下,x 被称为解释变量或自变量,y 被称为响应变量或因变量。“y 对 x 的回归”意味着把 y 作为 x 的函数来建模。
3. Calculating the Gradient b | 计算斜率 b
The gradient b is calculated using the formula:
斜率 b 使用以下公式计算:
b = Sxy / Sxx
Here Sxy is the sum of the products of deviations from the means, and Sxx is the sum of squares of deviations of x from its mean. They are given by:
其中 Sxy 是偏差乘积和,Sxx 是 x 相对于其均值的偏差平方和。它们的公式如下:
Sxx = Σ(xᵢ − x̄)² = Σxᵢ² − (Σxᵢ)²/n
Sxy = Σ(xᵢ − x̄)(yᵢ − ȳ) = Σxᵢyᵢ − (Σxᵢ)(Σyᵢ)/n
In these formulas, x̄ and ȳ are the means of the x-values and y-values, and n is the number of data pairs. The second version of each formula is usually easier for calculation because it avoids finding individual deviations.
在这些公式中,x̄ 和 ȳ 分别是 x 值和 y 值的平均数,n 是数据对的个数。每个公式的第二个形式通常更便于计算,因为它避免了逐个计算偏差。
It is important to remember that Sxy measures the joint variability of x and y, while Sxx measures only the variability of x. Dividing Sxy by Sxx gives the estimated rate of change of y with respect to x.
重要的是要记住,Sxy 衡量的是 x 和 y 的共同变异性,而 Sxx 只衡量 x 的变异性。将 Sxy 除以 Sxx 就得到了 y 关于 x 的估计变化率。
4. Calculating the Intercept a | 计算截距 a
Once the gradient b has been found, the intercept a is calculated using the means of the data:
一旦求出斜率 b,就可以使用数据均值计算截距 a:
a = ȳ − b x̄
This formula follows directly from the fact that the regression line always passes through the mean point (x̄, ȳ). If you substitute x̄ into y = a + bx, you obtain ȳ = a + b x̄, and rearranging gives the formula for a.
这个公式直接来自回归直线总是通过均值点 (x̄, ȳ) 这一事实。如果将 x̄ 代入 y = a + bx,就会得到 ȳ = a + b x̄,移项后就得到了 a 的公式。
In some exam questions, calculating a before b may seem tempting, but the standard procedure is to find b first using Sxy and Sxx, then use the mean point to find a. This reduces rounding errors.
在一些考试题中,先计算 a 可能看起来很有吸引力,但标准步骤是先使用 Sxy 和 Sxx 求出 b,然后利用均值点求 a。这样可以减少舍入误差。
5. Worked Example: Full Calculation | 完整计算示例
Consider the following bivariate data: x = 1, 2, 3, 4, 5 and y = 2, 3, 5, 5, 7. We will calculate the least squares regression line of y on x.
考虑以下双变量数据:x = 1, 2, 3, 4, 5,y = 2, 3, 5, 5, 7。我们将计算 y 对 x 的最小二乘回归直线。
First construct a table to organise the sums:
首先构造一个表格来整理各项和:
| x | y | xy | x² |
| 1 | 2 | 2 | 1 |
| 2 | 3 | 6 | 4 |
| 3 | 5 | 15 | 9 |
| 4 | 5 | 20 | 16 |
| 5 | 7 | 35 | 25 |
| Σx = 15 | Σy = 22 | Σxy = 78 | Σx² = 55 |
The means are x̄ = 15/5 = 3 and ȳ = 22/5 = 4.4. Now calculate Sxy and Sxx:
平均数为 x̄ = 15/5 = 3 和 ȳ = 22/5 = 4.4。现在计算 Sxy 和 Sxx:
Sxy = 78 − (15 × 22)/5 = 78 − 66 = 12
Sxx = 55 − (15)²/5 = 55 − 45 = 10
Then the gradient is b = 12/10 = 1.2. The intercept is a = 4.4 − 1.2 × 3 = 0.8. Therefore the least squares regression line is:
因此斜率为 b = 12/10 = 1.2。截距为 a = 4.4 − 1.2 × 3 = 0.8。所以最小二乘回归直线为:
y = 0.8 + 1.2x
This line can be used to predict y for given x-values. For example, when x = 3, the predicted y is 0.8 + 1.2 × 3 = 4.4, which equals the observed mean value at x = 3.
这条直线可以用来预测给定 x 值时的 y。例如当 x = 3 时,预测的 y 为 0.8 + 1.2 × 3 = 4.4,这与 x = 3 处的观测均值一致。
6. Using Coding to Simplify Data | 使用编码简化数据
In Edexcel exam questions, the data may be large or have awkward units. Coding can simplify calculations by transforming the original variables into smaller numbers. For example, let u = (x − m)/c and v = (y − d)/e, where m, c, d and e are constants.
在Edexcel考试题中,数据可能很大或单位不便。编码可以通过将原始变量转换为较小的数来简化计算。例如,令 u = (x − m)/c 和 v = (y − d)/e,其中 m、c、d 和 e 是常数。
If the regression line of v on u is v = α + βu, then you can convert back to a relationship between y and x. Since x = m + cu and y = d + ev, substituting gives:
如果 v 对 u 的回归直线为 v = α + βu,那么你可以转换回 y 与 x 之间的关系。因为 x = m + cu 且 y = d + ev,代入后得到:
y = d + eα + (eβ/c)(x − m)
The gradient in the original variables is eβ/c, and the intercept can be found by expanding and simplifying. Coding does not change the underlying relationship; it only changes the numerical scale used for calculation.
原始变量中的斜率为 eβ/c,截距可以通过展开和化简得到。编码不会改变基本关系,它只改变计算中使用的数值尺度。
A common choice for coding is to subtract a central value or to divide by a power of 10. Always write the coding clearly and remember to convert your final regression equation back to the original variables.
编码的常见选择是减去一个中心值或除以 10 的幂。始终清楚地写出编码方式,并记住将最终的回归方程转换回原始变量。
7. Interpreting the Regression Line | 回归直线的解释
The gradient b has a practical interpretation: for every one-unit increase in x, y is predicted to change by b units. If b is positive, the relationship is positive; if b is negative, the relationship is negative.
斜率 b 具有实际解释:x 每增加一个单位,y 预计会变化 b 个单位。如果 b 为正,则关系为正相关;如果 b 为负,则关系为负相关。
The intercept a is the predicted value of y when x equals zero. However, if x = 0 is outside the range of the observed data, the intercept may not have a meaningful real-world interpretation.
截距 a 是当 x 等于零时 y 的预测值。但是,如果 x = 0 在观测数据范围之外,截距可能没有实际意义。
You should always interpret the regression equation in context. For the example above, the gradient 1.2 means that for each additional unit of x, y is predicted to increase by 1.2 units.
你应该始终结合具体情境解释回归方程。对于上面的例子,斜率 1.2 表示 x 每增加一个单位,y 预计增加 1.2 个单位。
8. Predictions, Interpolation and Extrapolation | 预测、内插与外推
Using the regression line to estimate y for an x-value inside the observed range is called interpolation. This is generally reliable provided the linear model is a good fit.
使用回归直线估计观测范围内某个 x 值对应的 y 值称为内插。只要线性模型拟合良好,这种做法通常可靠。
Using the regression line to estimate y for an x-value outside the observed range is called extrapolation. Extrapolation can be unreliable because there is no evidence that the linear relationship continues beyond the data.
使用回归直线估计观测范围之外某个 x 值对应的 y 值称为外推。外推可能不可靠,因为没有证据表明线性关系在数据范围之外仍然成立。
The regression line is only a model. It cannot prove that changes in x cause changes in y. Always be cautious about making causal claims from a regression equation.
回归直线只是一个模型。它不能证明 x 的变化会导致 y 的变化。从回归方程中得出因果结论时一定要谨慎。
9. Exam Tips and Common Mistakes | 考试技巧与常见错误
When answering regression questions, always show your calculation of Sxy and Sxx before finding b and a. Edexcel examiners award method marks for these intermediate steps.
在解答回归问题时,始终先展示 Sxy 和 Sxx 的计算,再求 b 和 a。Edexcel考官会为这些中间步骤给方法分。
Common mistakes include:
常见错误包括:
- Confusing the regression of y on x with the regression of x on y. The denominator is Sxx for y on x, but Syy for x on y.
- 将 y 对 x 的回归与 x 对 y 的回归混淆。y 对 x 的回归分母是 Sxx,而 x 对 y 的回归分母是 Syy。
- Using Σx² instead of (Σx)² in the formula for Sxx. They are not the same.
- 在 Sxx 公式中将 Σx² 与 (Σx)² 混用。它们并不相同。
- Rounding intermediate values too early, which can lead to an inaccurate final equation.
- 过早舍入中间值,这会导致最终方程不准确。
- Forgetting to convert coded variables back to the original variables.
- 忘记将编码变量转换回原始变量。
Always check that your regression line gives the correct mean point by substituting (x̄, ȳ) into the equation. This can help you spot arithmetic errors.
始终通过将 (x̄, ȳ) 代入方程来检查回归直线是否通过均值点。这可以帮助你发现算术错误。
10. Quick Summary | 快速总结
The key formulas for least squares linear regression of y on x are:
y 对 x 的最小二乘线性回归的关键公式为:
b = Sxy / Sxx
a = ȳ − b x̄
Sxx = Σxᵢ² − (Σxᵢ)²/n
Sxy = Σxᵢyᵢ − (Σxᵢ)(Σyᵢ)/n
Remember that the regression line always passes through the mean point (x̄, ȳ). The gradient gives the estimated change in y per unit increase in x, and predictions outside the observed data range should be treated with caution.
记住回归直线总是通过均值点 (x̄, ȳ)。斜率给出 x 每增加一个单位时 y 的估计变化量,而对观测数据范围之外的预测应谨慎对待。
Published by TutorHao | Mathematics Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导