The two programs presented in this example perform calculations with the implied covariances in Example 2. The example assumes that you are familiar with XML programming and have the Microsoft XML parser installed.
A program for processing the implied covariances must first find the implied covariances within the text output file. The Amos Output viewer can provide assistance for writing the code for this task by displaying an XPath expression for any visible object in the viewer. The implied covariance matrix in Example 2 looks like this when displayed in the Amos Output viewer:
Suppose you want an XPath expression for selecting 2.220, the implied covariance between recall2 and place2. Click anywhere in the Implied Covariances table, and then right-click the value 2.220 to display a popup menu.
Click Show Path to display the XPath window.
The XPath window displays an XPath expression for selecting the value 2.220 in the implied covariance matrix. This expression can be copied and pasted into programs that you write.
To begin writing a Visual Basic 6 program to process Amos text output, click Project, then References on the VB6 menu. In the References window, put a check mark next to Microsoft XML, V4.0.
Enter the following program.
Option Explicit
Sub main()
Const FileName = "C:\Program Files\IBM\SPSS\Amos\28\Examples\English\ex02.amosoutput"
Dim objDOM As MSXML2.DOMDocument40
Set objDOM = New MSXML2.DOMDocument40
Dim eRoot As IXMLDOMElement
Dim e As IXMLDOMElement
objDOM.async = False
If Not objDOM.Load(FileName) Then
Debug.Print "Error reading Amos text output file"
End If
Set eRoot = objDOM.documentElement
Set e = eRoot.selectSingleNode("xpath expression goes here")
Debug.Print e.Text
Debug.Print e.getAttribute("x")
End Sub
In the Amos Output viewer's XPath window, click Copy to copy the XPath expression to the clipboard. Then paste the expression into the Basic program, replacing the string xpath expression goes here.
Running the program displays two numbers. The program statement
Debug.Print e.Text
displays 2.220, the implied covariance between recall2 and place1 as currently displayed by the output viewer. The program statement
Debug.Print e.getAttribute("x")
displays 2.22048708774092, the same implied covariance with extended precision.
Efficient processing of tables
In order to perform efficient processing of an entire table, the XPath expression for selecting a value in a table can be split into two expressions: an expression that selects the body of the table (excluding the column labels) and a second expression that selects an individual value within the table body. The following Visual Basic 6 program illustrates this technique by modifying the XPath expression used in the first program of this example. The following program displays the number of rows in the table of implied covariances. Then it displays the sum of the implied variances.
Option Explicit
Sub main()
Const FileName = "C:\Program Files\IBM\SPSS\Amos\28\Examples\English\ex02.amosoutput"
Dim objDOM As MSXML2.DOMDocument40
Set objDOM = New MSXML2.DOMDocument40
Dim eRoot As IXMLDOMElement
objDOM.async = False
If Not objDOM.Load(FileName) Then
Debug.Print "Error reading Amos text output file"
End If
Set eRoot = objDOM.documentElement
Dim eTableBody As IXMLDOMElement
Set eTableBody = eRoot.selectSingleNode("body/div/div[@ntype='models']/div[@ntype='model'][position() = 1]/div[@ntype='group'][position() = 1]/div[@ntype='estimates']/div[@ntype='matrices']/div[@ntype='covariances']/table/tbody")
Dim NumberOfRows As Long
NumberOfRows = eTableBody.childNodes.length
Debug.Print "Number of rows = "; NumberOfRows
Dim i As Long
Dim dSum As Double
dSum = 0
For i = 1 To NumberOfRows
dSum = dSum + MatrixElement(eTableBody, i, i)
Next
Debug.Print "Sum of variances = "; dSum
End Sub
'Return a single element of a numeric matrix
Function MatrixElement(eTableBody As IXMLDOMElement, row As Long, column As Long) As Double
Dim e As IXMLDOMElement
Set e = eTableBody.childNodes(row - 1).childNodes(column)
MatrixElement = CDbl(e.getAttribute("x"))
End Function