Amos Basic Tip
Reporting all fit measures with missing data
When you have missing data it takes extra work to get the chi square statistic and other fit measures like CFI. Amos Graphics does the extra work automatically, but when you write an Amos Basic program, you have to include code to do the extra work.
The following Basic program does not do the extra work. It fits a factor analysis model to the grant_x data, which contains missing values. The output does not include the chi square statistic and also does not include most fit measures.
Sub main() Const FileName As String = "c:\program files\amos 4\examples\grant_x.sav" 'Create a new instance of the Amos engine Dim Sem As AmosEngine Set Sem = New AmosEngine Sem.TableOutput Sem.Standardized Sem.Smc Sem.AllImpliedMoments Sem.ModelMeansAndIntercepts Sem.BeginGroup FileName Sem.Structure "visperc = ( ) + (1) spatial + (1) err_v" Sem.Structure "cubes = ( ) + spatial + (1) err_c" Sem.Structure "lozenges = ( ) + spatial + (1) err_l" Sem.Structure "paragrap = ( ) + (1) verbal + (1) err_p" Sem.Structure "sentence = ( ) + verbal + (1) err_s" Sem.Structure "wordmean = ( ) + verbal + (1) err_w" End Sub
In order to compute the chi square statistic the Amos engine needs to know the "function of log likelihood" of the saturated model. Furthermore, to compute many fit measures, the Amos engine needs to know the "function of log likelihood" of the baseline independence model. You need to supply code for fitting the saturated and independence models. Then when you fit your model you need to include statements to tell the Amos engine the value of "function of log likelihood" for the saturated and independence models. The following program shows how this can be done. The SaturatedOrIndependence subroutine can be used as-is in your own programs. The lines that were added to the main program in order to report all fit measures are shown in bold italic type.
Sub Main() Const FileName As String = "c:\program files\amos 4\examples\grant_x.sav" Dim SaturatedCmin As Double Dim LSaturatedResult As Long Dim IndependenceCmin As Double Dim LIndependenceResult As Long 'Try to fit the saturated and independence models LSaturatedResult = SaturatedOrIndependence(SaturatedCmin, False, 6, _ Array("visperc", "cubes", "lozenges", "paragrap", "sentence", "wordmean"), _ FileName) LIndependenceResult = SaturatedOrIndependence(IndependenceCmin, True, 6, _ Array("visperc", "cubes", "lozenges", "paragrap", "sentence", "wordmean"), _ FileName) 'Create a new instance of the Amos engine Dim Sem As AmosEngine Set Sem = New AmosEngine 'Tell the Amos engine about the fit of the saturated and independence models Sem.SetSaturatedFit LSaturatedResult = 0, SaturatedCmin Sem.SetIndependenceFit LIndependenceResult = 0, IndependenceCmin Sem.TableOutput Sem.Standardized Sem.Smc Sem.AllImpliedMoments Sem.ModelMeansAndIntercepts Sem.BeginGroup FileName Sem.Structure "visperc = ( ) + (1) spatial + (1) err_v" Sem.Structure "cubes = ( ) + spatial + (1) err_c" Sem.Structure "lozenges = ( ) + spatial + (1) err_l" Sem.Structure "paragrap = ( ) + (1) verbal + (1) err_p" Sem.Structure "sentence = ( ) + verbal + (1) err_s" Sem.Structure "wordmean = ( ) + verbal + (1) err_w" End Sub 'This is a generic routine that you can use without modification 'to fit the saturated and independence models 'Output: ' CMin ' The minimum discrepancy for the saturated (or independence) model 'Input: ' Independence ' True to fit the independence model, False to fit the saturated model ' NObservedVariables ' Number of observed variables ' ObservedVariables_0b ' Array of observed variable names ' FileName ' Data file name ' TableName ' Data table name (for file formats ' that can contain multiple data tables in a single file) ' GroupingVariable ' Name of variable used to select a subset of data for analysis ' GroupValue ' Value of the GroupingVariable used to select a subset of data for analysis 'Return 0 if ok Function SaturatedOrIndependence(CMin As Double, Independence As Boolean, _ NObservedVariables As Long, ObservedVariables_0b As Variant, _ FileName As String, Optional TableName As String, _ Optional GroupingVariable As String, _ Optional GroupValue As Variant) As Long Dim Sem As AmosEngine Dim i As Integer Dim STemp As String SaturatedOrIndependence = 0 On Error GoTo EHandler Set Sem = New AmosEngine Sem.ModelMeansAndIntercepts Call Sem.GenerateDefaultCovariances(Not Independence) Sem.BeginGroup FileName, TableName, GroupingVariable, GroupValue For i = 0 To NObservedVariables - 1 STemp = ObservedVariables_0b(i) Sem.Mean STemp Next If Sem.FitModel() = 0 Then CMin = Sem.CMin Else SaturatedOrIndependence = 1 End If Quit: Set Sem = Nothing DoEvents Exit Function EHandler: SaturatedOrIndependence = 1 GoTo Quit End Function