Correlation and regression

Enter X and Y values to get a scatter plot, the correlation, the regression line and predictions.

Question: Do two measurements change together? Knowing one, how well can the other be predicted?
Example: Yield (kg/da) at different nitrogen rates (kg/da). Is there a relationship between nitrogen and yield, and how much does yield rise as the rate increases?

n = 7, mean 9

n = 7, mean 376

300350400051015(0; 285)(3; 320)(6; 362)(9; 390)(12; 415)(15; 428)(18; 432)Nitrogen rate (kg/da)Yield (kg/da)

Dots are the measurements, the line is the regression line. The green dot is the prediction for your X.

Regression equation

y^=299.93+8.452 x\hat{y} = 299.93 + 8.452\,x

Correlation (r)
0.969
Determination (R²)
93.9%
Prediction for x = 10
384.45

When X increases by one unit, Y increases by 8.452 units on average. 93.9% of the variation in Y is explained by X; the relationship is strong.

  1. Slope (b): how much Y changes on average when X increases by one unit.

    b=SxySxx=2130252=8.4524b = \dfrac{S_{xy}}{S_{xx}} = \dfrac{2130}{252} = 8.4524
  2. Intercept (a): makes the line pass through the mean point (x̄, ȳ).

    a=yˉ−b xˉ=376−8.4524⋅9=299.9286a = \bar{y} - b\,\bar{x} = 376 - 8.4524 \cdot 9 = 299.9286
  3. Regression equation:

    y^=299.929+8.4524 x\hat{y} = 299.929 + 8.4524\,x
  4. Coefficient of determination: the share of the variation in Y explained by X.

    R2=r2=0.9392  (93.9%)R^2 = r^2 = 0.9392 \;(93.9\%)

Is the relationship significant?

H0:ρ=0H_0: \rho = 0H1:ρ≠0H_1: \rho \neq 0
-6-4-20246-2.5712.571calculated 8.78 →t (df = 5)

The red area is the rejection region (α = 0.05). The green line is the value calculated from your data.

H₀ rejected: the difference is significant

There is a strong, positive (as one increases, so does the other) and statistically significant relationship between X and Y.

p-value = 0.0003 (significant at 1%, **)

Correlation is not causation: two variables changing together does not mean one causes the other.

How was it calculated?

tcalct_{calc} = 8.785

  1. Compute the corrected sums of squares and products.

    Sxx=∑x2−(∑x)2n=252S_{xx} = \sum x^2 - \dfrac{(\sum x)^2}{n} = 252
  2. Syy=∑y2−(∑y)2n=19170S_{yy} = \sum y^2 - \dfrac{(\sum y)^2}{n} = 19170
  3. Sxy=∑xy−∑x∑yn=2130S_{xy} = \sum xy - \dfrac{\sum x \sum y}{n} = 2130
  4. Correlation coefficient: the direction and strength of the relationship (between −1 and +1).

    r=SxySxx⋅Syy=2130252⋅19170=0.9691r = \dfrac{S_{xy}}{\sqrt{S_{xx} \cdot S_{yy}}} = \dfrac{2130}{\sqrt{252 \cdot 19170}} = 0.9691
  5. A t test checks whether r differs from zero.

    t=rn−21−r2=0.969151−0.9392=8.785t = \dfrac{r\sqrt{n-2}}{\sqrt{1-r^2}} = \dfrac{0.9691\sqrt{5}}{\sqrt{1-0.9392}} = 8.785
  6. Compare the calculated value with the table (critical) value.

    ∣tcalc∣=8.785>ttab=2.571|t_{calc}| = 8.785 > t_{tab} = 2.571
  7. The calculated value is in the rejection region: H₀ is rejected. The p-value (0.0003) is smaller than α = 0.05.