我试图弄清楚如何在 R 的 OpenMx 包中的潜在增长曲线模型中正确添加斜率和截距的预测器。
我想在一个非常简单的增长曲线模型中预测性别的斜率和截距。为了这个问题,假设它是此处文档中描述的模型。
我会添加什么来包含斜率和截距的时不变预测器?在 MPlus 中,我会写i on male;
,我会估计从性别变量到潜在截距的路径。要在 OpenMx 中做同样的事情,我是否只需添加该路径规范?我是否需要覆盖任何默认值,以便我不估计这个清单变量的方差或平均路径(或者我这样做)?
为了便于参考,下面是简单增长曲线的代码,以及我为预测器添加的代码。但是,当我添加预测变量时,我得到错误“协方差矩阵不是正定的”。这也是我在真实数据中看到的。
注意,这个问题是在 OpenMx 论坛上交叉发布的。
myLongitudinalData=data.frame(x1=rnorm(100),
x2=rnorm(100),
x3=rnorm(100),
x4=rnorm(100),
x5=rnorm(100),
male=round(runif(100,0,1)))
require(OpenMx)
growthCurveModel <- mxModel("Linear Growth Curve Model Path Specification",
type="RAM",
mxData(
myLongitudinalData,
type="raw"
),
manifestVars=c("x1","x2","x3","x4","x5"),
latentVars=c("intercept","slope"),
# residual variances
mxPath(
from=c("x1","x2","x3","x4","x5"),
arrows=2,
free=TRUE,
values = c(1, 1, 1, 1, 1),
labels=c("residual","residual","residual","residual","residual")
),
# latent variances and covariance
mxPath(
from=c("intercept","slope"),
arrows=2,
connect="unique.pairs",
free=TRUE,
values=c(1, 1, 1),
labels=c("vari", "cov", "vars")
),
# intercept loadings
mxPath(
from="intercept",
to=c("x1","x2","x3","x4","x5"),
arrows=1,
free=FALSE,
values=c(1, 1, 1, 1, 1)
),
# slope loadings
mxPath(
from="slope",
to=c("x1","x2","x3","x4","x5"),
arrows=1,
free=FALSE,
values=c(0, 1, 2, 3, 4)
),
# manifest means
mxPath(
from="one",
to=c("x1", "x2", "x3", "x4", "x5"),
arrows=1,
free=FALSE,
values=c(0, 0, 0, 0, 0)
),
# latent means
mxPath(
from="one",
to=c("intercept", "slope"),
arrows=1,
free=TRUE,
values=c(1, 1),
labels=c("meani", "means")
)
) # close model
growthCurveFit <- mxRun(growthCurveModel)
summary(growthCurveFit)
我尝试添加一个预测器——我将性别变量添加到清单变量中,然后创建一个从它到潜在变量的路径定义(朝向底部):
growthCurveModel2 <- mxModel("Linear Growth Curve Model Path Specification",
type="RAM",
mxData(
myLongitudinalData,
type="raw"
),
manifestVars=c("x1","x2","x3","x4","x5","male"),
latentVars=c("intercept","slope"),
# residual variances
mxPath(
from=c("x1","x2","x3","x4","x5"),
arrows=2,
free=TRUE,
values = c(1, 1, 1, 1, 1),
labels=c("residual","residual","residual","residual","residual")
),
# latent variances and covariance
mxPath(
from=c("intercept","slope"),
arrows=2,
connect="unique.pairs",
free=TRUE,
values=c(1, 1, 1),
labels=c("vari", "cov", "vars")
),
# intercept loadings
mxPath(
from="intercept",
to=c("x1","x2","x3","x4","x5"),
arrows=1,
free=FALSE,
values=c(1, 1, 1, 1, 1)
),
# slope loadings
mxPath(
from="slope",
to=c("x1","x2","x3","x4","x5"),
arrows=1,
free=FALSE,
values=c(0, 1, 2, 3, 4)
),
# manifest means
mxPath(
from="one",
to=c("x1", "x2", "x3", "x4", "x5"),
arrows=1,
free=FALSE,
values=c(0, 0, 0, 0, 0)
),
# latent means
mxPath(
from="one",
to=c("intercept", "slope"),
arrows=1,
free=TRUE,
values=c(1, 1),
labels=c("meani", "means")
),
mxPath(
from="male",
to=c("intercept", "slope"),
arrows=1,
free=TRUE,
values=c(1,1),
labels=c("iOnMale", "sOnMale"))
) # close model
growthCurveFit2 <- mxRun(growthCurveModel2)
summary(growthCurveFit2)