Each extra unit of x goes with a change of 3.1091 in y on average, and the line accounts for 99.33% of the variation in y. At x = 7.5 the fitted value is 72.2091.
Data and fitted curve
Datay = 48.890909 + 3.109091x
Residuals
ResidualZero
Coefficients (t tests with 8 degrees of freedom) 行数:2
Linear regression calculator (line of best fit)について
Least squares picks the line or curve that makes the sum of squared vertical distances from the points as small as possible. For a straight line the slope is b₁ = Sxy/Sxx and the intercept b₀ = ȳ − b₁x̄; polynomial fits of degree 2 to 4 solve the normal equations, and the exponential model fits a straight line to ln y. Each coefficient gets a standard error, a t statistic and a p-value, and R² gives the share of the variation in y that the fit accounts for.
The default relates weekly study hours to exam scores for 10 students. The fitted line is y = 48.89 + 3.109x, so each extra hour goes with about 3.1 more points, R² is 0.9933, and at 7.5 hours the line predicts 72.2.
The standard errors and p-values assume independent residuals with constant spread. A curved or funnel-shaped residual plot means the model is missing something, and predictions outside the range of the x data are flagged as extrapolations.
計算例
Exact straight line y = 1 + 2x
x values
1, 2, 3
y values
3, 5, 7
Model
Linear
Predict y at x
4
Fitted equation
y = 1 + 2x
Intercept b₀
1
Slope / x coefficient b₁
2
R²
1
Predicted y
9
照合元:Constructed points (1,3), (2,5), (3,7) lie exactly on y = 1 + 2x; at x = 4, y = 9.
Study hours vs score (linear)
x values
2, 3, 4, 5, 6, 7, 8, 9, 10, 11
y values
55, 58, 62, 64, 68, 71, 72, 78, 80, 83
Model
Linear
Predict y at x
7.5
Slope / x coefficient b₁
3.109091
Intercept b₀
48.890909
R²
0.993252
Adjusted R²
0.992408
Residual standard error
0.822966
Standard error of b₁
0.090606
Standard error of b₀
0.643873
Predicted y
72.209091
Correlation r
0.99662
照合元:Python fractions: b₁ = Sxy/Sxx, b₀ = ȳ − b₁x̄, se = √(SSE/(n − 2)) with decimal square roots
Quadratic trend
x values
1, 2, 3, 4, 5, 6, 7, 8
y values
2.1, 3.9, 8.2, 14.8, 24.1, 35.9, 50.2, 66.8
Model
Polynomial
Degree
2 (quadratic)
Intercept b₀
2.85
Slope / x coefficient b₁
-1.980952
x² coefficient b₂
1.247619
R²
0.999994
Residual standard error
0.069007
照合元:Python fractions solving the 3×3 normal equations exactly (b₀ = 57/20, b₁ = −208/105, b₂ = 131/105); agrees with numpy.polyfit(x, y, 2)
Exact quartic y = 1 + x + x² + x³ + x⁴
x values
0 1 2 3 4 5 6 7 8 9 10
y values
1 5 31 121 341 781 1555 2801 4681 7381 11111
Model
Polynomial
Degree
4 (quartic)
Predict y at x
11
Intercept b₀
1
Slope / x coefficient b₁
1
x² coefficient b₂
1
x³ coefficient b₃
1
x⁴ coefficient b₄
1
R²
1
Predicted y
16,105
照合元:Constructed data: y = 1 + x + x² + x³ + x⁴ exactly, so every coefficient is 1 and R² = 1; 1 + 11 + 121 + 1331 + 14641 = 16105
よくある質問
How do you calculate the line of best fit?
Find the means x̄ and ȳ, then the slope b₁ = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² and the intercept b₀ = ȳ − b₁x̄. For the default study-hours data, Sxy = 256.5 and Sxx = 82.5, so b₁ = 3.109 and b₀ = 48.89. This least-squares line minimizes the sum of squared vertical distances, as set out in the NIST/SEMATECH e-Handbook (§4.1.4.1).
What does R² tell you in regression?
R² is the fraction of the variation in y that the model accounts for: R² = 1 − SSE/SST. The default fit has R² = 0.9933, so study hours account for 99.3% of the spread in exam scores. For a straight line R² equals the square of the correlation r. A high R² does not show that x causes y, that the model has the right shape, or that predictions beyond the data will hold.
What is the difference between R² and adjusted R²?
Adjusted R² charges for each extra coefficient: 1 − (1 − R²)(n − 1)/(n − k), where k counts the coefficients including the intercept. R² never falls when a term is added, so a quartic always fits at least as well as a quadratic; adjusted R² falls when the new term explains less than it costs. For the default data, n = 10 and k = 2 turn R² = 0.99325 into 0.99241.
What does the p-value of the slope mean?
It tests the null hypothesis that the true slope is 0, using t = b₁/SE(b₁) with n − 2 degrees of freedom. For the default data t = 3.109/0.0906 = 34.3 with 8 df, giving p = 5.7 × 10⁻¹⁰: a slope this steep would be very unlikely if hours and scores had no linear relation. The p-value says nothing about how large or important the effect is.
When should I use an exponential fit instead of a straight line?
When y grows or shrinks by a roughly constant percentage for each unit of x, so that ln y against x is straight. The exponential example, with y rising from 3.0 to 22.1 as x goes from 0 to 5, fits y = 2.98·e^(0.4007x), an increase of 49.3% per unit of x. The fit is made on ln y, as Excel's LOGEST function does, so R² describes ln y rather than y.
「Linear regression calculator (line of best fit)」の精度はどのくらいですか?
精度は入力値と計算方法の前提に依存します。十進演算には有効数字50桁を使いますが、推定、数値計算手法、元データの精度はそれより低い場合があります。表示の丸め処理でこれらの制約がなくなるわけではありません。 独立した出典の解答と照合した計算例:5。 例えば、「Exact straight line y = 1 + 2x」はConstructed points (1,3), (2,5), (3,7) lie exactly on y = 1 + 2x; at x = 4, y = 9と照合しています。
この計算方法の出典は何ですか?
NIST/SEMATECH e-Handbook of Statistical Methods, §4.1.4.1 Linear least squares regression; NIST Statistical Reference Datasets — linear regression; Draper & Smith, Applied Regression Analysis, 3rd ed. (Wiley, 1998), ch. 1 and 12.