MatLab 2 Edition Lecture 5:

advertisement
Environmental Data Analysis with MatLab
2nd Edition
Lecture 5:
Linear Models
SYLLABUS
Lecture 01
Lecture 02
Lecture 03
Lecture 04
Lecture 05
Lecture 06
Lecture 07
Lecture 08
Lecture 09
Lecture 10
Lecture 11
Lecture 12
Lecture 13
Lecture 14
Lecture 15
Lecture 16
Lecture 17
Lecture 18
Lecture 19
Lecture 20
Lecture 21
Lecture 22
Lecture 23
Lecture 24
Lecture 25
Lecture 26
Using MatLab
Looking At Data
Probability and Measurement Error
Multivariate Distributions
Linear Models
The Principle of Least Squares
Prior Information
Solving Generalized Least Squares Problems
Fourier Series
Complex Fourier Series
Lessons Learned from the Fourier Transform
Power Spectra
Filter Theory
Applications of Filters
Factor Analysis
Orthogonal functions
Covariance and Autocorrelation
Cross-correlation
Smoothing, Correlation and Spectra
Coherence; Tapering and Spectral Analysis
Interpolation
Linear Approximations and Non Linear Least Squares
Adaptable Approximations with Neural Networks
Hypothesis testing
Hypothesis Testing continued; F-Tests
Confidence Limits of Spectra, Bootstraps
Goals of the lecture
develop and apply the concept of a
Linear Model
data, d
what we measure
quantitative model
links model parameters to data
model parameters, m
what we want to know
data, d
carats, color, clarity
economic model for diamonds
model parameters, m
dollar value, celebrity value
Photo credit: Wikipedia Commons
quantitative model
general case
N = number of observations, d
M = number of model parameters, m
usually (but not always) N>M
many data, a few model parameters
special case of a linear model
=
The matrix G is called the
data kernel
it embodies the quantitative model
the relationship between the data and
the model parameters
because of observational noise
no m can exactly satisfy this equation
it can only be satisfied approximately
d ≈ Gm
data, dpre
prediction of data
evaluate equation
quantitative model
model parameters, mest
estimate of model parameters
data, dobs
observation of data
solve equation
quantitative model
model parameters, mest
estimate of model parameters
because of observational noise
est
m
true
≠m
the estimated model parameters differ from the true model
parameters
and
dpre ≠dobs
the predicted data differ from the observed data
the simplest of linear models
fitting a straight line to data
interpretion of xi
the model is only linear when the xi’s
are neither data nor model parameters
we will call them auxiliary variables
they are assumed to be exactly known
they specify the geometry of the
experiment
MatLab script for G in straight line case
M=2;
G=zeros(N,M);
G(:,1)=1;
G(:,2)=x;
fitting a quadratic curve to data
MatLab script for G in quadratic case
M=3;
G=zeros(N,M);
G(:,1)=1;
G(:,2)=x;
G(:,3)=x.^2;
fitting a sum of known functions
fitting a sum of cosines and sines
(Fourier series)
grey-scale images of data kernels
A) Polynomial
1
1
N
B) Fourier series
1
M
j1
j
N
i
M
i
any data kernel can be thought of
as a concatenation of its columns
G
1
1
N
i
M
c(1)
c(2) c(3) c(4)
c(M)
thought of this way,
the equation d=Gm means
sometimes, models do represent literal
mixing
but more often the mixing is more
abstract
any data kernel also can be thought
of as a concatenation of its rows
thought of this way,
the equation d=Gm means
data is a weighted average of the
model parameters
for example, if
weighted average
sometimes the model represents
literal averaging
data kernels for running averages
A) three points
1
B) five points
M
1
C) seven points
M
1
1
j 1
j 1
N
N
N
i
i
M
j
i
but more often the averaging is more
abstract
MatLab script
data kernel for a running-average
w = [2, 1]';
Lw = length(w);
n = 2*sum(w)-w(1);
w = w/n;
r = zeros(M,1); c = zeros(N,1);
r(1:Lw)=w; c(1:Lw)=w;
G = toeplitz(c,r);
averaging doesn’t have to be symmetric
with this data kernel, each di is a weighted average of mj, with
i≥j, that is, just “past and present” model parameters.
the prediction error
error vector, e
prediction error in straight line case
plot of linedata01.txt
15
10
dipre
d
data,
d
5
ei
diobs
0
-5
-10
-15
-6
-4
-2
0
x
auxiliary variable,
2
x
4
6
total error
single number summarizing the error
sum of squares of individual errors
principle of least-squares
that minimizes
MatLab script for total error
dpre = G*mest;
e=dobs-dpre;
E = e'*e;
grid search
strategy for finding the m that
minimizes E(m)
try lots of combinations of (m1, m2, …)
… a grid of combinations …
pick the combination with the smallest E as mest.
0
0
m2est
4
m2
point of minimum
error, Emin
m1est
region of low
error, E
4
m1
the best m is at the point of minimum E
choose that as mest
but, actually, any m in the region of
low E is almost as good as mest.
especially since E is effected by measurement error
if the experiment was repeated, the results would be
slightly different, anyway
the shape of the region of low error
is related to the
covariance of the estimated model parameters
(more on this in the next lecture)
think about error surfaces leads to important
insights
but actually calculating an error surface with a
grid search so as to locate mest is not very
practical
in the next lecture we will develop a solution to
the least squares problem that doesn’t require
a grid search
Download