Effects coding method in CFA

Posted on
Picture of user. pehkawn Joined: 05/24/2020
I am trying to run a CFA where one latent variable is regressed on four manifest variables. I am trying to constrain the pattern coefficients ($\lambda$) mean to equal one, according to [Kline's (2015, p. 200)](https://www.guilford.com/books/Principles-and-Practice-of-Structural-Equation-Modeling/Rex-Kline/9781462523344) *effects coding method*:

$$ \frac{\lambda_1 + \lambda_2 + \lambda_3 + \lambda_4}{4} = 1 $$

Below is a code example. I tried adding an `mxConstraint()` function in `mxModel()` but the syntax is not correct. How can I apply the constraints properly?


library(OpenMx)
data <- mxData(observed = mydata, type="raw")

# residual variances
res_var <- mxPath(
from = paste0("x", 1:4),
arrows = 2,
free = TRUE,
values = 1,
labels = paste0("e_x", 1:4)
)

# latent variance
lat_var <- mxPath(
from = "L",
arrows = 2,
free = TRUE,
values = 1,
labels = c("var_L")
)

# factor loadings
fac_loads <- mxPath(
from = "L",
to = paste0("x", 1:4),
free = c(TRUE, TRUE, TRUE, TRUE),
values = 1,
arrows = 1,
label = paste0("L__x", 1:4)
)
# means
means <- mxPath(
from = "one",
to = c(L, paste0("x", 1:4),
arrows = 1,
free = FALSE,
values = 0,
labels = c(paste0("mean_", student_sci_ach), "mean_stSCI")
)

model <- mxModel(
"My Model",
type = "RAM",
manifestVars = paste0("x", 1:4),
latentVars = "L",
data,
var, lat_var,
fac_loads,
means,
# I tried defining a constraint here, but this obviously doesn't work.
mxConstraint(mean(paste0("L__x", 1:4)) == 1)
)

results <- mxRun(model)
summary(results)
<\blockcode>

Replied on Mon, 03/07/2022 - 10:02
Picture of user. AdminRobK Joined: 01/24/2014

In an MxConstraint, both sides of the comparator (= in this case) have to be valid MxAlgebra-like expressions, evaluable in the MxModel's namespace; mere character strings aren't accepted. Try something like this:

model <- mxModel(
"My Model",
type = "RAM",
manifestVars = paste0("x", 1:4),
latentVars = "L",
data,
var, lat_var,
fac_loads,
means,
mxMatrix(type="Full",nrow=4,ncol=1,free=T,labels=paste0("L__x", 1:4),name="Lmat"),
mxConstraint(mean(Lmat) == 1)
)
Replied on Tue, 03/08/2022 - 17:54
Picture of user. AdminNeale Joined: 03/01/2013

In reply to by pehkawn

That is one way to avoid trying to start parameters at different values when they appear in different places in the model. Good solution, although it's a bit less controllable than manually setting parameters to the same value wherever they appear, in this case I think changing the mxMatrix line to

mxMatrix(type="Full",nrow=4,ncol=1,free=T, values=1, labels=paste0("L__x", 1:4),name="Lmat"),

Use of omxAssignFirstParameters() means that you don't actually know which starting value was used. Sometimes that's ok, but, (e.g., to debug bad starting values) it's not always ideal.