CFA and bootstrap

458 views
Skip to first unread message

kretzsc...@gmail.com

unread,
Feb 16, 2016, 1:50:08 AM2/16/16
to lavaan
Hi there,

I'd like to do a bootstrap based CFA in order to get a confidence interval of the correlation between two latent factors. I played a little bit around, looked at the documentation and searched in the forum. However, my latest attempt (not sure whether it is the right direction) produced the error:

Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x),  :
  'data' must be of a vector type, was 'NULL'

It might be important that I'm using a correlation matrix rather than raw data as input. An example:


library
(lavaan)

# Input
mat
.1 <- '
1
.21 1
.21 .21 1
.20 .20 .20 1
.20 .20 .20 .21 1
.20 .20 .20 .21 .21 1
'

mat1
.cov <-
  getCov
(mat.1, names = c("a1", "a2", "a3",
                         
"b1", "b2", "b3"))

# Model
correlated
.factor <- '
factorA =~ NA*a1 + a2 + a3
factorB =~ NA*b1 + b2 + b3
factorA ~~ 1*factorA
factorB ~~ 1*factorB
'


# Fit ---> OK
fit
.mat1.correlated <- sem(correlated.factor,
                           sample
.cov = mat1.cov,
                           sample
.nobs = 500)
summary
(fit.mat1.correlated, fit.measures = TRUE, standardized = TRUE)


# Fit: Bootstrap ---> Error!
fit
.mat1.correlated.boot <- cfa(correlated.factor,
                                sample
.cov = mat1.cov,
                                sample
.nobs = 500,
                                test
= "bootstrap", verbose = TRUE, bootstrap = 10)
summary
(fit.mat1.correlated.boot, fit.measures = TRUE, standardized = TRUE)


I'm using R version 3.2.3 and lavaan version 0.5-20. Any suggestions what's wrong? I do not now much about bootstrap and CFA yet. So maybe it's the wrong way anyway. So I would be happy if somebody could point me in the right direction.

André

Stas Kolenikov

unread,
Feb 16, 2016, 11:08:24 AM2/16/16
to lav...@googlegroups.com
The bootstrap method is resampling with replacement from the original
data. So yes, you do need the raw data for the bootstrap to make any
sense. Then within each bootstrap replicate, you could compute your
correlation matrix and feed it to lavaan. If you are just using
somebody else's data, then you are stuck. If you are using your own
data, you should supply the data. From how your correlation matrix
looks like, though, it appears that you are simulating a rather
difficult scenario with highly correlated factors and low unique
factor variances... as if you are trying to break lavaan down :). If
you want to see how the bootstrap works for a correlation matrix like
that, you would want to simulate a data set out of this matrix, e.g.
as mvnorm(n=whatever,Sigma=mat.1,mu=rep(0,6) ).


-- Stas Kolenikov, PhD, PStat (ASA, SSC)
-- Principal Survey Scientist, Abt SRBI
-- Education Officer, Survey Research Methods Section of the American
Statistical Association
-- Opinions stated in this email are mine only, and do not reflect the
position of my employer
-- http://stas.kolenikov.name
> --
> You received this message because you are subscribed to the Google Groups
> "lavaan" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to lavaan+un...@googlegroups.com.
> To post to this group, send email to lav...@googlegroups.com.
> Visit this group at https://groups.google.com/group/lavaan.
> For more options, visit https://groups.google.com/d/optout.

kretzsc...@gmail.com

unread,
Feb 23, 2016, 4:33:14 AM2/23/16
to lavaan
Indeed, I do not have the raw data and have to use the correlation matrix. However, based on your code example I used

mvrnorm(n=500, sigma=mat1.cov, mu=rep(0,6), empirical = TRUE)

to simulate a data set and it worked. So I was able to play a little bit with the data.
Thank you very much!

Jing Yu

unread,
Mar 15, 2016, 12:43:41 AM3/15/16
to lavaan
Reply all
Reply to author
Forward
0 new messages