90 4 BIVARIATE STATISTICS
le agedepth_1.txt. We can de ne two new variables, meters and age,
and generate a scatter plot of the data.
clear
agedepth = load('agedepth_1.txt');
meters = agedepth(:,1);
age = agedepth(:,2);
A signi cant linear trend in the bivariate scatter plot, together with a cor-
relation coe cient of more than r=0.9 suggests a strong linear dependence
between
meters and age. In geological terms, this implies that the sedi-
mentation rate was constant through time. We now try to t a linear model
to the data that will help us predict the age of the sediment at levels for which
we have no age data. e function
polyfit computes the coe cients of a
polynomial p(x) of a speci c degree that ts the data y in a least-squared
sense. In our example, we t a rst degree (linear) polynomial to the data.
p = polyfit(meters,age,1)
p =
5.5760 21.2480
Since we are working with synthetic data, we know the values for the slope
and the intercept with the y-axis. e estimated slope (5.5760) and the in-
tercept with the y-axis (21.2480) are in good agreement with the true values
of 5.6 and 20, respectively. Both the data and the tted line can be plotted
on the same graph.
plot(meters,age,'o'), hold on
plot(meters,p(1)*meters+p(2),'r'), hold off
Instead of using the equation for the regression line, we can also use the
function
polyval to calculate the y-values.
plot(meters,age,'o'), hold on
plot(meters,polyval(p,meters),'r'), hold off
Both, the functions polyfit and polyval are incorporated in the GUI
function
polytool.
polytool(meters,age)
e coe cients p(x) and the equation obtained by linear regression can
now be used to predict y-values for any given x-value. However, we can only
do this within the depth interval for which the linear model was tted, i.e.,