Linear Regression (y = a + bx)
Statistics
Intro: We fit $\hat{y}=a+bx$, report slope/intercept, and optionally predict $\hat{y}(x_0)$.
Worked example
- $x:1,2,3,4,5;\; y:2,3,5,6,8;\;$ predict at $x=6$
- Goal: Fit the least-squares line $\hat{y}=a+bx$ and then compute $\hat{y}(6)$. We use $$\displaystyle b=\frac{\sum (x_i-\bar{x})(y_i-\bar{y})}{\sum (x_i-\bar{x})^2},\qquad a=\bar{y}-b\bar{x}.$$
- Means: $\displaystyle \bar{x}=\frac{1+2+3+4+5}{5}=3,\quad \bar{y}=\frac{2+3+5+6+8}{5}=\frac{24}{5}=4.8.$
- Deviations in $x$: $(x_i-\bar{x})=(-2,-1,0,1,2)$. Deviations in $y$: $(y_i-\bar{y})=(-2.8,-1.8,0.2,1.2,3.2)$.
- Compute $S_{xx}=\sum (x_i-\bar{x})^2 = (-2)^2+(-1)^2+0^2+1^2+2^2=4+1+0+1+4=10.$
- Compute $S_{xy}=\sum (x_i-\bar{x})(y_i-\bar{y}) = (-2)(-2.8)+(-1)(-1.8)+0(0.2)+1(1.2)+2(3.2) = 5.6+1.8+0+1.2+6.4=15.0.$
- Slope: $\displaystyle b=\frac{S_{xy}}{S_{xx}}=\frac{15}{10}=1.5.$
- Intercept: $\displaystyle a=\bar{y}-b\bar{x}=4.8-(1.5)(3)=4.8-4.5=0.3.$
- Model: $$\boxed{\hat{y}=0.3+1.5x}.$$
- Prediction at $x=6$: $\hat{y}(6)=0.3+1.5\cdot6=0.3+9=9.3.$
- Answer: $$\boxed{\hat{y}=0.3+1.5x,\quad \hat{y}(6)=9.3}.$$
- Check (optional via alternative formula): $$\displaystyle b=\frac{n\sum xy-\sum x\sum y}{n\sum x^2-(\sum x)^2} = \frac{5\cdot87-15\cdot24}{5\cdot55-15^2}=\frac{435-360}{275-225}=\frac{75}{50}=1.5,$$ which matches.
FAQs
Require equal spacing?
No—least squares works for any real x-values (non-constant).
Why choose MathGPT?
- Get clear, step-by-step solutions that explain the “why,” not just the answer.
- See the rules used at each step (power, product, quotient, chain, and more).
- Optional animated walk-throughs to make tricky ideas click faster.
- Clean LaTeX rendering for notes, homework, and study guides.
How this calculator works
- Type or paste your function (LaTeX like
\sin,\lnworks too). - Press Generate a practice question button to generate the derivative and the full reasoning.
- Review each step to understand which rule was applied and why.
- Practice with similar problems to lock in the method.