$ Author: Chanel Malherbe $ $Date: 11/1/2006$
This script file tests FTCOR by calculating the correlation of two evenly-spaced synchronous series
clear %clear workspace total = waitbar(0,'Total Progess'); %measure overall progress j = 1; %initialize variables N = 255; %set sample size of series nrsim = 100; %set number of monte carlo simulations
ftac = zeros(nrsim,10); pc = zeros(nrsim,10); errftac = zeros(nrsim,10); errpc = zeros(nrsim,10); kurtftac = zeros(1,10); kurtpc = zeros(1,10); meanftac = zeros(1,10); meanpc = zeros(1,10); stdftac = zeros(1,10); stdpc = zeros(1,10); skewftac = zeros(1,10); skewpc = zeros(1,10); rmseftac = zeros(1,10); rmsepc = zeros(1,10);
%run simulation for different correlation values, k for k = 0.1:0.1:1 %run simulation for i = 1:nrsim waitbar((i + (j-1)*nrsim)/(nrsim * 10),total); clear simdata; clear data; %generate 2 series with correlation k simdata = gencordata(N,k); ftac(i,j) = ftcor([simdata(1:N,1),simdata(1:N,2)],[simdata(1:N,1),simdata(1:N,3)],1,N); temp = corr([simdata(1:N,2),simdata(1:N,3)]); pc(i,j) = temp(2,1); %calculate relative errors if (k > 0) errftac(i,j) = (ftac(i,j) - k)/k; errpc(i,j) = (pc(i,j) - k)/k; end end j = j+1; end close(total); %calculate evaluation statistics i = 1; %repeat for different values of k for k = 0.1:0.1:1 %calculate statistics for fourier method %calculate kurtosis kurtftac(i) = kurtosis(errftac(1:nrsim,i)); kurtpc(i) = kurtosis(errpc(1:nrsim,i)); %calculate bias meanftac(i) = mean(errftac(1:nrsim,i)); meanpc(i) = mean(errpc(1:nrsim,i)); %calculate standard deviation stdftac(i) = std(errftac(1:nrsim,i)); stdpc(i) = std(errpc(1:nrsim,i)); %calculate skewness skewftac(i) = skewness(errftac(1:nrsim,i)); skewpc(i) = skewness(errpc(1:nrsim,i)); %calculate root mean square error rmseftac(i) = 0; rmsepc(i) = 0; for j = 1:nrsim rmseftac(i) = rmseftac(i) + (k - ftac(j,i))^2; rmsepc(i) = rmsepc(i) + (k - pc(j,i))^2; end rmseftac(i) = rmseftac(i)/nrsim; rmsepc(i) = rmsepc(i)/nrsim; i = i+1; end
Warning: Divide by zero. Warning: Divide by zero.
%This table and graph shows the average correlation obtained from both methods. The %first column shows the value of k, the second the correlation obtained %from the Fourier method and the second the correlation obtained from the %Pearson method. The Fourier correlation is shown in green and the pearson %correlation in blue. plot((1:10),(0.1:0.1:1),'r',(1:10),mean(ftac),'g',(1:10),mean(pc),'b'); legend('Induced correlation','Fourier','Pearson','Location','SouthEast') [(0.1:0.1:1)',mean(ftac)',mean(pc)']
ans = 0.1000 0.1097 0.0521 0.2000 0.2038 0.1616 0.3000 0.2937 0.1977 0.4000 0.4028 0.3530 0.5000 0.5019 0.4011 0.6000 0.5937 0.5006 0.7000 0.7014 0.6513 0.8000 0.7992 0.7612 0.9000 0.8996 0.8423 1.0000 1.0000 1.0000
%This table shows the statistics of the relative errors for the Fourier %estimator
for i = 1:9 subplot(3,3,i); hist(errftac(1:nrsim,i)); title(i/10); % axis([-2 2 0 65]); end [(0.1:0.1:1)',kurtftac',skewftac',stdftac',meanftac',rmseftac']
ans = 0.1000 3.1874 -0.1739 0.6352 0.0967 0.0041 0.2000 3.3246 -0.4607 0.3308 0.0190 0.0043 0.3000 2.8184 0.2670 0.1783 -0.0209 0.0029 0.4000 3.7002 -0.2849 0.1166 0.0071 0.0022 0.5000 2.4219 -0.3150 0.0897 0.0038 0.0020 0.6000 3.4100 0.1385 0.0672 -0.0104 0.0016 0.7000 2.3849 0.1207 0.0449 0.0020 0.0010 0.8000 2.8632 -0.3994 0.0276 -0.0010 0.0005 0.9000 2.8949 -0.4981 0.0128 -0.0005 0.0001 1.0000 NaN NaN 0 0 0
%This table shows the statistics of the relative errors for the Pearson %estimator for i = 1:9 subplot(3,3,i); hist(errpc(1:nrsim,i)); title(i/10); % axis([min(errpc(1:nrsim,i) max(errpc(1:nrsim,i) 0 65]); end [(0.1:0.1:1)',kurtpc',skewpc',stdpc',meanpc',rmsepc']
ans = 0.1000 1.9560 -0.0511 4.9508 -0.4788 0.2449 0.2000 2.4390 -0.3397 2.3093 -0.1918 0.2127 0.3000 1.9342 -0.3866 1.5443 -0.3409 0.2230 0.4000 2.4225 -0.6183 1.1427 -0.1176 0.2090 0.5000 2.0373 -0.4792 0.9335 -0.1978 0.2255 0.6000 3.2065 -1.0977 0.7208 -0.1657 0.1950 0.7000 5.5117 -1.6229 0.4879 -0.0696 0.1178 0.8000 8.2788 -2.1644 0.3216 -0.0485 0.0670 0.9000 8.4017 -2.2405 0.2111 -0.0641 0.0391 1.0000 3.1158 0.2542 0.0000 0.0000 0.0000