public static synchronized double partialCorrelation(TetradMatrix submatrix){
  try {
    TetradMatrix inverse=submatrix.inverse();
    double a=-1.0 * inverse.get(0,1);
    double v0=inverse.get(0,0);
    double v1=inverse.get(1,1);
    double b=Math.sqrt(v0 * v1);
    return a / b;
  }
 catch (  Exception e) {
    e.printStackTrace();
    return Double.NaN;
  }
}

public static synchronized double partialCorrelation ( TetradMatrix submatrix ) { try { TetradMatrix inverse = submatrix . inverse ( ) ; double a = - 1.0 * inverse . get ( 0 , 1 ) ; double v0 = inverse . get ( 0 , 0 ) ; double v1 = inverse . get ( 1 , 1 ) ; double b = Math . sqrt ( v0 * v1 ) ; return a / b ; } catch ( Exception e ) { e . printStackTrace ( ) ; return Double . NaN ; } }
assumes that the given covariance matrix was extracted in such a way that the order of the variables ( in either direction ) is x , y , z1 , . . . , zn , where the partial correlation one wants is correlation ( x , y | z1 , . . . , zn ) . this may be extracted using datautils . submatrix ( ) .
