Accessing MxModel objects by other than name
algObj <- mxAlgebra(-2*sum(log(classProbs[1,1]%x%Class1.objective + classProbs[2,1]%x%Class2.objective)), name="mixtureObj")
where Class1 and Class2 are models, and their vector=T (individual observation vector) likelihoods are returned in Class1.objective & Class2.objective vectors. However, I am trying to specify a model with hundreds of models, and it would be much more convenient to be able to refer to them by an array index variable, so that I could use something like
algObj <- mxAlgebra(-2*sum(log(classProbs[1,1]%x%submodels[1].objective + classProbs[2,1]%x%submodels[2].objective)), name="mixtureObj")
with a view to having a much simplified matrix algebra form for the -2lnL, constructed by, e.g., cbind'ing all the vector=TRUE'd likelihoods (not quite sure how to do this within mxAlgebra() either), and post-multiplying that matrix by the classProbs matrix.
I have a feeling I may be needing mxRowObjective() but perhaps someone else has tackled this problem?
Ooh. Fun problem. I don't
I don't think you can get at the
submodels
in the way you like. However, I assume that you're not specifying hundreds of models manually, which gives you Rish ways of dealing with this. To make this brief, I'll assume that your submodels written with an intuitive naming scheme ("Model1", "Model2", etc), and already exist someplace/can be added to your model. Furthermore, assumemyModelNames
is a vector of these model names.So use paste. Or rather, two paste functions: one to make the n-length set of operations to be summed, and one to collapse them all together.
paste("algObj <- mxAlgebra(-2*sum(log(",
paste(paste("classProbs[", 1:n, ",1]%x%", myModelNames, ".objective", sep="), collapse=" + "),
")), name="mixtureObj")", sep="")
The middle line will yield everything from the first
classProbs[1,1]
to the lastmodel.objective
, while the first and last put the header and footer on. There may also be a way to make a matrix of objective results through square bracket substitution.Log in or register to post comments
In reply to Ooh. Fun problem. I don't by Ryne
Umm, let's split this into
Log in or register to post comments
In reply to Umm, let's split this into by mspiegel
nice
Log in or register to post comments
In reply to nice by neale
Success!
Log in or register to post comments