Clear Filters
Clear Filters

How to correlate vector and matrix time series?

7 views (last 30 days)
Hello everyone,
I have two data time-series for five years, one is monthly sea surface temperature (SST) index (1X60) and another one is monthly rainfall in matrix form (180X360X60).
Now I want to correlate this monthly SST index with rainfall of every grid. How can I calculate correlation coefficient between these two data? Outputs should be in matrix form, Correlation Coefficient (180X360) and P-value (180X360).
Thanks.

Accepted Answer

George Abrahams
George Abrahams on 12 Jan 2024
If you're asking about code only, i.e., not statistical methdology, it would look this:
% Example data. Using a smaller grid size for demonstration.
seaSurfaceTemp = rand( 1, 60 );
rainfall = rand( 3, 5, 60 );
gridSize = size( rainfall, 1:2 );
% Convert rainfall so that the columns are the monthly values for each grid.
rainfall = reshape( rainfall(:), [], length( seaSurfaceTemp ) )';
% For each grid, calculate the Pearson's correlation and p-value between
% seaSurfaceTemp and rainfall.
[ rho, pval ] = corr( seaSurfaceTemp', rainfall );
% Reshape rho and pval back into the grid format.
rho = reshape( rho, gridSize )
rho = 3×5
0.0519 -0.0159 0.0652 0.2697 -0.0361 0.1220 -0.0329 0.0511 0.2074 0.0842 0.0467 0.0823 0.1660 -0.0118 0.0229
pval = reshape( pval, gridSize )
pval = 3×5
0.6939 0.9041 0.6207 0.0372 0.7843 0.3531 0.8031 0.6981 0.1118 0.5223 0.7230 0.5319 0.2048 0.9285 0.8624
See corr for statistical details and more options, e.g., correlation type.
  4 Comments
Vedanta
Vedanta on 24 Jan 2024
Edited: Vedanta on 24 Jan 2024
@George Abrahams if the pvalue is less than 0.05 it shows 95% significance level. https://ch.mathworks.com/help/stats/corr.html
George Abrahams
George Abrahams on 24 Jan 2024
Almost.
  • The null hypothesis () is that no correlation exists between the two variables, rainfall and sea surface temperature.
  • The p-value (p) is the likelihood of seeing a correlation between the two variables purely by random chance, i.e., when no correlation truly exists. Consider if you were to roll a dice 5 times and get the same number each time, it seems likely that the dice is weighted, but it may also just be due to chance. Note that for the Pearson correlation coefficient, corr calculates the p-value with a Student's t-test.
  • The significance level (α) is set by you, typically to 5% (0.05) - not 95% as you stated. If , you are satisfied that the correlation is real, you reject the null hypothesis and the correlation is deemed statistically-signficant, although you can never be 100% certain. If , there is insufficient evidence to reject the null hypothesis, and you cannot show a statistically-significant correlation.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!