(bootstrapLavaan) Error in Yc[case.idx, var.idx, drop = FALSE] : subscript out of bounds

124 views
Skip to first unread message

André Kretzschmar

unread,
Mar 16, 2017, 5:11:45 PM3/16/17
to lavaan
Hi,
I run an older script with a new lavaan version and spotted an error with regard to bootstrapLavaan:

Error in Yc[case.idx, var.idx, drop = FALSE] : subscript out of bounds

 I don't know what the problem is so you might want to use the following example (data attached):

data <- read.table(file="data_error_bootstrap.dat")
library
(lavaan) #version 0.5-23.1097

model
<-'x =~ x1 + x2 + x3'

fit
<- cfa(model=model, data=data, missing="FIML", estimator = "MLR")
summary
(fit, fit.measures = TRUE, standardized = TRUE)
bootstrapLavaan
(fit, R=10, FUN=fitMeasures, fit.measures="chisq")
# Error: Error in Yc[case.idx, var.idx, drop = FALSE] : subscript out of bounds

If I change the estimator to "ML" or missing to "pairwise", then everything is okay:

fit <- cfa(model=model, data=data, missing="FIML", estimator = "ML")
summary
(fit, fit.measures = TRUE, standardized = TRUE)
bootstrapLavaan
(fit, R=10, FUN=fitMeasures, fit.measures="chisq")
# No Error: MLR --> ML

fit
<- cfa(model=model, data=data, missing="pairwise", estimator = "MLR")
summary
(fit, fit.measures = TRUE, standardized = TRUE)
bootstrapLavaan
(fit, R=10, FUN=fitMeasures, fit.measures="chisq")
# No Error: FIML --> pairwise

I used lavaan version 0.5-23.1097 (R version 3.3.3). There was no error with lavaan version 0.5-20.

André
data_error_bootstrap.dat

Terrence Jorgensen

unread,
Mar 19, 2017, 12:13:24 PM3/19/17
to lavaan
Error in Yc[case.idx, var.idx, drop = FALSE] : subscript out of bounds

This has to do with some newer source code (see file: lav_mvnorm_missing.R).  

Pragmatically speaking, why are you requesting a robust estimator if you are bootstrapping?  In fact, the only fit measure you are requesting is the naïve chi-squared, so you don't need to request MLR or missing = pairwise.  You can just use FIML to get a bootstrap distribution of that statistic (not that it varies at all in this case, since your model has df = 0).

Of course, the results will not really represent the distribution of that statistic under the null hypothesis, even if the data were normal, because you are bootstrapping from data which were (almost certainly) generated from a different population than the one implied by your model's estimates (i.e., the null is false).  The solution to this is to transform the data, commonly referred to as the Bollen-Stine (1992) transformation, which is only available using complete data.  You can request a Bollen-Stine bootstrap in the semTools package, and your top example works in the latest development version (make sure the devtools package is installed):

install.packages("lavaan", repos = "http://www.da.ugent.be", type = "source")
devtools
::install_github("simsem/semTools/semTools")

dat
<- read.table("data_error_bootstrap.dat", header = TRUE)
library
(semTools)


model
<- 'x =~ x1 + x2 + x3'

fit
<- cfa(model=model, data=dat, missing="FIML", estimator = "MLR")
out <- bsBootMiss(fit, nBoot = 10)
summary
(out)

Another curiosity of your example is that there is in fact only complete data and completely missing data, so missing = "fiml" returns the same output as missing = "listwise" would.

lavInspect(fit, "patterns")

Terrence D. Jorgensen
Postdoctoral Researcher, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Reply all
Reply to author
Forward
0 new messages