Spatial Correlation between two variables

120 views (last 30 days)
ANKUR KUMAR on 28 Sep 2017
Commented: Deepthi B on 3 Aug 2021
How can I find the spatial correlation between two variables. For example: I have Latitude (having length 175) and longitude (having length 200). AOD having size 175*200 & AE having size 175*200. I want to find the spatial correlation between these two variables, AOD and AE.
ANKUR KUMAR on 14 Jan 2018
Here you can get timesaving toolbox in which spatialcorr3 is there. You can use this function to get the spatial correlation of 2 data sets.

ANKUR KUMAR on 2 Dec 2017
For simplicity, I am taking A and B for which we want to find spatial correlation. lat have the dimension 240 and lon have the dimension 120.
Note: This method is applicable only if the A and B are in timesteps. For eg. dimesion of A and B are 120*240*365 . 365 is the timesteps.
A=rand(120,240,365);
B=rand(120,240,365);
for i=1:120
for j=1:240
C(i,j)=corr2(squeeze(A(i,j,:)),squeeze(B(i,j,:)));
end
end
If your data set contains some nan values, then you have to remove those nans for finding correlation, otherwise you will get all nan values If there is nan values, then use this
for i=1:120
for j=1:240
C(i,j)=nancorr2(A(i,j,:),B(i,j,:));
end
end
Below is function for nancorr2. Is you are using 2016b or later, then you can write function within a script. Otherwise you have to save it in another file.
function A=nancorr2(U,V)
id1=find(isnan(U));
id2=find(isnan(U));
id=union(id1,id2);
U(id)=[];
V(id)=[];
A=corr2(U,V);
end
Deepthi B on 3 Aug 2021
@ANKUR KUMAR Sir, the code that you have given for calculating the spatial coorelation is calculating the correlation between the data available at a particular grid point ( 20.5 75 for example ) for the entire period (365 days). Is this spatial correlation? then we for this example , we will have (240*120) correlation values. Then how wil get reduced to one value for substituting in some equations?

ANKUR KUMAR on 14 Jan 2018
Here you can get timesaving toolbox in which spatialcorr3 is there. You can use this function to get the spatial correlation of 2 data sets.