|
>It might be a bit stupid question, but I've started to use curve fitting
>toolbox, and
>I wonder if there is a way to fit a specially formed curve to only a part
>of the data points,
>without knowing beforehand wich part to fit.
Hi Grygory
From the sounds of things, you're interested in a change point detection
algorithm. (You need an algorithm that is able to detect the most likely
point in time at which your data set is flipping from model 1 to model 2).
Unfortunately, neither Curve Fitting Toolbox nor Statistics Toolbox have any
change point detection algorithms available by default. With this said and
done, MATLAB is a really great platform for implementing change point
detection algorithms.
Here's a few pointers that you might find useful:
If you google change point + MATLAB + Bayesian you can find a lot of useful
citations.
I personally found "Bayesian Econometric Methods" by Koop, Poirier, and
Tobias pretty easy to follow. The "Computational Statistics Handbook with
MATLAB" by Martinez and Martinez is another useful source with pretty
accessible source code.
The CUSUM algorithm is an oldie but goodie... Base MATLAB includes an
algorithm called CUMSUM which can be easily modified for this type of work.
However, you might find the follow example easier to understand
%% Random data
clear all
clc
% Create A
A = randn(100,1);
A = A+100;
B = randn(100,1);
B = B + 101;
data = [A;B];
% Calculate the Cumulate Sum
%Calculate the average
mu = mean(data);
% Initialize the cumulative sum
CUSUM = zeros(length(data)+1,1);
CUSUM(1) = 0 + data(1) - mu;
%CUMSUM Loop
for i = 2:length(data)
CUSUM(i) = CUSUM(i-1) + (data(i) - mu);
end
plot(CUSUM)
% Find the inflection point
X = linspace(1,length(CUSUM),length(CUSUM));
X = X';
Y = CUSUM;
cfun = fit(X,Y,'poly2');
upordown = differentiate(cfun,1);
if upordown < 0, index = find(CUSUM == min(CUSUM))
else
index = find(CUSUM == max(CUSUM));
end;
index
|