It seems that constants cannot be used in the arguments to mxConstraint function calls. Good news, only the first and third arguments need be fixed! Here is an example snippet:
> onelocus<-mxModel("onelocus", mxAlgebraObjective("NegativeLogLikelihood"),
mxMatrix("Full", nrow=1, ncol=1, free=TRUE, values=c(.3333), name="P"), # P, freq of allele 1
mxMatrix("Full", nrow=1, ncol=1, free=TRUE, values=c(.3333), name="Q"), # Q, freq of allele 2
mxMatrix("Full", nrow=1, ncol=1, free=TRUE, values=c(.3333), name="R"), # R, freq of allele 3
mxMatrix("Unit", nrow=1, ncol=1, name="I"), # 1.0 constant for equality constraint
mxMatrix("Full", nrow=4, ncol=1, values=c(234,261,182,94),name="ObservedFreqs"), # Data
mxAlgebra(rbind(P*(P+2*R), Q*(Q+2*R), 2*P*Q, R*R), name="ExpectedFreqs"), # Predicted proportions
mxAlgebra(P+Q+R, name="SumAlleleFreqs"), # P+Q+R has to equal 1.0
mxAlgebra(-(sum( log(ExpectedFreqs) * ObservedFreqs )), name = "NegativeLogLikelihood"), # here is -log Likelihood
mxConstraint("I", "=", "SumAlleleFreqs") # This is the equality constraint
)
#run the model
run<-mxRun(onelocus)
run@matrices
run@algebras
Running onelocus
Error: Unknown reference '1.0' detected in the entity 'untitled4' in model 'onelocus'
#1
Huh? I ran the example with the latest OpenMx version from subversion and it worked. Try closing R and then make clean install.
Log in or register to post comments
#2
Closing R and firing it up again seemed to do the trick. Sorry to bother you. Great that it works!!
Log in or register to post comments