% The following data give the time between eruptions
% and the duration of 222 different 
% eruptions of Old Faithful taken over a number of days 
% in August 1978 and August 1979.   All times are in minutes.
% (From Applied Linear Regression, 2nd Edition,  Wiley
% by Sanford Weisberg, pp. 231 and 234.)  
close all
clear all

oldfaith=[...
1       78      4.4
1       74      3.9
1       68      4.0
1       76      4.0
1       80      3.5
1       84      4.1
1       50      2.3
1       93      4.7
1       55      1.7
1       76      4.9
1       58      1.7
1       74      4.6
1       75      3.4
2       80      4.3
2       56      1.7
2       80      3.9
2       69      3.7
2       57      3.1
2       90      4.0
2       42      1.8
2       91      4.1
2       51      1.8
2       79      3.2
2       53      1.9
2       82      4.6
2       51      2.0
3       76      4.5
3       82      3.9
3       84      4.3
3       53      2.3
3       86      3.8
3       51      1.9
3       85      4.6
3       45      1.8
3       88      4.7
3       51      1.8
3       80      4.6
3       49      1.9
3       82      3.5
4       75      4.0
4       73      3.7
4       67      3.7
4       68      4.3
4       86      3.6
4       72      3.8
4       75      3.8
4       75      3.8
4       66      2.5
4       84      4.5
4       70      4.1
4       79      3.7
4       60      3.8
4       86      3.4
5       71      4.0
5       67      2.3
5       81      4.4
5       76      4.1
5       83      4.3
5       76      3.3
5       55      2.0
5       73      4.3
5       56      2.9
5       83      4.6
5       57      1.9
5       71      3.6
5       72      3.7
5       77      3.7
6       55      1.8
6       75      4.6
6       73      3.5
6       70      4.0
6       83      3.7
6       50      1.7
6       95      4.6
6       51      1.7
6       82      4.0
6       54      1.8
6       83      4.4
6       51      1.9
6       80      4.6
6       78      2.9
7       81      3.5
7       53      2.0
7       89      4.3
7       44      1.8
7       78      4.1
7       61      1.8
7       73      4.7
7       75      4.2
7       73      3.9
7       76      4.3
7       55      1.8
7       86      4.5
7       48      2.0
8       77      4.2
8       73      4.4
8       70      4.1
8       88      4.1
8       75      4.0
8       83      4.1
8       61      2.7
8       78      4.6
8       61      1.9
8       81      4.5
8       51      2.0
8       80      4.8
8       79      4.1
16      82      4.1
16      80      4.2
16      76      4.5
16      56      1.9
16      82      4.7
16      47      2.0
16      76      4.7
16      61      2.5
16      75      4.3
16      72      4.4
16      74      4.4
16      69      4.3
16      78      4.6
16      52      2.1
17      91      4.8
17      66      4.1
17      71      4.0
17      75      4.0
17      81      4.4
17      77      4.1
17      74      4.3
17      70      4.0
17      83      3.9
17      53      3.2
17      82      4.5
17      62      2.2
17      73      4.7
17      84      4.6
18      58      2.2
18      82      4.8
18      77      4.3
18      75      3.8
18      77      4.0
18      77      4.1
18      53      1.8
18      75      4.4
18      78      4.0
18      51      2.2
18      81      5.1
18      52      1.9
18      76      5.0
18      73      4.4
19      84      4.5
19      72      3.8
19      89      4.3
19      75      4.4
19      57      2.2
19      81      4.8
19      49      1.9
19      87      4.7
19      43      1.8
19      94      4.8
19      45      2.0
19      81      4.4
19      59      2.5
19      82      4.3
20      80      4.4
20      54      1.9
20      75      4.7
20      73      4.3
20      57      2.2
20      80      4.7
20      51      2.3
20      77      4.6
20      66      3.3
20      77      4.2
20      60      2.9
20      86      4.6
20      62      3.3
20      75      4.2
20      67      2.6
20      69      4.6
21      84      3.7
21      58      1.8
21      90      4.7
21      82      4.5
21      71      4.5
21      80      4.8
21      51      2.0
21      80      4.8
21      62      1.9
21      84      4.7
21      51      2.0
21      81      5.1
21      83      4.3
21      84      4.8
22      72      3.0
22      54      2.1
22      75      4.6
22      74      4.0
22      51      2.2
22      91      5.1
22      60      2.9
22      80      4.3
22      54      2.1
22      80      4.7
22      70      4.5
22      60      1.7
22      86      4.2
22      78      4.3
23      51      1.7
23      83      4.4
23      76      4.2
23      51      2.2
23      90      4.7
23      71      4.0
23      49      1.8
23      88      4.7
23      52      1.8
23      79      4.5
23      61      2.1
23      81      4.2
23      48      2.1
23      84      5.2
23      63      2.0
];

mean(oldfaith)
date = oldfaith(:,1);      %1-8 Aug 1978 + 16-23 August 1979
interval = oldfaith(:,2);  %time interval to next erruption (y)
duration = oldfaith(:,3);   %duration of erruption (x)
figure(1)
plot(duration, interval, 'o')
hold on
X = [ones(size(duration)) duration];
[betahat,Ibeta,res,Ires,stats] = regress(interval, X)
xlabel('Duration')
ylabel('Interval')
x2 = 1:6;
y2 = betahat(1) + betahat(2)*x2;
plot(x2,y2,'r')
title('{\bf Old Faithful Regression}')




