On 06/01/2018 10:33 AM,
alexander....@gmail.com wrote:
> Hi lavaan-users group,
>
> I read at
lavaan.org that sample weights can now be used in lavaan, but
> I did not find an example (or argument) on how to do this. Are there any
> hints about it?
The argument is 'sampling.weights'. Below is a small (artificial) example.
Yves.
library(lavaan)
# generate data
set.seed(1234)
pop.model <- '
f =~ x1 + x2 + x3 + x4 + x5
'
Data <- simulateData(pop.model, sample.nobs = 1000)
# add sampling weights
N <- nrow(Data)
wt <- abs(rnorm(N, mean = 1, sd = 2)); wt <- wt/sum(wt)*N
Data$wt <- wt
model <- '
f =~ x1 + x2 + x3 + x4 + x5
'
fit <- sem(model, data = Data, sampling.weights = "wt", estimator = "ML")
summary(fit)