With scipy.stats.multiscale_graphcorr, we can test for independence on
high-dimensional and nonlinear data. Before we start, let us import some useful
packages:
Now, we can see the test statistic, p-value, and MGC map visualized below. The
optimal scale is shown on the map as a red “x”:
>>> stat,pvalue,mgc_dict=multiscale_graphcorr(x,y)>>> print("MGC test statistic: ",round(stat,1))MGC test statistic: 1.0>>> print("P-value: ",round(pvalue,1))P-value: 0.0>>> mgc_plot(x,y,"Linear",mgc_dict,only_mgc=True)
It is clear from here, that MGC is able to determine a relationship between the
input data matrices because the p-value is very low and the MGC test statistic
is relatively high. The MGC-map indicates a strongly linear relationship.
Intuitively, this is because having more neighbors will help in identifying a
linear relationship between x and y. The optimal scale in this
case is equivalent to the global scale, marked by a red spot on the map.
The same can be done for nonlinear data sets. The following x and
y arrays are derived from a nonlinear simulation:
Now, we can see the test statistic, p-value, and MGC map visualized below. The
optimal scale is shown on the map as a red “x”:
>>> stat,pvalue,mgc_dict=multiscale_graphcorr(x,y)>>> print("MGC test statistic: ",round(stat,1))MGC test statistic: 0.2 # random>>> print("P-value: ",round(pvalue,1))P-value: 0.0>>> mgc_plot(x,y,"Spiral",mgc_dict,only_mgc=True)
It is clear from here, that MGC is able to determine a relationship again
because the p-value is very low and the MGC test statistic is relatively high.
The MGC-map indicates a strongly nonlinear relationship. The optimal scale
in this case is equivalent to the local scale, marked by a red spot on the
map.