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
BLASSO:
https://github.com/donaldRwilliams/bnets/blob/master/exec/lasso.stan
My solution was to apply this function to the individual estimates by:
-
fitting model
https://github.com/donaldRwilliams/bnets/blob/master/R/blasso_net.R -
extracting BETA
https://github.com/donaldRwilliams/bnets/blob/master/R/extract_BETA.R
(note: called from 3) -
apply function to individual BETA posterior estimates
https://github.com/donaldRwilliams/bnets/blob/master/R/partial_corr.R