You are here

$ accessor support for mxModel manifestVars latentVars

the model$ accessor for manifestVars and for latentVars should return the contents of the eponymous model slots: model@manifestVars & model@latentVars

Reporter: 
Created: 
Sun, 03/20/2016 - 20:02
Updated: 
Fri, 04/08/2016 - 10:45

Comments

For implementation hints, see a6a6a03392e97

I'm not convinced the $ accessor is what we want. I believe we agreed that we don't want a $ mutator for manifestVars and latentVars.

To me, the problem is when you print a model it shows $manifestVars when you need to use @manifestVars, e.g.

library(OpenMx)
data(demoOneFactor)
# ===============================
# = Make and run a 1-factor CFA =
# ===============================
 
latents  = c("G") # the latent factor
manifests = names(demoOneFactor) # manifest variables to be modeled
# ====================
# = Make the MxModel =
# ====================
m1 <- mxModel("One Factor", type = "RAM",
    manifestVars = manifests, latentVars = latents,
    mxPath(from = latents, to = manifests),
    mxPath(from = manifests, arrows = 2),
    mxPath(from = latents, arrows = 2, free = FALSE, values = 1.0),
    mxData(cov(demoOneFactor), type = "cov", numObs = 500)
)
 
m1
#MxModel 'One Factor' 
#type : RAM 
#$matrices : 'A', 'S', and 'F' 
#$algebras : NULL 
#$constraints : NULL 
#$intervals : NULL 
#$latentVars : 'G' 
#$manifestVars : 'x1', 'x2', 'x3', 'x4', and 'x5' 
#$data : 5 x 5 
#$data means : NA
#$data type: 'cov' 
#$submodels : NULL 
#$expectation : MxExpectationRAM 
#$fitfunction : MxFitFunctionML 
#$compute : NULL 
#$independent : FALSE 
#$options :  
#$output : FALSE 

The change I would propose is to alter the print method to show @manifestVars instead of $manifestVars. To me, manifestVars is something that you may want to look at via the print method, but I'm really not sure why you would ever need to use model@manifestVars.

If it's a umx code issue, find and replace of "$manifestVars" with "@manifestVars" should be neither difficult nor error prone.

The current behavior is this:

  1. model$manifestVars and model$latentVars works for all models.
  2. manifestVars and latentVars are displayed as "none" for all "default" type (i.e. non-RAM, non-LISREL) models, regardless of what was given to mxModel() as the manifestVars and latentVars argument. However, model$manifestVars still returns whatever was given to manifestVars.
  3. Tab completion can always be used for manifestVars and latentVars
  4. Nothing smart is done for matrix versions RAM/LISREL models wrt manifestVars/latentVars. The user can set these to anything, regardless of the content of the model.
  5. manifestVars and latentVars are part of names(model).

If modifications or extensions are desired, provided a detailed description with example code an re-open the issue.