annotate toolboxes/FullBNT-1.0.7/KPMstats/partial_corr_coef.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function [r, c] = partial_corr_coef(S, i, j, Y)
Daniel@0 2 % PARTIAL_CORR_COEF Compute a partial correlation coefficient
Daniel@0 3 % [r, c] = partial_corr_coef(S, i, j, Y)
Daniel@0 4 %
Daniel@0 5 % S is the covariance (or correlation) matrix for X, Y, Z
Daniel@0 6 % where X=[i j], Y is conditioned on, and Z is marginalized out.
Daniel@0 7 % Let S2 = Cov[X | Y] be the partial covariance matrix.
Daniel@0 8 % Then c = S2(i,j) and r = c / sqrt( S2(i,i) * S2(j,j) )
Daniel@0 9 %
Daniel@0 10
Daniel@0 11 % Example: Anderson (1984) p129
Daniel@0 12 % S = [1.0 0.8 -0.4;
Daniel@0 13 % 0.8 1.0 -0.56;
Daniel@0 14 % -0.4 -0.56 1.0];
Daniel@0 15 % r(1,3 | 2) = 0.0966
Daniel@0 16 %
Daniel@0 17 % Example: Van de Geer (1971) p111
Daniel@0 18 %S = [1 0.453 0.322;
Daniel@0 19 % 0.453 1.0 0.596;
Daniel@0 20 % 0.322 0.596 1];
Daniel@0 21 % r(2,3 | 1) = 0.533
Daniel@0 22
Daniel@0 23 X = [i j];
Daniel@0 24 i2 = 1; % find_equiv_posns(i, X);
Daniel@0 25 j2 = 2; % find_equiv_posns(j, X);
Daniel@0 26 S2 = S(X,X) - S(X,Y)*inv(S(Y,Y))*S(Y,X);
Daniel@0 27 c = S2(i2,j2);
Daniel@0 28 r = c / sqrt(S2(i2,i2) * S2(j2,j2));