mxModel Help

Wiki home page

[toc list: ol; title: Table of Contents; minlevel: 1; maxlevel: 3; attachments: 1;]

Basic Examples

<em># Create an empty model, and place it in an object.</em>
	model &lt;- mxModel()

# Create a model named 'firstdraft' with one matrix

	model &lt;- mxModel('firstdraft', mxMatrix('Full', nrow = 3, ncol = 3, name = "A"))

# Add two matrices to the model, renaming it too 'finaldraft'

	model &lt;- mxModel(model, name= "finaldraft",
	     mxMatrix('Symm', nrow = 3, name = "S"),
	     mxMatrix('Iden', nrow = 3, name = "F")
	)

Note the difference between the "model" variable, and the "name" of the model

# Add data to the model from an existing data frame in object 'data'

	myData &lt;- data.frame(x=rnorm(100),y=rnorm(100))
	model &lt;- mxModel(model, 
		mxData(myData, type='raw')
	)

# View the matrix named "A" in MxModel object 'model'

	model@matrices$A

# View the data associated with MxModel object 'model'
model@data

Remove an object from a model

You can remove paths, matrices, algebras, and other objects from a model using mxModel, with the to-be-modified model as its first parameter, and then a comma delimited list of the names of the objects you want to remove, setting remove to TRUE e.g.

<em># make a model</em>
	aModel &lt;- <strong>mxModel</strong>("my name", mxMatrix(name="myMatrix", type="Full",nrow=8,ncol=5))
<em># remove by name</em>
	aMinus &lt;- <strong>mxModel</strong>(aModel,  "myMatrix", remove = <font	color="green">TRUE</font>)

Note: If the first parameter is a model, it is used as a base model to modify. If you give a string, then this is used as a name for a new model

This example shows why you must use the name of the entity instead of the entity itself.

The following code WILL NOT WORK because "container.A" and "submodel.A" are identical objects: Both contain the value "A" in the slot "name."

	A &lt;- mxMatrix("Full", 1, 1, name = "A")
	submodel1 &lt;- mxModel("submodel1", A)
	container &lt;- mxModel("container", submodel1, A)
 
	<em># Oh oh, this would have deleted "countainer.A" instead of "submodel.A"</em>
	accident &lt;- mxModel(container, submodel1$A, remove = TRUE)

Please add material here as you learn...

If you have questions not answers, then add those here: That's how a wiki works.