% The function implements the converging variance and converging mean tests and it is the new version of the function convvartest.
% The new moment in these functions is that if the length of your vector is too big and you probably can not analize it with the
% current resources of your PC, then you can analize the converging variance and mean by partitioning of vector. For this you must
% follow the next rules:
%
% 1. If your vector is Y and its length is 50000 for example, first you have to partition a vector of 2 pieces for example:
% Y1 = Y(1:25000);
% Y2 = Y(25001:50000);
%
% 2. To analyze first sequence Y1 in the command window type the following:
% [m1, v1, z1] = convvartest_new(Y1);
%
% 3. Then type:
% [m2, v2, z2] = convvartest_new(Y2,z1,Y1);
%
% The evaluated vectors v1 and v2 are the vectors containing the value of running variance for the vector Y. Now you can easily
% plot the converging variance plot for Y, just type the following in the connamd window:
%
% v = horzcat(v1,v2); % this will concatenate the variances in one vector,
% n = 1:length(Y);
% figure;
% plot(n,v,'bd','MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize', 5)
% title('Converging variance');
%
% The evaluated vectors m1 and m2 are the vectors containing the value of running mean for the vector Y. Now you can easily
% plot the converging mean plot for Y, just type the following in the connamd window:
%
% v = horzcat(m1,m2); % this will concatenate the variances in one vector,
% n = 1:length(Y);
% figure;
% plot(n,v,'bd','MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize', 5)
% title('Converging mean');
%
%
%
%
%
% If you find any bug, the author will be very glad to report for it on the
% following e-mail address: zlatkopetrov@yahoo.com.
% Any comments and suggestions would be accepted with appreciation.
%
%
%
% Author: Zlatko Petroff, July 23, 2004
% Last Revision July 26, 2004
%
function [m, v, z] = convvartest_new(X,Z,Xprevious);
if nargin==0, help convvartest_new
return;
end
if nargout==0, help convvartest_new
return;
end
if nargin < 2, N = length(X);
for i = 1:N;
mean_value(i) = (1/i)*(sum(X(1:i)));
temp(i) = (X(i)-mean_value(i))^2;
temp_variance = sum(temp);
variance(i) = (1/(i-1))*temp_variance;
end
n=1:length(variance);
figure
plot(n,variance,'bd','MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',5)
title('Converging Variance');
figure
plot(n,mean_value,'bd','MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',5)
title('Converging mean');
m=mean_value;
v=variance;
z=temp;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if nargin==3, N = length(X);
mm=sum(Xprevious);
vv=sum(Z);
for i = 1:N;
j=i+length(Xprevious);
mean_value(i) = (1/j)*(sum(X(1:i))+mm);
temp(i) = (X(i)-mean_value(i))^2;
temp_variance = sum(temp)+vv;
variance(i) = (1/(j-1))*temp_variance;
n(i)=i:length(variance);
end
m=mean_value;
v=variance;
z=temp;
else
help convvartest_new
return;
end