Global Index (all files) (short | long) | Local Index (files in subdir) (short | long)
[out, ccoef] = regress_eof(temp, pcs, lags);
[out, ccoef] = regress_eof(dat, pcs, lags);
Here 'dat' refers to the variable to regress onto 'pcs'.
The variable 'lags' refers to a vector of leads/lags, where
-1 refers to 'dat' leading 'pcs', and +1 refers to 'pcs'
leading 'dat'.
| This function calls | |
|---|---|
function [out, ccoef] = regress_eof(temp, pcs, lags);
if nargin < 2;
error('There must be at least 2 inputs, ''dat'' and ''pcs'' ');
elseif nargin < 3;
lags = 0;
end
sz_temp = size(temp);
ndim = length(sz_temp);
temp = reshape(temp, sz_temp(1), prod(sz_temp(2:ndim)));
clim = mean(temp);
kp = find(~isnan(clim));
temp = temp(:,kp);
[temp, tem] = remove_mean(temp);
stdtemp = std(temp);
nlag = length(lags);
num = 1;
if (size(pcs,1)==1); pcs=pcs'; end;
timeseries = (pcs(:,num) - mean(pcs(:,num)))./std(pcs(:,num));
for j = 1:nlag;
if lags(j) > 0;
tm = timeseries(1:(sz_temp(1)-lags(j)));
tem = temp((1+lags(j)):sz_temp(1),:);
elseif lags(j) < 0;
tm = timeseries((1-lags(j)):sz_temp(1));
tem = temp(1:(sz_temp(1)+lags(j)),:);
elseif lags(j) == 0;
tm = timeseries;
tem = temp;
end
out(j, :) = tm' * tem ./ (sz_temp(1)-abs(lags(j))-1);
ccoef(j,:) = out(j,:) ./ stdtemp;
end;
tem = NaN*ones(nlag, prod(sz_temp(2:ndim)));
tem(:,kp) = out;
out = reshape(tem, [nlag sz_temp(2:ndim)]);
tem = NaN*ones(nlag, prod(sz_temp(2:ndim)));
tem(:,kp) = ccoef;
ccoef = reshape(tem, [nlag sz_temp(2:ndim)]);