# Effects coding method in CFA

4 posts / 0 new
Offline
Joined: 05/24/2020 - 19:45
Effects coding method in CFA

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) 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")
)

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,
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>
Online
Joined: 01/24/2014 - 12:15
try something like this

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,
means,
mxMatrix(type="Full",nrow=4,ncol=1,free=T,labels=paste0("L__x", 1:4),name="Lmat"),
mxConstraint(mean(Lmat) == 1)
)
Offline
Joined: 05/24/2020 - 19:45
Thanks, that did the trick!

That worked after I added an extra line model &lt;- omxAssignFirstParameters(model) to copy the values in the A matrix into Lmat.

Online
Joined: 03/01/2013 - 14:09
Yep

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.