Manually calculating the standard errors of parameters

62 views
Skip to first unread message

tran viet Yen

unread,
Dec 28, 2021, 1:25:03 AM12/28/21
to lavaan
Hi everyone,

I'm trying to manually calculate the standard errors (SE) from a fitted model using the expected information matrix. I took the example from the tutorial:

library(lavaan)
?HolzingerSwineford1939
visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9
HS.model <- ' visual  =~ x1 + x2 + x3
              textual =~ x4 + x5 + x6
              speed   =~ x7 + x8 + x9 '
fit <- cfa(HS.model, data=HolzingerSwineford1939)
print(sqrt(diag(solve(lavInspect(fit, what = "information.expected")))))

And here is what I got:
Untitled.png
So is there anything wrong with my calculation?

Thanks.

Shu Fai Cheung

unread,
Dec 29, 2021, 9:54:57 PM12/29/21
to lavaan
You can try this:

```
n <- lavInspect(fit, "nobs")
se_manual <- sqrt(diag(solve(lavInspect(fit, what = "information.expected"))) / n)
se_lavaan <- sqrt(diag(vcov(fit)))
se_manual / se_lavaan
```

Divide the variance by n, the sample size.

Hope this helps.

-- Shu Fai

tran viet Yen

unread,
Dec 30, 2021, 8:22:39 PM12/30/21
to lavaan
Hi Fai,

Oh, I did not notice this. Yes, dividing by n will give the correct standard errors. Thank you very much for this. 

Best,

Tran.
Vào lúc 11:54:57 UTC+9 ngày Thứ Năm, 30 tháng 12, 2021, shufai...@gmail.com đã viết:

Yves Rosseel

unread,
Jan 9, 2022, 5:37:05 AM1/9/22
to lav...@googlegroups.com
For more information about the computation of (robust and non-robust)
standard errors in lavaan, see:

https://psyarxiv.com/wmuqj

(The paper is published in the SEM journal, but I prefer the typesetting
of this LaTeX version).

Yves.
> Untitled.png
> So is there anything wrong with my calculation?
>
> Thanks.
>
> --
> 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
> <mailto:lavaan+un...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/lavaan/cb95c58a-a7ca-4978-9cea-03aaa7604d28n%40googlegroups.com
> <https://groups.google.com/d/msgid/lavaan/cb95c58a-a7ca-4978-9cea-03aaa7604d28n%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages