How to correlate vector and matrix time series?

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

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

Thanks, this code works. For p value by default confidance interval is 95% so is it possible to change the confidance interval at 90% .
And also with the same data I need to perform the lag correlation at 0, 1, 2, 3 months. how can i do this?
Hi again. It's important to understand that p-values and confidence intervals are not the same thing. corr provides does not give confidence intervals, so I'm not sure where you're seeing this "default confidence interval".
For the Pearson correlation coefficient, corrcoeff also returns RL and RU, the lower and upper bounds of the confidence interval, according to signficance level set by the Alpha name-value argument.
As you have opened a new question for the lag correlation, please accept my answer if it satisfies your original question and continue the discussion there.
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
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!