# LASSO regularized partial correlations

Hi:
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) )
return(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:

https://github.com/donaldRwilliams/bnets

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

1. extracting BETA
https://github.com/donaldRwilliams/bnets/blob/master/R/extract_BETA.R
(note: called from 3)

2. apply function to individual BETA posterior estimates
https://github.com/donaldRwilliams/bnets/blob/master/R/partial_corr.R

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

Hi:
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.