LASSO regularized partial correlations

I am having a difficult time estimating partial correlations in the generated quantities blocks. The model is estimating regularized partial correlation networks, in which I am using the node-wise regression approach. Basically, assuming x1, x2, …x10 and standardized data, I fit 10 penalized regression models: x1 ~ x2…x10; x2 ~ x1 + x3…x10…so on and so on. I would then like to apply this function to the estimates.

function (Beta, verbose = FALSE) 
    Dummy = Beta * t(Beta)
    if (verbose == TRUE) {
        cat("\nNumber of pairwise regression coefficients with conflicting signs:", 
            (sum((Dummy) < 0))/2, "\n")
        cat("Number of partial correlation coefficients greater than 1 in absolute value:", 
            (sum((Dummy) > 1))/2, "\n\n")
    Dummy[Dummy < 0] = 0
    Dummy[Dummy > 1] = 1
    P = sign(Beta) * sqrt(Dummy)
    diag (P)  = rep(1, ncol (P) )

Importantly, this 10 x 10 matrix would need a zero when that variable was the response. For example, x2 ~ would have a zero in the second row and second column, and the x1_BETA would be in the second row and first column, x3_BETA would be in the second row and third column etc.

I am developing a package using Stan, so am including the relevant links here:


My solution was to apply this function to the individual estimates by:

  1. fitting model

  2. extracting BETA
    (note: called from 3)

  3. apply function to individual BETA posterior estimates

I couldn’t see a question in this post, but it seemed to start like a question. Is there something we could help with?

Thank you for the reply. My question was about how to use the model estimates in the generated quantities to estimate partial correlations. Suppose we have a matrix X that is n * p. The models I am fitting are X[,-i] ~ X[,i] in a loop, so we get p regression models. The function I provided in the original comment is then used to compute the partial correlations, where there is a matrix of regression estimates that is p * p.

I was wondering if there was a way to somehow use that function in the generated quantities block to estimate the partial correlations.

I do have a solution to do this outside of Stan that seems to work fine, but requires some extensive code.

Thanks in advance,

There’s nothing built-in to do that, so the extensive code would have to be coded up inside Stan. That’s challenging as we don’t have good debugging facilities for large functions. My advice (if you’re in R) would be to use the expose functions functionality to test functions independently.

We don’t even have a correlation or covariance function built in, but we should. I thought someone picked up the issue to do that, but I haven’t seen a pull request.