552 Homework Helper for Autocorrelation
In Homework 4 you need to estimate the number of degrees of freedom in the data set in order to evaluate the statistical significance of the differences between the eigenvalues using the North, et al test. We can use the rule of thumb relating the temporal autocorrelation to the number of degrees of freedom discussed in Chapter 6, section a of the class notes. Here are some helpful hints about how to get the autocorrelation. First go to the public ftp directory:
ftp eos.atmos.washington.edu
and copy the file auto.m into the directory where you have stored the data files x552a.dat and x552b.dat. Running matlab in that directory, load the data files and then follow the procedure outlined in the matlab session below:
>> clear
>> load x552a.dat
>> x=552a;
*Begin by testing the auto.m function auto(x,m), where x is a data vector and m is the number of lags over which you want to compute the lag correlation. Here we ask to calculate the lag correlation of the first row of x out to 10 lags.
>> auto(x(:,1),10)
ans =
Columns 1 through 7
1.0000 0.6219 0.4312 0.3093 0.2238 0.2038 0.1918
Columns 8 through 11
0.1159 0.0966 0.1042 0.1176
*Next set up a loop to calculate the temporal autocorrelation function to 10 lags for all 32 columns of x, which are the spatial grid points, if you like.
>> for n = 1:32
cor(n,:)=auto(x(:,n),10);
end
*Next plot the transpose of the cor matrix. This gives you a plot of the temporal autocorrelation functions of each of the 32 spatial grid points. Notice that they are all a little different because of sampling noise.
>> plot(cor')
*Next we can set up a loop to calculate the average autocorrelation function for all 32 spatial grid points. First set the average array to zero.
>> for k=1:10
corm(k)=0. ;
end
*Then add the autocorrelation functions all 32 grid points together.
>> for k=1:10
for j = 1:32
corm(k)=corm(k)+cor(j,k);
end
end
*And normalize
>> corm=corm/32.;
*Then we can plot up the average and see a nice exponential curve, indicating red noise.
>> plot (corm)
*or you can print out the values.
>> corm
corm =
Columns 1 through 7
1.0000 0.6726 0.5092 0.4086 0.3387 0.2878 0.2545
Columns 8 through 10
0.2186 0.1903 0.1712
*The autocorrelation at one time step is on average equal to 0.67. You can use this number in the North formula to test whether the eigenvalues are distinct. You need to do the same analysis for variable b.