We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question 开发者_StackOverflow中文版I was wondering if there is any R package capable to do multilevel factor analysis?
check out http://openmx.psyc.virginia.edu/. The original MX software (http://www.vcu.edu/mx/) can do multilevel factor analyis (see e.g. [1]), so I suppose openMx
can do that also.
[1]: Bai, Yun and Poon, Wai-Yin(2009)'Using Mx to Analyze Cross-Level Effects in Two-Level Structural Equation Models',Structural Equation Modeling: A Multidisciplinary Journal,16:1,163 — 178
OpenMx 2.5.1 release includes inst/models/nightly/mplus-ex9.6.R (see below) that implements a two-level CFA with continuous factor indicators and covariates. For comparison, see example 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)))
精彩评论