2. Working with Time Series

Linear regression analysis (2/3)

Step 2: Calculating the slope cont.

We consider the July temperatures, again converted to points P( x i , y i ) with i=1, ..., 6, as given in the data table.

Year xi yi
2003 1.58 19.69
2004 2.58 17.38
2005 3.58 18.98
2006 4.58 21.12
2007 5.58 18.23
2008 6.58 18.67

We already calculated the centroid P( x ¯ , y ¯ ) of the data points which is at x ¯ =4.08 and y ¯ =19.01 .

The slope a of the best-fit line

f(x)=ax+b

which has the smallest distance to the data points is calculated according to the method of the least squares fit to:

a= i=1 n ( x i x ¯ )( y i y ¯ ) i=1 n ( x i x ¯ ) 2

Again, you will find this relation derived in supplement 1 in detail. With our temperature data one calculates:

a= ( x 1 x ¯ )( y 1 y ¯ )+...+( x 6 x ¯ )( y 6 y ¯ ) ( x 1 x ¯ ) 2 +...+ ( x 6 x ¯ ) 2 =0.0117

We use now the point-slope form to calculate the best-fit straight line:

f(x) y ¯ =a(x x ¯ )


Step 3: Calculating the intercept

The intercept b of the best-fit line is calculated by re-arranging the equation above:

b= y ¯ a x ¯ =19.01

Finally, the best-fit line becomes:

f(x)=0.0117x+19.01
Zoom Sign
points in the diagram and best-fit line
Data points, their centroid P( x ¯ , y ¯ ) and linear best-fit line f(x)=ax+b .

Converted to seawater temperatures in July, the best-fit line reads:

T(t)=0.0117t+42.50

where T is the temperature in °C and t is the calendar year.

Zoom Sign
Temperatures in July and best-fit line
Seawater temperature near Spiekeroog in July 2003-2008, mean July temperature in these years, and linear temperature trend.