Test alternative hypotheses for positive, negative, and nonzero correlation between the columns of two matrices. Compare values of the correlation coefficient and p-value in each case.
Generate sample data.
Introduce positive correlation between column one of the matrix X
and column four of the matrix Y
.
Introduce negative correlation between column two of X
and column two of Y
.
Test the alternative hypothesis that the correlation is greater than zero.
rho = 4×4
0.0627 -0.1438 -0.0035 0.7060
-0.1197 -0.8600 -0.0440 0.1984
-0.1119 0.2210 -0.3433 0.1070
-0.3526 -0.2224 0.1023 0.0374
pval = 4×4
0.3327 0.8405 0.5097 0.0000
0.7962 1.0000 0.6192 0.0836
0.7803 0.0615 0.9927 0.2298
0.9940 0.9397 0.2398 0.3982
As expected, the correlation coefficient between column one of X
and column four of Y
, rho(1,4)
, has the highest positive value, representing a high positive correlation between the two columns. The corresponding p-value, pval(1,4)
, is zero to the four digits shown, which is lower than the significance level of 0.05
. These results indicate rejection of the null hypothesis that no correlation exists between the two columns and lead to the conclusion that the correlation is greater than zero.
Test the alternative hypothesis that the correlation is less than zero.
rho = 4×4
0.0627 -0.1438 -0.0035 0.7060
-0.1197 -0.8600 -0.0440 0.1984
-0.1119 0.2210 -0.3433 0.1070
-0.3526 -0.2224 0.1023 0.0374
pval = 4×4
0.6673 0.1595 0.4903 1.0000
0.2038 0.0000 0.3808 0.9164
0.2197 0.9385 0.0073 0.7702
0.0060 0.0603 0.7602 0.6018
As expected, the correlation coefficient between column two of X
and column two of Y
, rho(2,2)
, has the negative number with the largest absolute value (-0.86
), representing a high negative correlation between the two columns. The corresponding p-value, pval(2,2)
, is zero to the four digits shown, which is lower than the significance level of 0.05
. Again, these results indicate rejection of the null hypothesis and lead to the conclusion that the correlation is less than zero.
Test the alternative hypothesis that the correlation is not zero.
rho = 4×4
0.0627 -0.1438 -0.0035 0.7060
-0.1197 -0.8600 -0.0440 0.1984
-0.1119 0.2210 -0.3433 0.1070
-0.3526 -0.2224 0.1023 0.0374
pval = 4×4
0.6654 0.3190 0.9807 0.0000
0.4075 0.0000 0.7615 0.1673
0.4393 0.1231 0.0147 0.4595
0.0120 0.1206 0.4797 0.7964
The p-values, pval(1,4)
and pval(2,2)
, are both zero to the four digits shown. Because the p-values are lower than the significance level of 0.05
, the correlation coefficients rho(1,4)
and rho(2,2)
are significantly different from zero. Therefore, the null hypothesis is rejected; the correlation is not zero.