Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Compute the first order correlation matrix from an original correlation matrix
ResourceFunction["FirstOrderCorrelation"][m] computes the first order correlation matrix of a matrix m. |
Compute the first order correlation of a rational 3×3 matrix:
In[1]:= | ![]() |
Out[1]= | ![]() |
Compute the first order correlation of a symbolic symmetric 2×2 matrix:
In[2]:= | ![]() |
Out[2]= | ![]() |
FirstOrderCorrelation works on large matrices:
In[3]:= | ![]() |
Out[3]= | ![]() |
Unless the "ConditionsCheck" option is set to True, FirstOrderCorrelation will evaluate and provide no warning even if the matrix is not symmetric:
In[4]:= | ![]() |
Out[4]= | ![]() |
Out[4]= | ![]() |
Setting "ConditionsCheck" to True also issues a warning if the matrix is not unambiguously positive definite and if it is not unambiguously positive semi-definite:
Out[4]= | ![]() |
Find the value of an element in a 3×3 zero-order correlation matrix that will set to 0 the corresponding element in the first order correlation matrix:
In[5]:= | ![]() |
Out[5]= | ![]() |
Find the element in a 4×4 zero-order correlation matrix that will set to 0 the corresponding element in the first order correlation matrix:
In[6]:= | ![]() |
Out[6]= | ![]() |
The first order correlation matrix of the first order correlation matrix is the same as the original matrix:
In[7]:= | ![]() |
Out[7]= | ![]() |
The function will fail and throw a message if the matrix is singular:
Out[7]= | ![]() |
Compare the false positive rates and true positive rates among "minority" and "majority" populations when classifying a population where the first variable is correlated with the second, the first variable is correlated with the third, but, after the first variable is taken into account, the second variable is uncorrelated with the third.
Take a first order correlation matrix and compute the zero-order correlation matrix:
In[8]:= | ![]() |
Out[8]= | ![]() |
In[9]:= | ![]() |
Out[9]= | ![]() |
Use the zero-order correlation matrix as the covariance matrix of a multinormal copula and use that to produce 1000 instances of training data and 1000 instances of test data:
Classify uses AutoML to figure out how to best classify the data; ClassifierMeasurements uses the trained classifier and the test data to compute various performance statistics:
In[10]:= | ![]() |
Out[10]= | ![]() |
Select picks out minority members from the test data set; the same performance statistics are generated:
In[11]:= | ![]() |
Out[11]= | ![]() |
Select picks out majority members from the test data set; the same performance statistics are generated:
In[12]:= | ![]() |
Out[12]= | ![]() |
Although there is no intentional "discrimination," and while the accuracy of the classifier is roughly the same for both groups, the false positive rates and true positive rates are higher for the majority than the minority.
This work is licensed under a Creative Commons Attribution 4.0 International License