1

谁能建议如何最好地使用 R 中的 lavaan 包来解释测量误差(由 Cronbach 的 alpha 测量)?下面是一个完整的例子。该示例试图根据某人的外向程度来预测某人的朋友数量。请注意,我试图在代码末尾解释外向性测量误差的尝试失败。

#Setup dataset with 10000 observations (individuals).
set.seed(1226)
np <- 10000
df <- data.frame(matrix(0,np,0))

#Create 'true' extraversion with mean=5, SD=0.5.
df$TruE <- round(rnorm(np, 5, 0.5),0)

#Create Friends variable, making it depend on Extraversion such that 
#for every 1 unit increase in extraversion, the person has +3 friends.
df$Frnd <- 3*df$TruE+round(rnorm(np,5,5),0)

#Create items that attempt to measure true extraversion (TruE).
df$ext1 <- df$TruE+round(rnorm(np,0,0.8),0)
df$ext2 <- df$TruE+round(rnorm(np,0,0.8),0)
df$ext3 <- df$TruE+round(rnorm(np,0,0.8),0)
df$ext4 <- df$TruE+round(rnorm(np,0,0.8),0)
df$ext5 <- df$TruE+round(rnorm(np,0,0.8),0)
multi.hist(df[,c("ext1", "ext2", "ext3", "ext4", "ext5")])

#Create latent variable that attempts to measure extraversion from the items.
df$LatE <- rowMeans(df[,c("ext1", "ext2", "ext3", "ext4", "ext5")])

#Check correlation matrix.
round(cor(df),2)

#Check Cronbach alpha for latent variable.
psych::alpha(df[,c("ext1", "ext2", "ext3", "ext4", "ext5")])

#Recover the true model using standard regression (works as expected).
summary(lm(Frnd~TruE, data=df))

#Attempt to recover the true model based on the latent variable using standard regression.
summary(lm(Frnd~LatE, data=df)) #Not correct due to poor reliability

#Using lavaan with latent variable modelling (works very well).
Mod1 <- 'LatE2 =~ ext1 + ext2 + ext3 + ext4 + ext5
         
         Frnd ~ LatE2
        '
Fit1 <- lavaan::sem(Mod1, data=df)
summary(Fit1, standardized=TRUE)

#Attempt to adjust for Cronbach alpha (doesn't work).
Mod2 <- 'Frnd ~ (1-.69)*LatE
        '
Fit2 <- lavaan::sem(Mod2, data=df)
summary(Fit2, standardized=TRUE)
4

0 回答 0