
4.10 NONLINEAR AND WEIGHTED REGRESSION 103
4 BIVARIATE STATISTICS
[p,s] = polyfit(meters,age,2);
[p_age,delta] = polyval(p,meters,s);
plot(meters,age,'o',meters,p_age,'g',meters,...
p_age+2*delta,'r--',meters,p_age-2*delta,'r--')
axis([0 20 0 700]), grid on
xlabel('Depth in Sediment (meters)')
ylabel('Age of Sediment (kyrs)')
e plot shows that the quadratic model for this data is a good one. e
quality of the result could again be tested by exploring the residuals, by em-
ploying resampling schemes or by cross validation. Combining regression
analysis with one of these methods provides a powerful tool in bivariate
data analysis, whereas Pearson’s correlation coe cient should be used only
as a preliminary test for linear relationships.
4.10 Nonlinear and Weighted Regression
Many bivariate data in earth sciences follow a more complex trend than a
simple linear or curvilinear trend. Classic examples for nonlinear trends are
the exponential decay of radionuclides, or the exponential growth of algae
populations. In such cases, MATLAB provides various tools to t nonlinear
models to the data. An easy-to-use routine to t such models is nonlinear
regression using the function
nlinfit. To demonstrate the use of nlin-
fit we generate a bivariate data set where one variable is exponentially
correlated with a second variable. We rst generate evenly-spaced values
between 0.1 and 3 in 0.1 intervals and add some Gaussian noise with a stan-
dard deviation of 0.2 to make the data unevenly spaced. e resulting 30
data points are stored in the rst column of the variable
data.
clear
randn('seed',0)
data(:,1) = 0.1 : 0.1 : 3;
data(:,1) = data(:,1) + 0.2*randn(size(data(:,1)));
Next, we can compute the second variable, which is the exponent of the rst
variable multiplied by 0.2 and increased by 3. We again add Gaussian noise,
this time with a standard deviation of 0.5, to the data. Finally, we can sort
the data with respect to the rst column and display the result.
data(:,2) = 3 + 0.2 * exp(data(:,1));
data(:,2) = data(:,2) + 0.5*randn(size(data(:,2)));
data = sortrows(data,1);
plot(data(:,1),data(:,2),'o')