no method found for function 'summary' and signature blavFitIndices

182 views
Skip to first unread message

Gidon Frischkorn-Bartsch

unread,
Dec 15, 2020, 7:47:46 AM12/15/20
to blavaan

Hi everyone,
I have issues getting a proper summary for my models fitted with blavaan. I do not get posterior estimates and the top of my summary reads:

lavaan 0.6-7 ended normally after 5000 iterations

I already saw that sometimes loading "lavaan" after "blavaan" may cause a conflict in the namespaces. Therefore, I only load "blavaan" without additionally loading "lavaan" before. However, I still don't get proper blavaan summaries. This also leads to the blavFitIndices function not working, because it relies on the adequate summary for blavaan objects.

This is my session Info:

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] blavaan_0.3-12     RcppParallel_5.0.2 Rcpp_1.0.5         lavaan_0.6-7       forcats_0.5.0      stringr_1.4.0      dplyr_1.0.2       
 [8] purrr_0.3.4        readr_1.4.0        tidyr_1.1.2        tibble_3.0.4       ggplot2_3.3.2      tidyverse_1.3.0   

loaded via a namespace (and not attached):
  [1] readxl_1.3.1         backports_1.2.1      plyr_1.8.6           igraph_1.2.6         splines_4.0.3        svUnit_1.0.3        
  [7] crosstalk_1.1.0.1    listenv_0.8.0        TH.data_1.0-10       rstantools_2.1.1     inline_0.3.17        digest_0.6.27       
 [13] htmltools_0.5.0      rsconnect_0.8.16     fansi_0.4.1          checkmate_2.0.0      magrittr_2.0.1       globals_0.14.0      
 [19] brms_2.14.4          modelr_0.1.8         matrixStats_0.57.0   MCMCpack_1.4-9       xts_0.12.1           sandwich_3.0-0      
 [25] prettyunits_1.1.1    colorspace_2.0-0     rvest_0.3.6          ggdist_2.3.0         haven_2.3.1          callr_3.5.1         
 [31] crayon_1.3.4         jsonlite_1.7.2       lme4_1.1-26          survival_3.2-7       zoo_1.8-8            glue_1.4.2          
 [37] gtable_0.3.0         emmeans_1.5.3        MatrixModels_0.4-1   V8_3.4.0             distributional_0.2.1 pkgbuild_1.1.0      
 [43] rstan_2.21.2         future.apply_1.6.0   abind_1.4-5          SparseM_1.78         scales_1.1.1         mvtnorm_1.1-1       
 [49] DBI_1.1.0            miniUI_0.1.1.1       xtable_1.8-4         performance_0.6.1    tmvnsim_1.0-2        stats4_4.0.3        
 [55] StanHeaders_2.21.0-6 DT_0.16              timeSeries_3062.100  httr_1.4.2           htmlwidgets_1.5.3    threejs_0.3.3       
 [61] arrayhelpers_1.1-0   runjags_2.0.4-6      ellipsis_0.3.1       pkgconfig_2.0.3      loo_2.4.1            tidybayes_2.3.1     
 [67] farver_2.0.3         dbplyr_2.0.0         tidyselect_1.1.0     rlang_0.4.9          reshape2_1.4.4       later_1.1.0.1       
 [73] cellranger_1.1.0     munsell_0.5.0        tools_4.0.3          cli_2.2.0            generics_0.1.0       broom_0.7.2         
 [79] ggridges_0.5.2       fastmap_1.0.1        yaml_2.2.1           mcmc_0.9-7           fs_1.5.0             processx_3.4.5      
 [85] future_1.21.0        nlme_3.1-151         mime_0.9             quantreg_5.75        projpred_2.0.2       xml2_1.3.2          
 [91] nonnest2_0.5-5       compiler_4.0.3       bayesplot_1.7.2      shinythemes_1.1.2    rstudioapi_0.13      curl_4.3            
 [97] gamm4_0.2-6          e1071_1.7-4          reprex_0.3.0         statmod_1.4.35       pbivnorm_0.6.0       stringi_1.5.3       
[103] ps_1.5.0             Brobdingnag_1.2-6    lattice_0.20-41      Matrix_1.2-18        psych_2.0.9          nloptr_1.2.2.2      
[109] markdown_1.1         shinyjs_2.0.0        vctrs_0.3.5          CompQuadForm_1.4.3   pillar_1.4.7         lifecycle_0.2.0     
[115] bridgesampling_1.0-0 estimability_1.3     insight_0.11.1       conquer_1.0.2        httpuv_1.5.4         R6_2.5.0            
[121] promises_1.1.1       gridExtra_2.3        parallelly_1.22.0    codetools_0.2-18     boot_1.3-25          colourpicker_1.1.0  
[127] MASS_7.3-53          gtools_3.8.2         assertthat_0.2.1     withr_2.3.0          shinystan_2.5.0      mnormt_2.0.2        
[133] multcomp_1.4-15      hms_0.5.3            mgcv_1.8-33          bayestestR_0.8.0     parallel_4.0.3       timeDate_3043.102   
[139] grid_4.0.3           class_7.3-17         coda_0.19-4          minqa_1.2.4          lubridate_1.7.9.2    shiny_1.5.0         
[145] base64enc_0.1-3      dygraphs_1.1.1.6

Hope someone can help me.
Thanks in advance for your efforts.
Best, Gidon

Mauricio Garnier-Villarreal

unread,
Dec 15, 2020, 9:00:37 AM12/15/20
to blavaan
Gidon

When this has happend, has been fixed when I close Rstudio and start fresh.
If this still doesnt work, can you share your code that continuosly gives the problem, when I start from a fresh R session this minimal call works

######
library(blavaan)

HS.model <- ' visual  =~ x1 + x2 + x3
              textual =~ x4 + x5 + x6
              speed   =~ x7 + x8 + x9 '

fitb <- bcfa(HS.model,
            data = HolzingerSwineford1939, std.lv=T)
summary(fitb)

Gidon Frischkorn-Bartsch

unread,
Dec 15, 2020, 10:14:47 AM12/15/20
to blavaan
Thanks for your suggestion. Unfortunately, closing and restarting RStudio fresh has not helped. Even just running the minimal example code you posted  in a fresh RStudio session did not give te correct blavaan summary.

I have now uninstalled blavaan and re-installed the development version of blavaan via GitHub. That seems to have done the trick.

David Allen

unread,
Jan 19, 2021, 6:54:43 PM1/19/21
to blavaan
I have been having the same issue, although when I attempt to install from source I receive the following error:
Error: Failed to install 'blavaan' from GitHub:
  'local_makevars' is not an exported object from 'namespace:withr'

I'm working around this by downloading a local copy of /R/blav_object_methods.R and loading it using source, as it seems that this file isn't being run when I load the library for some reason.

- David

David Allen

unread,
Jan 19, 2021, 7:03:47 PM1/19/21
to blavaan
Looks like while that gives me the Rhat values and priors (which is most of what I was after), the PI limits aren't included. I can get them with parameterEstimates() without any trouble though, so it looks like something might be breaking after line 208 of blav_object_methods.R?

I'm not familiar enough with the codebase to be able to make much more progress beyond just hacking away until I find something that works for me though, I'm sorry.

Mauricio Garnier-Villarreal

unread,
Jan 19, 2021, 7:52:14 PM1/19/21
to blavaan
David

can you share your sessioninfo()?

I would recommend to unstaill blavaan, and re-install it again from CRAN. Doing this with a clean new R session.

Also, can you run Stan models without problems? for example run this. As I have seen more installation problems with Stan, and as iblavaan uses it as default that might be the issue

library(rstan)
scode <- "
parameters {
  real y[2];
}
model {
  y[1] ~ normal(0, 1);
  y[2] ~ double_exponential(0, 2);
}
"
fit1 <- stan(model_code = scode, iter = 1000, verbose = FALSE)
print(fit1)

hopefully we can find a way to make it work

David Allen

unread,
Jan 19, 2021, 11:07:35 PM1/19/21
to blavaan
Okay, I restarted R and reinstalled everything (basically cleared everything out and told renv to bring it all back, then manually downgrading withr because renv is just too efficient some days).

Getting the lavaan-style output. Results plot fine though.

> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252    LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
 [1] lubridate_1.7.9.2    readxl_1.3.1         REDCapR_0.11.0       psych_2.0.12         coda_0.19-4          blavaan_0.3-13       RcppParallel_5.0.2  
 [8] Rcpp_1.0.6           lavaan_0.6-7         rstan_2.21.2         StanHeaders_2.21.0-7 forcats_0.5.0        stringr_1.4.0        dplyr_1.0.3         
[15] purrr_0.3.4          readr_1.4.0          tidyr_1.1.2          tibble_3.0.5         ggplot2_3.3.3        tidyverse_1.3.0     

loaded via a namespace (and not attached):
 [1] nlme_3.1-149       mcmc_0.9-7         fs_1.5.0           matrixStats_0.57.0 httr_1.4.2         tools_4.0.3        backports_1.2.1    R6_2.5.0          
 [9] DBI_1.1.1          colorspace_2.0-0   withr_2.2.0        tidyselect_1.1.0   gridExtra_2.3      prettyunits_1.1.1  mnormt_2.0.2       processx_3.4.5    
[17] nonnest2_0.5-5     curl_4.3           compiler_4.0.3     rvest_0.3.6        cli_2.2.0          quantreg_5.82      SparseM_1.78       xml2_1.3.2        
[25] sandwich_3.0-0     labeling_0.4.2     checkmate_2.0.0    scales_1.1.1       mvtnorm_1.1-1      ggridges_0.5.3     callr_3.5.1        digest_0.6.27     
[33] pbivnorm_0.6.0     MCMCpack_1.4-9     pkgconfig_2.0.3    parallelly_1.23.0  dbplyr_2.0.0       rlang_0.4.10       rstudioapi_0.13    farver_2.0.3      
[41] generics_0.1.0     zoo_1.8-8          jsonlite_1.7.2     inline_0.3.17      magrittr_2.0.1     loo_2.4.1          bayesplot_1.8.0    Matrix_1.2-18     
[49] munsell_0.5.0      fansi_0.4.2        lifecycle_0.2.0    stringi_1.5.3      CompQuadForm_1.4.3 MASS_7.3-53        pkgbuild_1.2.0     plyr_1.8.6        
[57] grid_4.0.3         parallel_4.0.3     listenv_0.8.0      crayon_1.3.4       lattice_0.20-41    haven_2.3.1        hms_1.0.0          tmvnsim_1.0-2     
[65] knitr_1.30         ps_1.5.0           pillar_1.4.7       reshape2_1.4.4     future.apply_1.7.0 codetools_0.2-16   stats4_4.0.3       rstantools_2.1.1  
[73] reprex_0.3.0       glue_1.4.2         V8_3.4.0           renv_0.12.5        modelr_0.1.8       vctrs_0.3.6        MatrixModels_0.4-1 cellranger_1.1.0  
[81] gtable_0.3.0       future_1.21.0      assertthat_0.2.1   xfun_0.20          broom_0.7.3        viridisLite_0.3.0  conquer_1.0.2      globals_0.14.0    
[89] ellipsis_0.3.1    
> library(rstan)
> scode <- "
+ parameters {
+   real y[2];
+ }
+ model {
+   y[1] ~ normal(0, 1);
+   y[2] ~ double_exponential(0, 2);
+ }
+ "
> fit1 <- stan(model_code = scode, iter = 1000, verbose = FALSE)
'C:/rtools40/usr/mingw_/bin/g++' not found
SAMPLING FOR MODEL '7c1c9409b5e3bcad671cc31b05ffc021' NOW (CHAIN 1).
...output removed...
> print(fit1)
Inference for Stan model: 7c1c9409b5e3bcad671cc31b05ffc021.
4 chains, each with iter=1000; warmup=500; thin=1; 
post-warmup draws per chain=500, total post-warmup draws=2000.

      mean se_mean   sd  2.5%   25%   50%   75% 97.5% n_eff Rhat
y[1]  0.01    0.03 1.01 -1.97 -0.65 -0.01  0.69  1.95  1032    1
y[2] -0.02    0.08 2.53 -5.21 -1.26 -0.01  1.32  5.26  1048    1
lp__ -1.42    0.04 1.15 -4.40 -1.94 -1.14 -0.57 -0.11   882    1

Samples were drawn using NUTS(diag_e) at Wed Jan 20 15:04:48 2021.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).

Mauricio Garnier-Villarreal

unread,
Jan 20, 2021, 5:56:39 AM1/20/21
to blavaan
David

It looks like you can run stan just fine.
I havent use withr or renv. And they are affecting the R enviroenment. Have you tried installing without using any of these?
For example, close R and orpen in a new session without anything else and only load the blavaan package and no other package? In case there is an odd interaction with some of these packages

Ed Merkle

unread,
Jan 20, 2021, 10:52:13 AM1/20/21
to David Allen, blavaan
I have recently heard of a number of issues with summary() methods in blavaan, and I just made some changes to the package that hopefully help. It would be helpful if anyone with these problems could install the github version of the package to see if it helps them:

remotes::install_github("ecmerkle/blavaan", INSTALL_opts = "--no-multiarch")

Ed



--
You received this message because you are subscribed to the Google Groups "blavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blavaan+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blavaan/a8cc9d6b-1d11-4b47-a426-ee79b0329652n%40googlegroups.com.

infiniteline

unread,
Jan 20, 2021, 6:29:49 PM1/20/21
to blavaan
I believe I was having some of the same issues. I installed the GitHub package (and the updated dependencies) and the summary seems better. It now says 'blavaan' and is producing the lower and upper pi values.

I am still having a problem with the fit indices and I'm not sure if it's related. When I call:

blavFitIndices(fit, baseline.model = fit0)

I'm now getting the error:

Error in apply(object@external$samplls, 2, function(x) 2 * (x[, 2] - x[,  : 
  dim(X) must have a positive length


Eric Andrews, MA, LPC
Ph.D. Student, Cognition and Neural Systems
Neuroscience of Emotion & Thought (NET) Lab
Department of Psychology, University of Arizona


Mauricio Garnier-Villarreal

unread,
Jan 21, 2021, 7:18:50 PM1/21/21
to blavaan
Eric

Can you share more information? Sessioninfo(), data structure etc, and you full syntax that produces the error

When I run examples of these functions they work for me

David Allen

unread,
Jan 22, 2021, 1:29:05 AM1/22/21
to blavaan
Things were working with the GitHub version installed, and then I changed the structure of the model (deleted two predictors) and now we're back to the lavaan version of the summary. I don't know whether those two things are related, but they certainly happened together.

I'm very intrigued as to what could be causing this.

- David

infiniteline

unread,
Jan 22, 2021, 3:05:04 AM1/22/21
to blavaan
On the positive side of things, blavaan still seems to be working and not exactly the issue that David is having.I can move my info into a new thread if these seem completely unrelated.

Session info is at the bottom. The model definitions and syntax are as follows (I replaced the variable names, but the structure is the same):

mySEMmodel <- '
# latent variable definitions
PWB =~ score01 + score02 + score03 + score04
# regressions
PWB ~ var1 + var2 + var3 + var4 + var5 + var6 + var7 + var8 + var9 + var10 + var11
# residual correlations
'

NullModelDesc <- '
# latent variable definitions
PWB =~ score01 + score02 + score03 + score04

# regressions
score01 ~ 1
score02 ~ 1
score03 ~ 1
score04 ~ 1
var1 ~ 1
var2 ~ 1
var3 ~ 1
var4 ~ 1
var5 ~ 1
var6 ~ 1
var7 ~ 1
var8 ~ 1
var9 ~ 1
var10 ~ 1
var11 ~ 1

# residual correlations
'

## fit null model to calculate CFI, TLI, and NFI
fit0 <- bsem(NullModelDesc, data = validationData, bcontrol=list(cores=4), test='none', n.chains=4, burnin=500, sample=1000)

fit1 <- bsem(mySEMmodel, data=validationData, bcontrol=list(cores=4), test='none', n.chains=4, burnin=500, sample=1000)

##################
## BOTH OF THE FOLLOWING ARE GIVING ME THE MENTIONED ERROR:
## Error in apply(object@external$samplls, 2, function(x) 2 * (x[, 2] - x[,  : 
## dim(X) must have a positive length
##################
ML <- blavFitIndices(fit1, baseline.model = fit0)
summary(ML)

PPMC <- blavFitIndices(fit1, baseline.model = fit0, pD = "waic", rescale = "PPMC")
summary(PPMC, central.tendency = c("mean","mode"), prob = .95)


======================================================
SESSION INFO
======================================================
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.4

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] gridExtra_2.3      ggplot2_3.3.3      brms_2.14.4        blavaan_0.3-15.713 RcppParallel_5.0.2 Rcpp_1.0.6        
[7] lavaan_0.6-7      

loaded via a namespace (and not attached):
  [1] minqa_1.2.4          colorspace_2.0-0     ellipsis_0.3.1       ggridges_0.5.3       rsconnect_0.8.16    
  [6] markdown_1.1         base64enc_0.1-3      rstudioapi_0.13      listenv_0.8.0        farver_2.0.3        
 [11] rstan_2.21.2         MatrixModels_0.4-1   DT_0.17              fansi_0.4.2          mvtnorm_1.1-1       
 [16] bridgesampling_1.0-0 codetools_0.2-16     splines_4.0.3        mnormt_2.0.2         shinythemes_1.1.2   
 [21] bayesplot_1.8.0      projpred_2.0.2       jsonlite_1.7.2       nloptr_1.2.2.2       mcmc_0.9-7          
 [26] shiny_1.5.0          compiler_4.0.3       backports_1.2.1      assertthat_0.2.1     Matrix_1.2-18       
 [31] fastmap_1.0.1        cli_2.2.0            later_1.1.0.1        htmltools_0.5.1      quantreg_5.82       
 [36] prettyunits_1.1.1    tools_4.0.3          igraph_1.2.6         coda_0.19-4          gtable_0.3.0        
 [41] glue_1.4.2           reshape2_1.4.4       dplyr_1.0.3          V8_3.4.0             vctrs_0.3.6         
 [46] nlme_3.1-149         conquer_1.0.2        crosstalk_1.1.1      stringr_1.4.0        globals_0.14.0      
 [51] ps_1.5.0             lme4_1.1-26          mime_0.9             miniUI_0.1.1.1       CompQuadForm_1.4.3  
 [56] lifecycle_0.2.0      gtools_3.8.2         statmod_1.4.35       future_1.21.0        MASS_7.3-53         
 [61] zoo_1.8-8            scales_1.1.1         colourpicker_1.1.0   promises_1.1.1       Brobdingnag_1.2-6   
 [66] parallel_4.0.3       sandwich_3.0-0       inline_0.3.17        SparseM_1.78         shinystan_2.5.0     
 [71] gamm4_0.2-6          curl_4.3             loo_2.4.1            StanHeaders_2.21.0-7 stringi_1.5.3       
 [76] dygraphs_1.1.1.6     boot_1.3-25          pkgbuild_1.2.0       rlang_0.4.10         pkgconfig_2.0.3     
 [81] matrixStats_0.57.0   lattice_0.20-41      purrr_0.3.4          rstantools_2.1.1     htmlwidgets_1.5.3   
 [86] labeling_0.4.2       processx_3.4.5       tidyselect_1.1.0     parallelly_1.23.0    plyr_1.8.6          
 [91] magrittr_2.0.1       R6_2.5.0             generics_0.1.0       pillar_1.4.7         withr_2.4.0         
 [96] mgcv_1.8-33          xts_0.12.1           abind_1.4-5          tibble_3.0.5         future.apply_1.7.0  
[101] crayon_1.3.4         nonnest2_0.5-5       tmvnsim_1.0-2        grid_4.0.3           pbivnorm_0.6.0      
[106] callr_3.5.1          threejs_0.3.3        digest_0.6.27        xtable_1.8-4         httpuv_1.5.5        
[111] MCMCpack_1.5-0       stats4_4.0.3         munsell_0.5.0        shinyjs_2.0.0    

Mauricio Garnier-Villarreal

unread,
Jan 22, 2021, 8:51:11 AM1/22/21
to blavaan
David

Not sure what could be causing the issue to change like that, and continue after a while

Eric

The baseline model that you are deining is not exactly a baseline model, as it defines a latent factor

But, the issue is that you are running the models with test="none". When you request this you are telling blavaan to not estimate any fit measure. If you do this, then you cannot estimate any fit measure. Just take out that argument

Ed Merkle

unread,
Jan 22, 2021, 9:16:06 AM1/22/21
to David Allen, blavaan
David,

On Thu, 2021-01-21 at 22:29 -0800, David Allen wrote:
then I changed the structure of the model (deleted two predictors)

Is it possible that you used update() to do this? I can see how this would move you back to lavaan, I can send more details if this is the issue.

Ed

David Allen

unread,
Jan 22, 2021, 10:05:56 AM1/22/21
to blavaan
No, I'm not using update() - the call is (with variable names changed):

model = '
factor1 =~ output1 + output2 + output3 + output4 + output5 + output6
factor2 =~ output7 + output8 + output9
factor1 ~ input1 + input2 + input3 + input4 + input5 + input6 + input7 + input8
factor2 ~ input1 + input2 + input3 + input4 + input5 + input6 + input7 + input8
'
fit = bsem(model, data = datascaled%>% drop_na, mcmcfile = TRUE, save.lvs = TRUE, n.chains = 1)
lvs = blavInspect(fit, what = 'lvs')
summary(fit)

infiniteline

unread,
Jan 22, 2021, 12:00:01 PM1/22/21
to blavaan
Ah. Thanks for that! I put that parameter in due to the warning that came up about missing values, but didn't really know what it did as I didn't see it in the manual.

Ed Merkle

unread,
Jan 22, 2021, 2:58:45 PM1/22/21
to blavaan
@David: I just had a long look at some R documentation (url below) and have added an extra summary.blavaan method that hopefully addresses your problem. You can obtain it by installing blavaan from github.

If you still have a problem after this, it would be helpful if you could send a full script to reproduce the problem (though I realize this might be diffcult if it doesn't happen every time). It would also be helpful to know if your problem is fixed.

Thanks,
Ed

Reply all
Reply to author
Forward
0 new messages