Attachment | Size |
---|---|
CO_A2_Output.txt [6] | 53.87 KB |
Hi!
I am trying to constrain the results of an algebra, either to a fixed value or constraining the results of two algebras to be equivalent. I am using https://openmx.ssri.psu.edu//wiki/mxConstraint-help as a starting point.
Example output is attached, but the relevant lines of code are below
I want to fix AlCO[2,2] to 0 in the first example.
nl <- 3 # number of latent factors # Matrices ac, cc, and ec to store a, c, and e path coefficients for latent phenotype(s) XMN <- mxMatrix(type="Lower", nrow=nl, ncol=nl, free=TRUE, values=c(.6, .1, .1, .1, .1, 0), labels=c("x11MN", "x21MN", "x22MN", "x31MN", "x32MN", "x33MN"), name="XMN" ) YMN <- mxMatrix(type="Lower", nrow=nl, ncol=nl, free=TRUE, values=c(.6, .1, .1, .1, .1, .1), labels=c("y11MN", "y21MN", "y22MN", "y31MN", "y32MN", "y33MN"), name="YMN" ) ZMN <- mxMatrix(type="Lower", nrow=nl, ncol=nl, free=TRUE, values=c(.6, .1, .1, .1, .1, .1), labels=c("z11MN", "z21MN", "z22MN", "z31MN", "z32MN", "z33MN"), name="ZMN" ) XCO <- mxMatrix(type="Lower", nrow=nl, ncol=nl, free=TRUE, values=c(.6, .1, .1, .1, .1, 0), labels=c("x11CO", "x21CO", "x22CO", "x31CO", "x32CO", "x33CO"), name="XCO" ) YCO <- mxMatrix(type="Lower", nrow=nl, ncol=nl, free=TRUE, values=c(.6, .1, .1, .1, .1, .1), labels=c("y11CO", "y21CO", "y22CO", "y31CO", "y32CO", "y33CO"), name="YCO" ) ZCO <- mxMatrix(type="Lower", nrow=nl, ncol=nl, free=TRUE, values=c(.6, .1, .1, .1, .1, .1), labels=c("z11CO", "z21CO", "z22CO", "z31CO", "z32CO", "z33CO"), name="ZCO" ) AlMN <- mxAlgebra(XMN %*% t(XMN), name="AlMN") ClMN <- mxAlgebra(YMN %*% t(YMN), name="ClMN") ElMN <- mxAlgebra(ZMN %*% t(ZMN), name="ElMN") AlCO <- mxAlgebra(XCO %*% t(XCO), name="AlCO") ClCO <- mxAlgebra(YCO %*% t(YCO), name="ClCO") ElCO <- mxAlgebra(ZCO %*% t(ZCO), name="ElCO") CO_ACons2 <- mxMatrix("Full", 1, 1, free=FALSE, values=0, labels="AlCO[2,2]", name="CO_ACons2")
Example 1 runs but the output of the constrained correlation matrix is no different than the base model (seen in attached output)
In this second example, I want to constrain corLMN[1,2] and corLCO[1,2] to be the same.
VarLMN <- mxAlgebra(expression = AlMN + ClMN + ElMN, name="VarLMN") VarLCO <- mxAlgebra(expression = AlCO + ClCO + ElCO, name="VarLCO") corLMN <- mxAlgebra(cov2cor(VarLMN), name="corLMN") corLCO <- mxAlgebra(cov2cor(VarLCO), name="corLCO") MN_CorCons12 <- mxMatrix("Full", 1, 1, free=TRUE, labels="corLMN[1,2]", name="MN_CorCons12") CO_CorCons12 <- mxMatrix("Full", 1, 1, free=TRUE, labels="corLCO[1,2]", name="CO_CorCons12") CorCons12 <- mxConstraint(MN_CorCons12 == CO_CorCons12, name="CorCons12")
The model does not run in this example, I get an error "entity unknown"