Least-Squares Linear Regression Calculator
Enter paired (x, y) data to fit the best-fit line by least squares and get the slope, intercept and R-squared, for trend prediction and variable-relationship modelling.
📐 计算公式
最小二乘线性回归:b=Σ(xᵢ−x̄)(yᵢ−ȳ)÷Σ(xᵢ−x̄)²;a=ȳ−b·x̄;R²=1−SSres/SStot(Y 为常数时无定义);ŷ(x₀)=a+b·x₀。推断:残差标准误 s=√(SSres/(n−2));SE(b)=s/√Sxx、SE(a)=s·√(1/n+x̄²/Sxx);95% CI 用 t(0.975,n−2)。预测点区分均值响应区间(含 1/n 项)与单点预测区间(另加 1)。校验:X、Y 必须非空、逐项为有限数值、长度严格相等且 n≥2;长度不等直接报错,不再按较短长度截断;n=2 时 df=0 无法估计残差方差;残差为 0 时区间退化,不能据此断言模型正确。
由数据拟合最佳直线。
📌 计算说明
- 最小二乘:b=Σ(x−x̄)(y−ȳ)/Σ(x−x̄)²。
- a = ȳ − b x̄。