Bootstrapping parameter estimate CIs

3,345 views
Skip to first unread message

Conal Monaghan

unread,
May 24, 2014, 1:13:50 AM5/24/14
to lav...@googlegroups.com
Hey all,
      I am having some issues calculating the Confidence Intervals for the parameter coefficients of my Structural Equation Model. The normal SEM model runs well, however the bootstrap creates issues. I inspected the bootstrapped parameter coefficients and there is no missing data, or any observable issues. The same error always appears, "Error in parameterEstimates(SEM.model.boot, ci = TRUE, boot.ci.type = "norm",  : trying to get slot "SampleStats" from an object of a basic class ("matrix") with no slots".
>
>
>                                    #Attach Data
> attach(Dataset)
>
>
>                                     # Specify the factor loadings
> Model <- '
> Factorone=~ F1 + F2 + F3 + F4
> Factortwo =~ Parcel1 + item7 + item9
> Factorthree=~ Parcel2 + Parcel3 + Parcel4
>
>                                  # define the structure/ regressions
>
> Factorone ~ Factortwo + Factorthree '
>
>                                # Run the model
> SEM.model <- sem(Model, data = Dataset)
>
>                                # Examine
> summary(SEM.model, fit.measures=TRUE, standardized = TRUE, modindices = TRUE)
>
>                                # Run bootstraping
> SEM.model.boot <- bootstrapLavaan(SEM.model, R=10, type="ordinary", FUN="coef", warn=-1L)
> parameterEstimates(SEM.model.boot, ci = TRUE, boot.ci.type = "norm", level = 0.95, standardized = TRUE)

Error in parameterEstimates(SEM.model.boot, ci = TRUE, boot.ci.type = "norm", : trying to get slot "SampleStats" from an object of a basic class ("matrix") with no slots



 - Thanks for your help !!

Terrence Jorgensen

unread,
May 25, 2014, 1:10:49 PM5/25/14
to lav...@googlegroups.com

>                                # Run bootstraping
> SEM.model.boot <- bootstrapLavaan(SEM.model, R=10, type="ordinary", FUN="coef", warn=-1L)
> parameterEstimates(SEM.model.boot, ci = TRUE, boot.ci.type = "norm", level = 0.95, standardized = TRUE)

Error in parameterEstimates(SEM.model.boot, ci = TRUE, boot.ci.type = "norm", : trying to get slot "SampleStats" from an object of a basic class ("matrix") with no slots


The bootstrapLavaan() function does not return a "lavaan" object (i.e., the object with your all your model results, such as SEM.model above).  It simply returns the bootstrap distribution of whatever function you want to apply to a lavaan object.  Above, you apply the "coef" function (FUN = "coef"), so your object SEM.model.boot is simply the "distribution" (of size R = 10) of each coefficient in SEM.model

I think what you want to do is tell lavaan that you want bootstrapped SEs when you call sem(), then your call to parameterEstimates() will function as you expect.

nBoots <- 1000
SEM.model <- sem(Model, data = Dataset, se = "boot", test = "Bollen.Stine", bootstrap = nBoots)
parameterEstimates(SEM.model, boot.ci.type = "norm", standardized = TRUE)


Terry 

Conal Monaghan

unread,
May 25, 2014, 9:21:20 PM5/25/14
to lav...@googlegroups.com
Thanks Terry!

               I ran the code and the parameterEstimates() function worked (see below). This call has produced the parameter estimates with bootstrapped conventional standard errors. Now that this function is returning without errors, I was hoping to produce the CI's for the standardized parameter estimates (and later down the track several fit indices). As a result, bootstrapping the "coef" function should produce a distribution on these estimates from which the 95% CI could be determined through the parameterEstimates() function. I was wondering how I these estimates could be produced? 

>nBoots <- 1000
>SEM.model <- sem(Model, data = Dataset, se = "boot", test = "Bollen.Stine", bootstrap = nBoots)
>parameterEstimates(SEM.model, boot.ci.type = "norm", standardized = TRUE)


             lhs        op     rhs   est    se          z      pvalue     ci.lower ci.upper std.lv std.all std.nox
1       Factorone =~     F1    1.000 0.000     NA     NA        1.000    1.000     4.440   0.784   0.784
2       Factorone =~     F2    0.577 0.024    24.090  0.000    0.530    0.624    2.560   0.614   0.614
3       Factorone=~      F3    0.390 0.015   26.435  0.000    0.365    0.423   1.730   0.647   0.647
4       Factorone =~     F4   1.154 0.031    37.803  0.000    1.084    1.204    5.123   0.903   0.903
....
....


Thanks in advance,
                    Conal Monaghan

yrosseel

unread,
May 26, 2014, 10:57:18 AM5/26/14
to lav...@googlegroups.com
On 05/26/2014 03:21 AM, Conal Monaghan wrote:
> Thanks Terry!
>
> I ran the code and the parameterEstimates() function
> worked (see below). This call has produced the parameter estimates with
> bootstrapped conventional standard errors. Now that this function is
> returning without errors, I was hoping to produce the CI's for the
> standardized parameter estimates (and later down the track several fit
> indices). As a result, bootstrapping the "coef" function should produce
> a distribution on these estimates from which the 95% CI could be
> determined through the parameterEstimates() function. I was wondering
> how I these estimates could be produced?

To bootstrap the standardized estimates, you need to use the
bootstrapLavaan() function again. As follows:


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

fit <- cfa(HS.model, data=HolzingerSwineford1939)

out <- bootstrapLavaan(fit, R = 100, FUN = function(x) {
standardizedSolution(x)$est }, verbose = TRUE)

This will return a 100x24 matrix (in practice, you may want to use a
much larger number for R). The rows are the bootstraps, the columns are
the model parameters (here including fixed parameters).

To get a 95% CI, you can compute percentiles on the columns of out:

# just one column:
quantile(out[,1], probs=c(0.025, 0.975))

# all columns
lapply(as.data.frame(out), quantile, probs=c(0.025, 0.975))


To bootstrap one of more fit measures, you can use something like:

out <- bootstrapLavaan(fit, R = 100, FUN = function(x) { fitMeasures(x,
c("cfi", "rmsea")) }, verbose = TRUE)

Yves.

Conal Monaghan

unread,
May 28, 2014, 8:22:10 AM5/28/14
to lav...@googlegroups.com

Thanks Yves ,
      For everyone reading on, this solution works well to extract the required Standardised CIs. Additonally, running the bootstrap solutions for the fit inidicies allows for you to explore the precision of your fit, something relatively unexplored in the literature.

    Good luck,
            Conal

Lívia Bedin

unread,
Mar 22, 2015, 11:51:30 PM3/22/15
to lav...@googlegroups.com
Hi, 

I had the same problem and I just wanted to say THANK YOU Yves!!! 

The best help ever!
Finally I could bootstrap the standardized estimates of my sem model.

Lívia.
Reply all
Reply to author
Forward
0 new messages