用于多级因子分析的R包

时间:2011-07-25 03:54:02

标签: r

我想知道是否有任何R包能够进行多级因子分析?

2 个答案:

答案 0 :(得分:5)

结帐http://openmx.psyc.virginia.edu/。最初的MX软件(http://www.vcu.edu/mx/)可以进行多级因子分析(参见[1]),所以我认为openMx也可以做到这一点。

[1]:Bai,Yun和Poon,Wai-Yin(2009)'使用Mx分析两级结构方程中的跨层效应 模型',结构方程模型:多学科期刊,16:1,163 - 178

答案 1 :(得分:4)

OpenMx 2.5.1版本包括inst/models/nightly/mplus-ex9.6.R(见下文),它实现了具有连续因子指标和协变量的两级CFA。有关比较,请参见示例9.6,https://www.statmodel.com/usersguide/chapter9.shtml

library(OpenMx)

set.seed(1)
ex96 <- suppressWarnings(try(read.table("models/nightly/data/ex9.6.dat")))
if (is(ex96, "try-error")) ex96 <- read.table("data/ex9.6.dat")

ex96$V8 <- as.integer(ex96$V8)
bData <- ex96[!duplicated(ex96$V8), c('V7', 'V8')]
colnames(bData) <- c('w', 'clusterID')
wData <- ex96[,-match(c('V7'), colnames(ex96))]
colnames(wData) <- c(paste0('y', 1:4), paste0('x', 1:2), 'clusterID')

bModel <- mxModel('between', type="RAM",
                  mxData(type="raw", observed=bData, primaryKey="clusterID"),
                  latentVars = c("lw", "fb"),
                  mxPath("one", "lw", labels="data.w", free=FALSE),
                  mxPath("fb", arrows=2, labels="psiB"),
                  mxPath("lw", 'fb', labels="phi1"))

wModel <- mxModel('within', type="RAM", bModel,
                  mxData(type="raw", observed=wData, sort=FALSE),  #[abs(wData$clusterID - 41)<= 25,]
                  manifestVars = paste0('y', 1:4),
                  latentVars = c('fw', paste0("xe", 1:2)),
                  mxPath("one", paste0('y', 1:4), values=runif(4), labels=paste0("gam0", 1:4)),
                  mxPath("one", paste0('xe', 1:2), labels=paste0('data.x',1:2), free=FALSE),
                  mxPath(paste0('xe', 1:2), "fw", labels=paste0('gam', 1:2, '1')),
                  mxPath('fw', arrows=2, values=1.1, labels="varFW"),
                  mxPath('fw', paste0('y', 1:4), free=c(FALSE, rep(TRUE, 3)),
                         values=c(1,runif(3)), labels=paste0("loadW", 1:4)),
                  mxPath('between.fb', paste0('y', 1:4), values=c(1,runif(3)),
                         free=c(FALSE, rep(TRUE, 3)), labels=paste0("loadB", 1:4),
                         joinKey="clusterID"),
                  mxPath(paste0('y', 1:4), arrows=2, values=rlnorm(4), labels=paste0("thetaW", 1:4)))