!
! Kenny & Judd 1984 Psych Bull interactive example
!
#define nfac 6    ! number of factors including residuals
#define nfacsq 36 ! number of factors squared
#define nvar 4    ! number of observed variables
#define nvarsq 16 ! square of number of obs var
#define nextra  1 ! number of extra variables, not squared
#define ntot   21 ! nvar + nvarsq + nextra
#define ninput  9 ! nvar*(nvar+3)/2 + nextra less any products not used 

Title Kenny & Judd model in general form
Data Ngroups=1 Ninput=ninput Nobs=500
! Simulated data from Kenny & Judd 1984 Psychol Bull p 205
Labels X1 X2 Z1 Z2 X1Z1 X1Z2 X2Z1 X2Z2 Y
CMatrix File=kennyint.cov

 Begin Matrices;
  A Full nvar nfac            ! Loadings on Linear factors (including errors)
  B Symm nfac nfac            ! Covariances of Linear factors
  I Iden nfacsq nfacsq        ! Identity matrix
  J Full nfacsq nfacsq        ! Reordering matrix
  P Full nextra nfac          ! Paths from Linear factors to extra variables
  Q Full nextra nfacsq        ! Paths from Squared factors to extra variables
  E Diag nextra nextra Free   ! Residual variance of extra variables
  F Full ninput ntot          ! Filter matrix to select some of the variables
  Z Zero nvar nvarsq          ! Zeroes
 End Matrices;
 
 Specify A
 0 0 100 0 0 0
 101 0 0 102 0 0
 0 0 0 0 103 0
 0 104 0 0 0 105 
 Matrix A
 1 0 .5 0 0 0
 .5 0 0 .5 0 0
 0 1 0 0 .5 0
 0 .5 0 0 0 .5 

 Matrix B
 1 
 0 1
 0 0 1
 0 0 0 1
 0 0 0 0 1
 0 0 0 0 0 1
 Free B 1 1 B 2 1 B 2 2
 Matrix E 1
 Matrix F
 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

 Matrix J File=j6.mat

 Free Q 1 2
 Free P 1 1 P 1 2
 Begin Algebra;
  C = B@B*(I+J) ; ! Covariances among combinations
  M = A@A ;       ! Loadings on combinations
 End Algebra; 

 Covariance F*( A*B*A' |     Z | A*B*P' _
                    Z' | M*C*M'| M*C*Q' _
                P*B*A' | Q*C*M'| P*B*P' + Q*C*Q' + E ) *F';

End Group;
