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̄。