# Cholesky Factor and Kendall's Tau

Hello!

I am working on a Gaussian copula where the main parameter of interest is the Cholesky factor (or the related correlation matrix).

In the generated quantities block I generate the full correlation matrix:

corr_matrix[dim] pearson_cor_mat = multiply_lower_self_transpose(L);


The model is great, the above function does what I want, etc. I was curious if anyone knew of a way to extend the Cholesky factor to non-parametric cases. In other words, the above is a Pearson product moment correlation. I am looking for Kendall’s \tau (or Spearman’s \rho). I know there are nice properties where one can take Pearsons and estimate the other (e.g., Kendall’s = (2 / \pi)*arcsin(\rho)), but curious if there was a clean way to model this in Stan using the Cholesky factor?

Thank you!

Update:

I found this on git, but was not sure if there were a more efficient means to complete?

data {
int N;
int x_rank[N];
int y_rank[N];
}
parameters {
ordered[N] x;
ordered[N] y;
real<lower=-1, upper=1> rho;
}
transformed parameters {
real x2[N];
real y2[N];
matrix[2, 2] T;

for(i in 1:N) {
x2[i] = x[x_rank[i]];
y2[i] = y[y_rank[i]];
}

T[1, 1] = 1;
T[1, 2] = rho;
T[2, 1] = rho;
T[2, 2] = 1;
}
model {
vector[2] m;

for(i in 1:N) {
m[1] = x2[i];
m[2] = y2[i];
target += multi_normal_lpdf(m | [0, 0], T);
}
}
generated quantities {
real tau;
tau = 2 / pi() * asin(rho);
}