Example 2

This example computes partial correlations from a 9 variable correlation matrix originally given by Emmett (1949). The partial correlations between the remaining variables, after adjusting for variables 1, 3 and 9, are computed. Note in the output that the row and column labels are numbers, not variable numbers. The corresponding variable numbers would be 2, 4, 5, 6, 7 and 8, respectively.

import com.imsl.stat.PartialCovariances;
import com.imsl.math.PrintMatrix;

public class PartialCovariancesEx2 {

    static public void main(String arg[]) throws Exception {
        double sigma[][] = {
            {1.000, 0.523, 0.395, 0.471, 0.346, 0.426, 0.576, 0.434, 0.639},
            {0.523, 1.000, 0.479, 0.506, 0.418, 0.462, 0.547, 0.283, 0.645},
            {0.395, 0.479, 1.000, 0.355, 0.270, 0.254, 0.452, 0.219, 0.504},
            {0.471, 0.506, 0.355, 1.000, 0.691, 0.791, 0.443, 0.285, 0.505},
            {0.346, 0.418, 0.270, 0.691, 1.000, 0.679, 0.383, 0.149, 0.409},
            {0.426, 0.462, 0.254, 0.791, 0.679, 1.000, 0.372, 0.314, 0.472},
            {0.576, 0.547, 0.452, 0.443, 0.383, 0.372, 1.000, 0.385, 0.680},
            {0.434, 0.283, 0.219, 0.285, 0.149, 0.314, 0.385, 1.000, 0.470},
            {0.639, 0.645, 0.504, 0.505, 0.409, 0.472, 0.680, 0.470, 1.000}
        };

        int xIndices[] = {1, 0, 1, 0, 0, 0, 0, 0, 1};
        int df = 30;

        PartialCovariances pcov = new PartialCovariances(xIndices, sigma, df);

        double correl[][] = pcov.getPartialCorrelationMatrix();
        new PrintMatrix("Partial Correlations").print(correl);

        double pValues[][] = pcov.getPValues();
        new PrintMatrix("P-Values").print(pValues);
    }
}

Output

              Partial Correlations
     0       1      2       3      4      5     
0   1      0.224   0.194  0.211  0.125  -0.061  
1   0.224  1       0.605  0.72   0.092   0.025  
2   0.194  0.605   1      0.598  0.123  -0.077  
3   0.211  0.72    0.598  1      0.035   0.086  
4   0.125  0.092   0.123  0.035  1       0.062  
5  -0.061  0.025  -0.077  0.086  0.062   1      

                  P-Values
     0      1      2      3      4      5    
0  0      0.252  0.323  0.28   0.525  0.758  
1  0.252  0      0.001  0      0.642  0.9    
2  0.323  0.001  0      0.001  0.533  0.698  
3  0.28   0      0.001  0      0.86   0.665  
4  0.525  0.642  0.533  0.86   0      0.753  
5  0.758  0.9    0.698  0.665  0.753  0      

Link to Java source.