@@ -84,18 +84,44 @@ blavInspect <- function(blavobject, what, ...) {
8484 if (add.labels ) names(OUT ) <- labs
8585 OUT
8686 } else if (what %in% c(" mcmc" , " draws" , " samples" , " hpd" )){
87- # # add defined parameters to labels
87+ # # add defined parameters to labels or, for stan, compute defined parameters
8888 pt <- blavobject @ ParTable
89- pt $ free [pt $ op == " :=" ] <- max(pt $ free , na.rm = TRUE ) + 1 : sum(pt $ op == " :=" )
90- labs <- lav_partable_labels(pt , type = " free" )
91- draws <- make_mcmc(blavobject @ external $ mcmcout )
92- draws <- lapply(draws , function (x ) mcmc(x [, idx , drop = FALSE ]))
93- draws <- mcmc.list(draws )
94- if (add.labels ) {
89+ if (! (blavobject @ Options $ target %in% c(" stan" , " cmdstan" , " vb" ))) {
90+ pt $ free [pt $ op == " :=" ] <- max(pt $ free , na.rm = TRUE ) + 1 : sum(pt $ op == " :=" )
91+ labs <- lav_partable_labels(pt , type = " free" )
92+ draws <- make_mcmc(blavobject @ external $ mcmcout )
93+ draws <- lapply(draws , function (x ) mcmc(x [, idx , drop = FALSE ]))
94+ draws <- mcmc.list(draws )
95+ if (add.labels ) {
96+ for (i in 1 : length(draws )) {
97+ colnames(draws [[i ]]) <- labs
98+ }
99+ }
100+ } else {
101+ labs <- lav_partable_labels(pt , type = " free" )
102+ draws <- make_mcmc(blavobject @ external $ mcmcout )
103+ draws <- lapply(draws , function (x ) mcmc(x [, idx , drop = FALSE ]))
104+ draws <- mcmc.list(draws )
105+ labs <- lav_partable_labels(pt , type = " free" )
106+ if (add.labels ) {
95107 for (i in 1 : length(draws )) {
96- colnames(draws [[i ]]) <- labs
108+ colnames(draws [[i ]]) <- labs
97109 }
110+ }
111+
112+ ndef <- sum(pt $ op == " :=" )
113+ if (ndef > 0 ) {
114+ defpt <- which(pt $ op == " :=" )
115+ for (j in 1 : length(draws )) {
116+ for (i in defpt ) {
117+ thisop <- pt $ rhs [i ]
118+ draws [[j ]] <- cbind(draws [[j ]], eval(parse(text = thisop ), envir = as.data.frame(draws [[j ]])))
119+ colnames(draws [[j ]])[ncol(draws [[j ]])] <- pt $ lhs [i ]
120+ }
121+ }
122+ }
98123 }
124+
99125 if (what == " hpd" ){
100126 pct <- .95
101127 if (" level" %in% dotNames ) pct <- dotdotdot $ level
0 commit comments