Description Usage Arguments Details Value See Also Examples

Calculate the kernel partial correlation (KPC) coefficient with directed K-nearest neighbor (K-NN) graph or minimum spanning tree (MST).

1 2 3 4 5 6 7 8 |

`Y` |
a matrix (n by dy) |

`X` |
a matrix (n by dx) or |

`Z` |
a matrix (n by dz) |

`k` |
a function |

`Knn` |
number of nearest neighbor to use; or "MST" |

`trans_inv` |
TRUE or FALSE. Is |

The kernel partial correlation squared (KPC) measures the conditional dependence
between *Y* and *Z* given *X*, based on an i.i.d. sample of *(Y, Z, X)*.
It converges to the population quantity (depending on the kernel) which is between 0 and 1.
A small value indicates low conditional dependence between *Y* and *Z* given *X*, and
a large value indicates stronger conditional dependence.
If `X == NULL`

, it returns the `KMAc(Y,Z,k,Knn)`

, which measures the unconditional dependence between *Y* and *Z*.
Euclidean distance is used for computing the K-NN graph and the MST.

The algorithm returns a real number which is the estimated KPC.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ```
library(kernlab)
n = 2000
x = rnorm(n)
z = rnorm(n)
y = x + z + rnorm(n,1,1)
KPCgraph(y,x,z,vanilladot(),Knn=1,trans_inv=FALSE)
n = 1000
x = runif(n)
z = runif(n)
y = (x + z) %% 1
KPCgraph(y,x,z,rbfdot(5),Knn="MST",trans_inv=TRUE)
discrete_ker = function(y1,y2) {
if (y1 == y2) return(1)
return(0)
}
class(discrete_ker) <- "kernel"
set.seed(1)
n = 2000
x = rnorm(n)
z = rnorm(n)
y = rep(0,n)
for (i in 1:n) y[i] = sample(c(1,0),1,prob = c(exp(-z[i]^2/2),1-exp(-z[i]^2/2)))
KPCgraph(y,x,z,discrete_ker,1)
##0.330413
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.