Running examples in 'sem-Ex.R' failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: sem
> ### Title: General Structural Equation Models
> ### Aliases: sem sem.semmod sem.default sem.semmodList sem.msemmod
> ###   startvalues startvalues2 coef.sem vcov.sem df.residual.sem coef.msem
> ###   vcov.msem df.residual.msem
> ### Keywords: models
> 
> ### ** Examples
> 
> 
> # The following example illustrates the use the text argument to 
> #   readMoments() and specifyEquations():
> 
> R.DHP <- readMoments(diag=FALSE, names=c("ROccAsp", "REdAsp", "FOccAsp", 
+                 "FEdAsp", "RParAsp", "RIQ", "RSES", "FSES", "FIQ", "FParAsp"),
+                 text="
+     .6247     
+     .3269  .3669       
+     .4216  .3275  .6404
+     .2137  .2742  .1124  .0839
+     .4105  .4043  .2903  .2598  .1839
+     .3240  .4047  .3054  .2786  .0489  .2220
+     .2930  .2407  .4105  .3607  .0186  .1861  .2707
+     .2995  .2863  .5191  .5007  .0782  .3355  .2302  .2950
+     .0760  .0702  .2784  .1988  .1147  .1021  .0931 -.0438  .2087
+ ")
Read 45 items
> 
> model.dhp.1 <- specifyEquations(covs="RGenAsp, FGenAsp", text="
+ RGenAsp = gam11*RParAsp + gam12*RIQ + gam13*RSES + gam14*FSES + beta12*FGenAsp
+ FGenAsp = gam23*RSES + gam24*FSES + gam25*FIQ + gam26*FParAsp + beta21*RGenAsp
+ ROccAsp = 1*RGenAsp
+ REdAsp = lam21(1)*RGenAsp  # to illustrate setting start values
+ FOccAsp = 1*FGenAsp
+ FEdAsp = lam42(1)*FGenAsp
+ ")
Read 6 items
NOTE: adding 4 variances to the model
> 
> sem.dhp.1 <- sem(model.dhp.1, R.DHP, 329,
+     fixed.x=c('RParAsp', 'RIQ', 'RSES', 'FSES', 'FIQ', 'FParAsp'))
> summary(sem.dhp.1)

 Model Chisquare =  26.69722   Df =  15 Pr(>Chisq) = 0.03130238
 AIC =  64.69722
 BIC =  -60.24365

 Normalized Residuals
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-0.79953 -0.11783  0.00000 -0.01201  0.03974  1.56525 

 R-square for Endogenous Variables
RGenAsp FGenAsp ROccAsp  REdAsp FOccAsp  FEdAsp 
 0.5220  0.6170  0.5879  0.6639  0.6888  0.5954 

 Parameter Estimates
                   Estimate    Std Error  z value    Pr(>|z|)    
gam11               0.16122238 0.03879229  4.1560415 3.238091e-05
gam12               0.24964951 0.04398093  5.6763131 1.376288e-08
gam13               0.21840339 0.04419737  4.9415476 7.750487e-07
gam14               0.07183929 0.04970696  1.4452563 1.483859e-01
beta12              0.18423232 0.09488787  1.9415793 5.218805e-02
gam23               0.06188691 0.05171968  1.1965835 2.314690e-01
gam24               0.22886711 0.04416218  5.1824232 2.190216e-07
gam25               0.34903540 0.04528979  7.7067130 1.290997e-14
gam26               0.15953413 0.03882593  4.1089578 3.974486e-05
beta21              0.23547779 0.11938929  1.9723527 4.856936e-02
lam21               1.06267767 0.09013865 11.7893677 4.428532e-32
lam42               0.92972555 0.07028108 13.2286752 5.993451e-40
V[RGenAsp]          0.28098694 0.04623153  6.0778199 1.218274e-09
C[RGenAsp,FGenAsp] -0.02260935 0.05119391 -0.4416413 6.587488e-01
V[FGenAsp]          0.26383537 0.04466688  5.9067334 3.489577e-09
V[ROccAsp]          0.41214523 0.05122464  8.0458399 8.565593e-16
V[REdAsp]           0.33614544 0.05209991  6.4519386 1.104283e-10
V[FOccAsp]          0.31119476 0.04592712  6.7758385 1.236868e-11
V[FEdAsp]           0.40460387 0.04618438  8.7606206 1.941783e-18
                                       
gam11              RGenAsp <--- RParAsp
gam12              RGenAsp <--- RIQ    
gam13              RGenAsp <--- RSES   
gam14              RGenAsp <--- FSES   
beta12             RGenAsp <--- FGenAsp
gam23              FGenAsp <--- RSES   
gam24              FGenAsp <--- FSES   
gam25              FGenAsp <--- FIQ    
gam26              FGenAsp <--- FParAsp
beta21             FGenAsp <--- RGenAsp
lam21              REdAsp <--- RGenAsp 
lam42              FEdAsp <--- FGenAsp 
V[RGenAsp]         RGenAsp <--> RGenAsp
C[RGenAsp,FGenAsp] FGenAsp <--> RGenAsp
V[FGenAsp]         FGenAsp <--> FGenAsp
V[ROccAsp]         ROccAsp <--> ROccAsp
V[REdAsp]          REdAsp <--> REdAsp  
V[FOccAsp]         FOccAsp <--> FOccAsp
V[FEdAsp]          FEdAsp <--> FEdAsp  

 Iterations =  32 
> 
> # Note: The following set of examples can't be run via example() because the default file
> #  argument of specifyeEquations, specifyModel(), and readMoments() requires that the model 
> #  specification and covariances, correlations, or raw moments be entered in an interactive
> #  session at the command prompt. The examples can be copied and run in the R console,
> #  however. See ?specifyModel and ?readMoments for further information.
> #  These examples are repeated below using file input to specifyModel() and
> #  readMoments(). The second version of the examples may be executed through example().
> 
>     ## Not run: 
> ##D 
> ##D # ------------- Duncan, Haller and Portes peer-influences model ----------------------
> ##D # A nonrecursive SEM with unobserved endogenous variables and fixed exogenous variables
> ##D 
> ##D R.DHP <- readMoments(diag=FALSE, names=c("ROccAsp", "REdAsp", "FOccAsp", 
> ##D                 "FEdAsp", "RParAsp", "RIQ", "RSES", "FSES", "FIQ", "FParAsp"))
> ##D     .6247     
> ##D     .3269  .3669       
> ##D     .4216  .3275  .6404
> ##D     .2137  .2742  .1124  .0839
> ##D     .4105  .4043  .2903  .2598  .1839
> ##D     .3240  .4047  .3054  .2786  .0489  .2220
> ##D     .2930  .2407  .4105  .3607  .0186  .1861  .2707
> ##D     .2995  .2863  .5191  .5007  .0782  .3355  .2302  .2950
> ##D     .0760  .0702  .2784  .1988  .1147  .1021  .0931 -.0438  .2087
> ##D             
> ##D # Fit the model using a symbolic ram specification
> ##D 
> ##D model.dhp <- specifyModel()
> ##D     RParAsp  -> RGenAsp, gam11,  NA
> ##D     RIQ      -> RGenAsp, gam12,  NA
> ##D     RSES     -> RGenAsp, gam13,  NA
> ##D     FSES     -> RGenAsp, gam14,  NA
> ##D     RSES     -> FGenAsp, gam23,  NA
> ##D     FSES     -> FGenAsp, gam24,  NA
> ##D     FIQ      -> FGenAsp, gam25,  NA
> ##D     FParAsp  -> FGenAsp, gam26,  NA
> ##D     FGenAsp  -> RGenAsp, beta12, NA
> ##D     RGenAsp  -> FGenAsp, beta21, NA
> ##D     RGenAsp  -> ROccAsp,  NA,     1
> ##D     RGenAsp  -> REdAsp,  lam21,  NA
> ##D     FGenAsp  -> FOccAsp,  NA,     1
> ##D     FGenAsp  -> FEdAsp,  lam42,  NA
> ##D     RGenAsp <-> RGenAsp, ps11,   NA
> ##D     FGenAsp <-> FGenAsp, ps22,   NA
> ##D     RGenAsp <-> FGenAsp, ps12,   NA
> ##D     ROccAsp <-> ROccAsp, theta1, NA
> ##D     REdAsp  <-> REdAsp,  theta2, NA
> ##D     FOccAsp <-> FOccAsp, theta3, NA
> ##D     FEdAsp  <-> FEdAsp,  theta4, NA
> ##D     
> ##D # an equivalent specification, allowing specifyModel() to generate
> ##D #  variance parameters for endogenous variables (and suppressing the
> ##D #  unnecessary NAs):
> ##D  
> ##D model.dhp <- specifyModel()
> ##D RParAsp  -> RGenAsp, gam11
> ##D RIQ      -> RGenAsp, gam12
> ##D RSES     -> RGenAsp, gam13
> ##D FSES     -> RGenAsp, gam14
> ##D RSES     -> FGenAsp, gam23
> ##D FSES     -> FGenAsp, gam24
> ##D FIQ      -> FGenAsp, gam25
> ##D FParAsp  -> FGenAsp, gam26
> ##D FGenAsp  -> RGenAsp, beta12
> ##D RGenAsp  -> FGenAsp, beta21
> ##D RGenAsp  -> ROccAsp,  NA,     1
> ##D RGenAsp  -> REdAsp,  lam21
> ##D FGenAsp  -> FOccAsp,  NA,     1
> ##D FGenAsp  -> FEdAsp,  lam42
> ##D RGenAsp <-> FGenAsp, ps12
> ##D 
> ##D # Another equivalent specification, telling specifyModel to add paths for 
> ##D #   variances and covariance of RGenAsp and FGenAsp:
> ##D  
> ##D model.dhp <- specifyModel(covs="RGenAsp, FGenAsp")
> ##D RParAsp  -> RGenAsp, gam11
> ##D RIQ      -> RGenAsp, gam12
> ##D RSES     -> RGenAsp, gam13
> ##D FSES     -> RGenAsp, gam14
> ##D RSES     -> FGenAsp, gam23
> ##D FSES     -> FGenAsp, gam24
> ##D FIQ      -> FGenAsp, gam25
> ##D FParAsp  -> FGenAsp, gam26
> ##D FGenAsp  -> RGenAsp, beta12
> ##D RGenAsp  -> FGenAsp, beta21
> ##D RGenAsp  -> ROccAsp,  NA,     1
> ##D RGenAsp  -> REdAsp,  lam21
> ##D FGenAsp  -> FOccAsp,  NA,     1
> ##D FGenAsp  -> FEdAsp,  lam42
> ##D 
> ##D # Yet another equivalent specification using specifyEquations():
> ##D 
> ##D model.dhp.1 <- specifyEquations(covs="RGenAsp, FGenAsp")
> ##D RGenAsp = gam11*RParAsp + gam12*RIQ + gam13*RSES + gam14*FSES + beta12*FGenAsp
> ##D FGenAsp = gam23*RSES + gam24*FSES + gam25*FIQ + gam26*FParAsp + beta21*RGenAsp
> ##D ROccAsp = 1*RGenAsp
> ##D REdAsp = lam21(1)*RGenAsp  # to illustrate setting start values
> ##D FOccAsp = 1*FGenAsp
> ##D FEdAsp = lam42(1)*FGenAsp
> ##D  
> ##D sem.dhp.1 <- sem(model.dhp.1, R.DHP, 329,
> ##D     fixed.x=c('RParAsp', 'RIQ', 'RSES', 'FSES', 'FIQ', 'FParAsp'))
> ##D summary(sem.dhp.1)
> ##D 
> ##D # Fit the model using a numerical ram specification (not recommended!)
> ##D 
> ##D ram.dhp <- matrix(c(
> ##D #               heads   to      from    param  start
> ##D                 1,       1,     11,      0,     1,
> ##D                 1,       2,     11,      1,     NA, # lam21
> ##D                 1,       3,     12,      0,     1,
> ##D                 1,       4,     12,      2,     NA, # lam42
> ##D                 1,      11,      5,      3,     NA, # gam11
> ##D                 1,      11,      6,      4,     NA, # gam12
> ##D                 1,      11,      7,      5,     NA, # gam13
> ##D                 1,      11,      8,      6,     NA, # gam14
> ##D                 1,      12,      7,      7,     NA, # gam23
> ##D                 1,      12,      8,      8,     NA, # gam24
> ##D                 1,      12,      9,      9,     NA, # gam25
> ##D                 1,      12,     10,     10,     NA, # gam26
> ##D                 1,      11,     12,     11,     NA, # beta12
> ##D                 1,      12,     11,     12,     NA, # beta21
> ##D                 2,       1,      1,     13,     NA, # theta1
> ##D                 2,       2,      2,     14,     NA, # theta2
> ##D                 2,       3,      3,     15,     NA, # theta3
> ##D                 2,       4,      4,     16,     NA, # theta4
> ##D                 2,      11,     11,     17,     NA, # psi11
> ##D                 2,      12,     12,     18,     NA, # psi22
> ##D                 2,      11,     12,     19,     NA  # psi12
> ##D                 ), ncol=5, byrow=TRUE)
> ##D 
> ##D params.dhp <- c('lam21', 'lam42', 'gam11', 'gam12', 'gam13', 'gam14',
> ##D                  'gam23',  'gam24',  'gam25',  'gam26',
> ##D                  'beta12', 'beta21', 'theta1', 'theta2', 'theta3', 'theta4',
> ##D                  'psi11', 'psi22', 'psi12')
> ##D                  
> ##D vars.dhp <- c('ROccAsp', 'REdAsp', 'FOccAsp', 'FEdAsp', 'RParAsp', 'RIQ',
> ##D                 'RSES', 'FSES', 'FIQ', 'FParAsp', 'RGenAsp', 'FGenAsp')
> ##D                 
> ##D sem.dhp.2 <- sem(ram.dhp, R.DHP, 329, param.names=params.dhp, var.names=vars.dhp, 
> ##D 	fixed.x=5:10)
> ##D summary(sem.dhp.2)
> ##D 
> ##D 
> ##D # -------------------- Wheaton et al. alienation data ----------------------
> ##D     
> ##D 
> ##D S.wh <- readMoments(names=c('Anomia67','Powerless67','Anomia71',
> ##D                                     'Powerless71','Education','SEI'))
> ##D    11.834                                    
> ##D     6.947    9.364                            
> ##D     6.819    5.091   12.532                    
> ##D     4.783    5.028    7.495    9.986            
> ##D    -3.839   -3.889   -3.841   -3.625   9.610     
> ##D   -21.899  -18.831  -21.748  -18.775  35.522  450.288
> ##D 
> ##D # This is the model in the SAS manual for PROC CALIS: A Recursive SEM with
> ##D # latent endogenous and exogenous variables.
> ##D # Curiously, both factor loadings for two of the latent variables are fixed.
> ##D 
> ##D model.wh.1 <- specifyModel()
> ##D     Alienation67   ->  Anomia67,      NA,     1
> ##D     Alienation67   ->  Powerless67,   NA,     0.833
> ##D     Alienation71   ->  Anomia71,      NA,     1
> ##D     Alienation71   ->  Powerless71,   NA,     0.833 
> ##D     SES            ->  Education,     NA,     1     
> ##D     SES            ->  SEI,           lamb,   NA
> ##D     SES            ->  Alienation67,  gam1,   NA
> ##D     Alienation67   ->  Alienation71,  beta,   NA
> ##D     SES            ->  Alienation71,  gam2,   NA
> ##D     Anomia67       <-> Anomia67,      the1,   NA
> ##D     Anomia71       <-> Anomia71,      the1,   NA
> ##D     Powerless67    <-> Powerless67,   the2,   NA
> ##D     Powerless71    <-> Powerless71,   the2,   NA
> ##D     Education      <-> Education,     the3,   NA
> ##D     SEI            <-> SEI,           the4,   NA
> ##D     Anomia67       <-> Anomia71,      the5,   NA
> ##D     Powerless67    <-> Powerless71,   the5,   NA
> ##D     Alienation67   <-> Alienation67,  psi1,   NA
> ##D     Alienation71   <-> Alienation71,  psi2,   NA
> ##D     SES            <-> SES,           phi,    NA
> ##D                            
> ##D sem.wh.1 <- sem(model.wh.1, S.wh, 932)
> ##D summary(sem.wh.1)
> ##D 
> ##D # The same model in equation format:
> ##D 
> ##D model.wh.1 <- specifyEquations()
> ##D Anomia67 = 1*Alienation67
> ##D Powerless67 = 0.833*Alienation67
> ##D Anomia71 = 1*Alienation71
> ##D Powerless71 = 0.833*Alienation71
> ##D Education = 1*SES
> ##D SEI = lamb*SES
> ##D Alienation67 = gam1*SES
> ##D Alienation71 = gam2*SES + beta*Alienation67
> ##D V(Anomia67) = the1
> ##D V(Anomia71) = the1
> ##D V(Powerless67) = the2
> ##D V(Powerless71) = the2
> ##D V(SES) = phi
> ##D C(Anomia67, Anomia71) = the5
> ##D C(Powerless67, Powerless71) = the5
> ##D 
> ##D # The same model, but treating one loading for each latent variable as free
> ##D # (and equal to each other).
> ##D 
> ##D model.wh.2 <- specifyModel()
> ##D     Alienation67   ->  Anomia67,      NA,        1
> ##D     Alienation67   ->  Powerless67,   lamby,    NA
> ##D     Alienation71   ->  Anomia71,      NA,        1
> ##D     Alienation71   ->  Powerless71,   lamby,    NA 
> ##D     SES            ->  Education,     NA,        1     
> ##D     SES            ->  SEI,           lambx,    NA
> ##D     SES            ->  Alienation67,  gam1,     NA
> ##D     Alienation67   ->  Alienation71,  beta,     NA
> ##D     SES            ->  Alienation71,  gam2,     NA
> ##D     Anomia67       <-> Anomia67,      the1,     NA
> ##D     Anomia71       <-> Anomia71,      the1,     NA
> ##D     Powerless67    <-> Powerless67,   the2,     NA
> ##D     Powerless71    <-> Powerless71,   the2,     NA
> ##D     Education      <-> Education,     the3,     NA
> ##D     SEI            <-> SEI,           the4,     NA
> ##D     Anomia67       <-> Anomia71,      the5,     NA
> ##D     Powerless67    <-> Powerless71,   the5,     NA
> ##D     Alienation67   <-> Alienation67,  psi1,     NA
> ##D     Alienation71   <-> Alienation71,  psi2,     NA
> ##D     SES            <-> SES,           phi,      NA 
> ##D 
> ##D 
> ##D sem.wh.2 <- sem(model.wh.2, S.wh, 932)
> ##D summary(sem.wh.2)
> ##D 
> ##D # And again, in equation format:
> ##D 
> ##D model.wh <- specifyEquations()
> ##D Anomia67 = 1*Alienation67
> ##D Powerless67 = lamby*Alienation67
> ##D Anomia71 = 1*Alienation71
> ##D Powerless71 = lamby*Alienation71
> ##D Education = 1*SES
> ##D SEI = lambx*SES
> ##D Alienation67 = gam1*SES
> ##D Alienation71 = gam2*SES + beta*Alienation67
> ##D V(Anomia67) = the1
> ##D V(Anomia71) = the1
> ##D V(Powerless67) = the2
> ##D V(Powerless71) = the2
> ##D V(SES) = phi
> ##D C(Anomia67, Anomia71) = the5
> ##D C(Powerless67, Powerless71) = the5
> ##D 
> ##D 
> ##D # Compare the two models by a likelihood-ratio test:
> ##D 
> ##D anova(sem.wh.1, sem.wh.2)
> ##D 
> ##D 
> ##D # ----------------------- Thurstone data ---------------------------------------
> ##D #  Second-order confirmatory factor analysis, from the SAS manual for PROC CALIS
> ##D 
> ##D R.thur <- readMoments(diag=FALSE, names=c('Sentences','Vocabulary',
> ##D         'Sent.Completion','First.Letters','4.Letter.Words','Suffixes',
> ##D         'Letter.Series','Pedigrees', 'Letter.Group'))
> ##D     .828                                              
> ##D     .776   .779                                        
> ##D     .439   .493    .46                                 
> ##D     .432   .464    .425   .674                           
> ##D     .447   .489    .443   .59    .541                    
> ##D     .447   .432    .401   .381    .402   .288              
> ##D     .541   .537    .534   .35    .367   .32   .555        
> ##D     .38   .358    .359   .424    .446   .325   .598   .452  
> ##D             
> ##D model.thur <- specifyModel()
> ##D     F1 -> Sentences,                      lam11
> ##D     F1 -> Vocabulary,                     lam21
> ##D     F1 -> Sent.Completion,                lam31
> ##D     F2 -> First.Letters,                  lam42
> ##D     F2 -> 4.Letter.Words,                 lam52
> ##D     F2 -> Suffixes,                       lam62
> ##D     F3 -> Letter.Series,                  lam73
> ##D     F3 -> Pedigrees,                      lam83
> ##D     F3 -> Letter.Group,                   lam93
> ##D     F4 -> F1,                             gam1
> ##D     F4 -> F2,                             gam2
> ##D     F4 -> F3,                             gam3
> ##D     F1 <-> F1,                            NA,     1
> ##D     F2 <-> F2,                            NA,     1
> ##D     F3 <-> F3,                            NA,     1
> ##D     F4 <-> F4,                            NA,     1
> ##D 
> ##D sem.thur <- sem(model.thur, R.thur, 213)
> ##D summary(sem.thur)
> ##D 
> ##D # The model in equation format:
> ##D 
> ##D model.thur <- specifyEquations()
> ##D Sentences = lam11*F1
> ##D Vocabulary = lam21*F1
> ##D Sent.Completion = lam31*F1
> ##D First.Letters = lam42*F2
> ##D 4.Letter.Words = lam52*F2
> ##D Suffixes = lam62*F2
> ##D Letter.Series = lam73*F3
> ##D Pedigrees = lam83*F3
> ##D Letter.Group = lam93*F3
> ##D F1 = gam1*F4
> ##D F2 = gam2*F4
> ##D F3 = gam3*F4
> ##D V(F1) = 1
> ##D V(F2) = 1
> ##D V(F3) = 1
> ##D V(F4) = 1
> ##D 
> ##D 
> ##D #------------------------- Kerchoff/Kenney path analysis ---------------------
> ##D # An observed-variable recursive SEM from the LISREL manual
> ##D 
> ##D R.kerch <- readMoments(diag=FALSE, names=c('Intelligence','Siblings',
> ##D                         'FatherEd','FatherOcc','Grades','EducExp','OccupAsp'))
> ##D     -.100                                
> ##D      .277  -.152                          
> ##D      .250  -.108  .611                     
> ##D      .572  -.105  .294   .248               
> ##D      .489  -.213  .446   .410   .597         
> ##D      .335  -.153  .303   .331   .478   .651   
> ##D     
> ##D model.kerch <- specifyModel()
> ##D     Intelligence -> Grades,       gam51
> ##D     Siblings -> Grades,           gam52
> ##D     FatherEd -> Grades,           gam53
> ##D     FatherOcc -> Grades,          gam54
> ##D     Intelligence -> EducExp,      gam61
> ##D     Siblings -> EducExp,          gam62
> ##D     FatherEd -> EducExp,          gam63
> ##D     FatherOcc -> EducExp,         gam64
> ##D     Grades -> EducExp,            beta65
> ##D     Intelligence -> OccupAsp,     gam71
> ##D     Siblings -> OccupAsp,         gam72
> ##D     FatherEd -> OccupAsp,         gam73
> ##D     FatherOcc -> OccupAsp,        gam74
> ##D     Grades -> OccupAsp,           beta75
> ##D     EducExp -> OccupAsp,          beta76
> ##D                        
> ##D sem.kerch <- sem(model.kerch, R.kerch, 737, 
> ##D     fixed.x=c('Intelligence', 'Siblings', 'FatherEd', 'FatherOcc'))
> ##D summary(sem.kerch)
> ##D 
> ##D # The model in equation format:
> ##D 
> ##D model.kerch <- specifyEquations()
> ##D Grades = gam51*Intelligence + gam52*Siblings + gam53*FatherEd 
> ##D            + gam54*FatherOcc
> ##D EducExp = gam61*Intelligence + gam62*Siblings + gam63*FatherEd 
> ##D             + gam64*FatherOcc + beta65*Grades
> ##D OccupAsp = gam71*Intelligence + gam72*Siblings + gam73*FatherEd 
> ##D             + gam74*FatherOcc + beta75*Grades + beta76*EducExp
> ##D 
> ##D 
> ##D #------------------- McArdle/Epstein latent-growth-curve model -----------------
> ##D # This model, from McArdle and Epstein (1987, p.118), illustrates the use of a 
> ##D # raw moment matrix to fit a model with an intercept. (The example was suggested
> ##D # by Mike Stoolmiller.)
> ##D 
> ##D M.McArdle <- readMoments(
> ##D     names=c('WISC1', 'WISC2', 'WISC3', 'WISC4', 'UNIT'))
> ##D     365.661                                      
> ##D     503.175     719.905                           
> ##D     675.656     958.479    1303.392                
> ##D     890.680    1265.846    1712.475    2278.257     
> ##D      18.034      25.819      35.255      46.593     1.000
> ##D  
> ##D mod.McArdle <- specifyModel()
> ##D     C -> WISC1, NA, 6.07
> ##D     C -> WISC2, B2, NA
> ##D     C -> WISC3, B3, NA
> ##D     C -> WISC4, B4, NA
> ##D     UNIT -> C, Mc, NA
> ##D     C <-> C, Vc, NA,
> ##D     WISC1 <-> WISC1, Vd, NA
> ##D     WISC2 <-> WISC2, Vd, NA
> ##D     WISC3 <-> WISC3, Vd, NA
> ##D     WISC4 <-> WISC4, Vd, NA
> ##D 
> ##D sem.McArdle <- sem(mod.McArdle, M.McArdle, 204, fixed.x="UNIT", raw=TRUE)
> ##D summary(sem.McArdle)
> ##D 
> ##D # The model in equation format:
> ##D 
> ##D mod.McArdle <- specifyEquations()
> ##D WISC1 = 6.07*C
> ##D WISC2 = B2*C
> ##D WISC3 = B3*C
> ##D WISC4 = b4*C
> ##D C = Mc*UNIT
> ##D v(C) = Vc
> ##D v(WISC1) = Vd
> ##D v(WISC2) = Vd
> ##D v(WISC3) = Vd
> ##D v(WISC4) = Vd
> ##D 
> ##D     
> ##D #------------ Bollen industrialization and democracy example -----------------
> ##D # This model, from Bollen (1989, Ch. 8), illustrates the use in sem() of a
> ##D # case-by-variable data (see ?Bollen) set rather than a covariance or moment matrix
> ##D 
> ##D model.bollen <- specifyModel()
> ##D 	Demo60 -> y1, NA, 1
> ##D 	Demo60 -> y2, lam2, 
> ##D 	Demo60 -> y3, lam3, 
> ##D 	Demo60 -> y4, lam4, 
> ##D 	Demo65 -> y5, NA, 1
> ##D 	Demo65 -> y6, lam2, 
> ##D 	Demo65 -> y7, lam3, 
> ##D 	Demo65 -> y8, lam4, 
> ##D 	Indust -> x1, NA, 1
> ##D 	Indust -> x2, lam6, 
> ##D 	Indust -> x3, lam7, 
> ##D 	y1 <-> y5, theta15
> ##D 	y2 <-> y4, theta24
> ##D 	y2 <-> y6, theta26
> ##D 	y3 <-> y7, theta37
> ##D 	y4 <-> y8, theta48
> ##D 	y6 <-> y8, theta68
> ##D 	Indust -> Demo60, gamma11, 
> ##D 	Indust -> Demo65, gamma21, 
> ##D 	Demo60 -> Demo65, beta21, 
> ##D 	Indust <-> Indust, phi
> ##D 	
> ##D sem.bollen <- sem(model.bollen, data=Bollen)
> ##D summary(sem.bollen)
> ##D summary(sem.bollen, robust=TRUE) # robust SEs and tests
> ##D summary(sem.bollen, analytic.se=FALSE) # uses numeric rather than analytic Hessian
> ##D 
> ##D   # GLS rather than ML estimator:
> ##D sem.bollen.gls <- sem(model.bollen, data=Bollen, objective=objectiveGLS) 
> ##D summary(sem.bollen.gls)
> ##D 
> ##D # The model in equation format:
> ##D 
> ##D model.bollen <- specifyEquations()
> ##D y1 = 1*Demo60
> ##D y2 = lam2*Demo60
> ##D y3 = lam3*Demo60
> ##D y4 = lam4*Demo60
> ##D y5 = 1*Demo65
> ##D y6 = lam2*Demo65
> ##D y7 = lam3*Demo65
> ##D y8 = lam4*Demo65
> ##D x1 = 1*Indust
> ##D x2 = lam6*Indust
> ##D x3 = lam7*Indust
> ##D c(y1, y5) = theta15
> ##D c(y2, y4) = theta24
> ##D c(y2, y6) = theta26
> ##D c(y3, y7) = theta37
> ##D c(y4, y8) = theta48
> ##D c(y6, y8) = theta68
> ##D Demo60 = gamma11*Indust
> ##D Demo65 = gamma21*Indust + beta21*Demo60
> ##D v(Indust) = phi
> ##D 
> ##D 
> ##D # -------------- A simple CFA model for the Thurstone mental tests data --------------
> ##D 
> ##D R.thur <- readMoments(diag=FALSE, 
> ##D   names=c('Sentences','Vocabulary',
> ##D           'Sent.Completion','First.Letters','4.Letter.Words','Suffixes',
> ##D           'Letter.Series','Pedigrees', 'Letter.Group'))
> ##D .828                                              
> ##D .776   .779                                        
> ##D .439   .493    .46                                 
> ##D .432   .464    .425   .674                           
> ##D .447   .489    .443   .59    .541                    
> ##D .447   .432    .401   .381    .402   .288              
> ##D .541   .537    .534   .35    .367   .32   .555        
> ##D .38   .358    .359   .424    .446   .325   .598   .452
> ##D 
> ##D 	#  (1) in CFA format:
> ##D 
> ##D mod.cfa.thur.c <- cfa(reference.indicators=FALSE)
> ##D FA: Sentences, Vocabulary, Sent.Completion
> ##D FB: First.Letters, 4.Letter.Words, Suffixes
> ##D FC: Letter.Series, Pedigrees, Letter.Group
> ##D 
> ##D cfa.thur.c <- sem(mod.cfa.thur.c, R.thur, 213)
> ##D summary(cfa.thur.c)
> ##D 
> ##D 	#  (2) in equation format:
> ##D 
> ##D mod.cfa.thur.e <- specifyEquations(covs="F1, F2, F3")
> ##D Sentences = lam11*F1
> ##D Vocabulary = lam21*F1
> ##D Sent.Completion = lam31*F1
> ##D First.Letters = lam42*F2
> ##D 4.Letter.Words = lam52*F2
> ##D Suffixes = lam62*F2
> ##D Letter.Series = lam73*F3
> ##D Pedigrees = lam83*F3
> ##D Letter.Group = lam93*F3
> ##D V(F1) = 1
> ##D V(F2) = 1
> ##D V(F3) = 1
> ##D 
> ##D cfa.thur.e <- sem(mod.cfa.thur.e, R.thur, 213)
> ##D summary(cfa.thur.e)
> ##D 
> ##D 	#  (3) in path format:
> ##D 
> ##D mod.cfa.thur.p <- specifyModel(covs="F1, F2, F3")
> ##D F1 -> Sentences,                      lam11
> ##D F1 -> Vocabulary,                     lam21
> ##D F1 -> Sent.Completion,                lam31
> ##D F2 -> First.Letters,                  lam41
> ##D F2 -> 4.Letter.Words,                 lam52
> ##D F2 -> Suffixes,                       lam62
> ##D F3 -> Letter.Series,                  lam73
> ##D F3 -> Pedigrees,                      lam83
> ##D F3 -> Letter.Group,                   lam93
> ##D F1 <-> F1,                            NA,     1
> ##D F2 <-> F2,                            NA,     1
> ##D F3 <-> F3,                            NA,     1
> ##D 
> ##D cfa.thur.p <- sem(mod.cfa.thur.p, R.thur, 213)
> ##D summary(cfa.thur.p)
> ##D 
> ##D # -----  a CFA model fit by FIML to the mental-tests dataset with missing data -----
> ##D 
> ##D mod.cfa.tests <- cfa(raw=TRUE)
> ##D verbal: x1, x2, x3
> ##D math: y1, y2, y3
> ##D 
> ##D cfa.tests <- sem(mod.cfa.tests, data=Tests, na.action=na.pass, 
> ##D                 objective=objectiveFIML, fixed.x="Intercept")
> ##D summary(cfa.tests)
> ##D summary(cfa.tests, saturated=TRUE) # takes time to fit saturated model for comparison
> ##D 
> ##D 
> ##D # ---  a multigroup CFA model fit to the Holzinger-Swineford mental-tests data  -----
> ##D 
> ##D library(MBESS) # for data
> ##D data(HS.data)
> ##D 
> ##D mod.hs <- cfa()
> ##D spatial: visual, cubes, paper, flags
> ##D verbal: general, paragrap, sentence, wordc, wordm
> ##D memory: wordr, numberr, figurer, object, numberf, figurew
> ##D math: deduct, numeric, problemr, series, arithmet
> ##D 
> ##D mod.mg <- multigroupModel(mod.hs, groups=c("Female", "Male")) 
> ##D 
> ##D sem.mg <- sem(mod.mg, data=HS.data, group="Gender",
> ##D               formula = ~ visual + cubes + paper + flags +
> ##D               general + paragrap + sentence + wordc + wordm +
> ##D               wordr + numberr + figurer + object + numberf + figurew +
> ##D               deduct + numeric + problemr + series + arithmet
> ##D               )
> ##D summary(sem.mg)
> ##D 
> ##D 	# with cross-group equality constraints:
> ##D 	
> ##D mod.mg.eq <- multigroupModel(mod.hs, groups=c("Female", "Male"), allEqual=TRUE)
> ##D 
> ##D sem.mg.eq <- sem(mod.mg.eq, data=HS.data, group="Gender",
> ##D               formula = ~ visual + cubes + paper + flags +
> ##D                 general + paragrap + sentence + wordc + wordm +
> ##D                 wordr + numberr + figurer + object + numberf + figurew +
> ##D                 deduct + numeric + problemr + series + arithmet
> ##D               )
> ##D summary(sem.mg.eq)
> ##D 
> ##D anova(sem.mg, sem.mg.eq) # test equality constraints
> ##D 	
> ## End(Not run)
> 
> ## ===============================================================================
> 	
> # The following examples use file input and may be executed via example():
> 
> etc <- system.file(package="sem", "etc") # path to data and model files
> 
> #   to get all fit indices (not recommended, but for illustration):
> 
> opt <- options(fit.indices = c("GFI", "AGFI", "RMSEA", "NFI", "NNFI", 
+          "CFI", "RNI", "IFI", "SRMR", "AIC", "AICc", "BIC", "CAIC"))
> 
> # ------------- Duncan, Haller and Portes peer-influences model ----------------------
> # A nonrecursive SEM with unobserved endogenous variables and fixed exogenous variables
> 
> (R.DHP <- readMoments(file=file.path(etc, "R-DHP.txt"),
+ 				diag=FALSE, names=c("ROccAsp", "REdAsp", "FOccAsp", 
+                 "FEdAsp", "RParAsp", "RIQ", "RSES", "FSES", "FIQ", "FParAsp")))
Read 45 items
        ROccAsp REdAsp FOccAsp FEdAsp RParAsp    RIQ   RSES    FSES    FIQ
ROccAsp  1.0000 0.0000  0.0000 0.0000  0.0000 0.0000 0.0000  0.0000 0.0000
REdAsp   0.6247 1.0000  0.0000 0.0000  0.0000 0.0000 0.0000  0.0000 0.0000
FOccAsp  0.3269 0.3669  1.0000 0.0000  0.0000 0.0000 0.0000  0.0000 0.0000
FEdAsp   0.4216 0.3275  0.6404 1.0000  0.0000 0.0000 0.0000  0.0000 0.0000
RParAsp  0.2137 0.2742  0.1124 0.0839  1.0000 0.0000 0.0000  0.0000 0.0000
RIQ      0.4105 0.4043  0.2903 0.2598  0.1839 1.0000 0.0000  0.0000 0.0000
RSES     0.3240 0.4047  0.3054 0.2786  0.0489 0.2220 1.0000  0.0000 0.0000
FSES     0.2930 0.2407  0.4105 0.3607  0.0186 0.1861 0.2707  1.0000 0.0000
FIQ      0.2995 0.2863  0.5191 0.5007  0.0782 0.3355 0.2302  0.2950 1.0000
FParAsp  0.0760 0.0702  0.2784 0.1988  0.1147 0.1021 0.0931 -0.0438 0.2087
        FParAsp
ROccAsp       0
REdAsp        0
FOccAsp       0
FEdAsp        0
RParAsp       0
RIQ           0
RSES          0
FSES          0
FIQ           0
FParAsp       1
> (model.dhp <- specifyModel(file=file.path(etc, "model-DHP.txt")))
Read 15 records
NOTE: it is generally simpler to use specifyEquations() or cfa()
      see ?specifyEquations
NOTE: adding 6 variances to the model
   Path                Parameter  StartValue
1  RParAsp  -> RGenAsp gam11                
2  RIQ      -> RGenAsp gam12                
3  RSES     -> RGenAsp gam13                
4  FSES     -> RGenAsp gam14                
5  RSES     -> FGenAsp gam23                
6  FSES     -> FGenAsp gam24                
7  FIQ      -> FGenAsp gam25                
8  FParAsp  -> FGenAsp gam26                
9  FGenAsp  -> RGenAsp beta12               
10 RGenAsp  -> FGenAsp beta21               
11 RGenAsp  -> ROccAsp <fixed>    1         
12 RGenAsp  -> REdAsp  lam21                
13 FGenAsp  -> FOccAsp <fixed>    1         
14 FGenAsp  -> FEdAsp  lam42                
15 RGenAsp <-> FGenAsp ps12                 
16 RGenAsp <-> RGenAsp V[RGenAsp]           
17 FGenAsp <-> FGenAsp V[FGenAsp]           
18 ROccAsp <-> ROccAsp V[ROccAsp]           
19 REdAsp <-> REdAsp   V[REdAsp]            
20 FOccAsp <-> FOccAsp V[FOccAsp]           
21 FEdAsp <-> FEdAsp   V[FEdAsp]            
> sem.dhp.1 <- sem(model.dhp, R.DHP, 329,
+     fixed.x=c('RParAsp', 'RIQ', 'RSES', 'FSES', 'FIQ', 'FParAsp'))
> summary(sem.dhp.1)

 Model Chisquare =  26.69722   Df =  15 Pr(>Chisq) = 0.03130238
 Goodness-of-fit index =  0.984387
 Adjusted goodness-of-fit index =  0.9427525
 RMSEA index =  0.04875944   90% CI: (0.01451664, 0.07830923)
 Bentler-Bonett NFI =  0.969384
 Tucker-Lewis NNFI =  0.9575676
 Bentler CFI =  0.9858559
 Bentler RNI =  0.9858559
 Bollen IFI =  0.986351
 SRMR =  0.02020441
 AIC =  64.69722
 AICc =  29.15676
 BIC =  -60.24365
 CAIC =  -75.24365

 Normalized Residuals
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-0.79953 -0.11783  0.00000 -0.01201  0.03974  1.56525 

 R-square for Endogenous Variables
RGenAsp FGenAsp ROccAsp  REdAsp FOccAsp  FEdAsp 
 0.5220  0.6170  0.5879  0.6639  0.6888  0.5954 

 Parameter Estimates
           Estimate    Std Error  z value    Pr(>|z|)                         
gam11       0.16122243 0.03879229  4.1560429 3.238070e-05 RGenAsp <--- RParAsp
gam12       0.24964929 0.04398092  5.6763087 1.376323e-08 RGenAsp <--- RIQ    
gam13       0.21840307 0.04419737  4.9415399 7.750795e-07 RGenAsp <--- RSES   
gam14       0.07183948 0.04970692  1.4452610 1.483846e-01 RGenAsp <--- FSES   
gam23       0.06188722 0.05171967  1.1965895 2.314666e-01 FGenAsp <--- RSES   
gam24       0.22886655 0.04416219  5.1824090 2.190383e-07 FGenAsp <--- FSES   
gam25       0.34903584 0.04528981  7.7067195 1.290931e-14 FGenAsp <--- FIQ    
gam26       0.15953378 0.03882594  4.1089486 3.974645e-05 FGenAsp <--- FParAsp
beta12      0.18423260 0.09488782  1.9415832 5.218758e-02 RGenAsp <--- FGenAsp
beta21      0.23547774 0.11938936  1.9723511 4.856954e-02 FGenAsp <--- RGenAsp
lam21       1.06267796 0.09013868 11.7893663 4.428606e-32 REdAsp <--- RGenAsp 
lam42       0.92972549 0.07028107 13.2286762 5.993366e-40 FEdAsp <--- FGenAsp 
ps12       -0.02260953 0.05119394 -0.4416447 6.587463e-01 FGenAsp <--> RGenAsp
V[RGenAsp]  0.28098701 0.04623153  6.0778220 1.218259e-09 RGenAsp <--> RGenAsp
V[FGenAsp]  0.26383553 0.04466689  5.9067359 3.489525e-09 FGenAsp <--> FGenAsp
V[ROccAsp]  0.41214545 0.05122465  8.0458422 8.565431e-16 ROccAsp <--> ROccAsp
V[REdAsp]   0.33614511 0.05209992  6.4519310 1.104339e-10 REdAsp <--> REdAsp  
V[FOccAsp]  0.31119482 0.04592713  6.7758385 1.236867e-11 FOccAsp <--> FOccAsp
V[FEdAsp]   0.40460363 0.04618437  8.7606177 1.941833e-18 FEdAsp <--> FEdAsp  

 Iterations =  32 
> 
> 
> # -------------------- Wheaton et al. alienation data ----------------------
> 
> (S.wh <- readMoments(file=file.path(etc, "S-Wheaton.txt"),
+ 					names=c('Anomia67','Powerless67','Anomia71',
+                             'Powerless71','Education','SEI')))
Read 21 items
            Anomia67 Powerless67 Anomia71 Powerless71 Education     SEI
Anomia67      11.834       0.000    0.000       0.000     0.000   0.000
Powerless67    6.947       9.364    0.000       0.000     0.000   0.000
Anomia71       6.819       5.091   12.532       0.000     0.000   0.000
Powerless71    4.783       5.028    7.495       9.986     0.000   0.000
Education     -3.839      -3.889   -3.841      -3.625     9.610   0.000
SEI          -21.899     -18.831  -21.748     -18.775    35.522 450.288
> 
> # This is the model in the SAS manual for PROC CALIS: A Recursive SEM with
> # latent endogenous and exogenous variables.
> # Curiously, both factor loadings for two of the latent variables are fixed.
> 
> (model.wh.1 <- specifyModel(file=file.path(etc, "model-Wheaton-1.txt")))                    
Read 20 records
NOTE: it is generally simpler to use specifyEquations() or cfa()
      see ?specifyEquations
   Path                            Parameter StartValue
1  Alienation67   ->  Anomia67     <fixed>   1         
2  Alienation67   ->  Powerless67  <fixed>   0.833     
3  Alienation71   ->  Anomia71     <fixed>   1         
4  Alienation71   ->  Powerless71  <fixed>   0.833     
5  SES            ->  Education    <fixed>   1         
6  SES            ->  SEI          lamb                
7  SES            ->  Alienation67 gam1                
8  Alienation67   ->  Alienation71 beta                
9  SES            ->  Alienation71 gam2                
10 Anomia67       <-> Anomia67     the1                
11 Anomia71       <-> Anomia71     the1                
12 Powerless67    <-> Powerless67  the2                
13 Powerless71    <-> Powerless71  the2                
14 Education      <-> Education    the3                
15 SEI            <-> SEI          the4                
16 Anomia67       <-> Anomia71     the5                
17 Powerless67    <-> Powerless71  the5                
18 Alienation67   <-> Alienation67 psi1                
19 Alienation71   <-> Alienation71 psi2                
20 SES            <-> SES          phi                 
> sem.wh.1 <- sem(model.wh.1, S.wh, 932)
> summary(sem.wh.1)

 Model Chisquare =  13.48505   Df =  9 Pr(>Chisq) = 0.1418581
 Goodness-of-fit index =  0.9952676
 Adjusted goodness-of-fit index =  0.9889578
 RMSEA index =  0.02313597   90% CI: (NA, 0.04699697)
 Bentler-Bonett NFI =  0.9936732
 Tucker-Lewis NNFI =  0.9964681
 Bentler CFI =  0.9978808
 Bentler RNI =  0.9978808
 Bollen IFI =  0.9978868
 SRMR =  0.01499777
 AIC =  37.48505
 AICc =  13.82455
 BIC =  -48.05094
 CAIC =  -57.05094

 Normalized Residuals
      Min.    1st Qu.     Median       Mean    3rd Qu.       Max. 
-1.2607533 -0.1307997  0.0000074 -0.0286693  0.1136786  0.8742272 

 R-square for Endogenous Variables
Alienation67     Anomia67  Powerless67 Alienation71     Anomia71  Powerless71 
      0.3165       0.6969       0.6156       0.4988       0.7140       0.6349 
   Education          SEI 
      0.6885       0.4235 

 Parameter Estimates
     Estimate    Std Error   z value    Pr(>|z|)     
lamb   5.3688665  0.43371377  12.378824  3.402917e-35
gam1  -0.6299440  0.05634103 -11.180910  5.056855e-29
beta   0.5931117  0.04677973  12.678819  7.749076e-37
gam2  -0.2408634  0.05488533  -4.388483  1.141438e-05
the1   3.6078615  0.20091855  17.956837  4.243095e-72
the2   3.5949414  0.16448404  21.855867 6.836095e-106
the3   2.9937043  0.49860940   6.004107  1.923876e-09
the4 259.5750846 18.31151887  14.175508  1.298995e-45
the5   0.9057998  0.12167000   7.444726  9.714559e-14
psi1   5.6704863  0.42301086  13.405061  5.647691e-41
psi2   4.5147952  0.33532398  13.463980  2.548139e-41
phi    6.6162908  0.63913887  10.351883  4.103350e-25
                                   
lamb SEI <--- SES                  
gam1 Alienation67 <--- SES         
beta Alienation71 <--- Alienation67
gam2 Alienation71 <--- SES         
the1 Anomia67 <--> Anomia67        
the2 Powerless67 <--> Powerless67  
the3 Education <--> Education      
the4 SEI <--> SEI                  
the5 Anomia71 <--> Anomia67        
psi1 Alienation67 <--> Alienation67
psi2 Alienation71 <--> Alienation71
phi  SES <--> SES                  

 Iterations =  80 
> 
> # The same model, but treating one loading for each latent variable as free
> # (and equal to each other).
> 
> (model.wh.2 <- specifyModel(file=file.path(etc, "model-Wheaton-2.txt")))
Read 20 records
NOTE: it is generally simpler to use specifyEquations() or cfa()
      see ?specifyEquations
   Path                            Parameter StartValue
1  Alienation67   ->  Anomia67     <fixed>   1         
2  Alienation67   ->  Powerless67  lamby               
3  Alienation71   ->  Anomia71     <fixed>   1         
4  Alienation71   ->  Powerless71  lamby               
5  SES            ->  Education    <fixed>   1         
6  SES            ->  SEI          lambx               
7  SES            ->  Alienation67 gam1                
8  Alienation67   ->  Alienation71 beta                
9  SES            ->  Alienation71 gam2                
10 Anomia67       <-> Anomia67     the1                
11 Anomia71       <-> Anomia71     the1                
12 Powerless67    <-> Powerless67  the2                
13 Powerless71    <-> Powerless71  the2                
14 Education      <-> Education    the3                
15 SEI            <-> SEI          the4                
16 Anomia67       <-> Anomia71     the5                
17 Powerless67    <-> Powerless71  the5                
18 Alienation67   <-> Alienation67 psi1                
19 Alienation71   <-> Alienation71 psi2                
20 SES            <-> SES          phi                 
> sem.wh.2 <- sem(model.wh.2, S.wh, 932)
> summary(sem.wh.2)

 Model Chisquare =  12.67312   Df =  8 Pr(>Chisq) = 0.1236024
 Goodness-of-fit index =  0.9955336
 Adjusted goodness-of-fit index =  0.9882758
 RMSEA index =  0.02504861   90% CI: (NA, 0.04985045)
 Bentler-Bonett NFI =  0.9940542
 Tucker-Lewis NNFI =  0.99586
 Bentler CFI =  0.997792
 Bentler RNI =  0.997792
 Bollen IFI =  0.9977993
 SRMR =  0.01298098
 AIC =  38.67312
 AICc =  13.06964
 BIC =  -42.02554
 CAIC =  -50.02554

 Normalized Residuals
      Min.    1st Qu.     Median       Mean    3rd Qu.       Max. 
-0.9967121 -0.1395485  0.0000016 -0.0287011  0.1001799  0.7588994 

 R-square for Endogenous Variables
Alienation67     Anomia67  Powerless67 Alienation71     Anomia71  Powerless71 
      0.3188       0.6821       0.6312       0.4999       0.6997       0.6502 
   Education          SEI 
      0.6905       0.4223 

 Parameter Estimates
      Estimate    Std Error   z value    Pr(>|z|)     
lamby   0.8626118  0.03319330  25.987525 6.852235e-149
lambx   5.3530643  0.43194788  12.392848  2.857137e-35
gam1   -0.6212954  0.05644272 -11.007538  3.514771e-28
beta    0.5942703  0.04703213  12.635412  1.346866e-36
gam2   -0.2358101  0.05436083  -4.337869  1.438711e-05
the1    3.7449867  0.24835569  15.079126  2.221915e-51
the2    3.4937978  0.19935463  17.525541  9.146767e-69
the3    2.9741747  0.49881095   5.962529  2.483637e-09
the4  260.1364736 18.27773152  14.232427  5.764614e-46
the5    0.9037858  0.12166283   7.428611  1.097442e-13
psi1    5.4737323  0.45711672  11.974474  4.834942e-33
psi2    4.3640660  0.36736560  11.879354  1.515339e-32
phi     6.6358246  0.63968778  10.373537  3.271868e-25
                                    
lamby Powerless67 <--- Alienation67 
lambx SEI <--- SES                  
gam1  Alienation67 <--- SES         
beta  Alienation71 <--- Alienation67
gam2  Alienation71 <--- SES         
the1  Anomia67 <--> Anomia67        
the2  Powerless67 <--> Powerless67  
the3  Education <--> Education      
the4  SEI <--> SEI                  
the5  Anomia71 <--> Anomia67        
psi1  Alienation67 <--> Alienation67
psi2  Alienation71 <--> Alienation71
phi   SES <--> SES                  

 Iterations =  81 
> 
> # Compare the two models by a likelihood-ratio test:
> 
> anova(sem.wh.1, sem.wh.2)
LR Test for Difference Between Models

         Model Df Model Chisq Df LR Chisq Pr(>Chisq)
sem.wh.1        9      13.485                       
sem.wh.2        8      12.673  1  0.81193     0.3676
> 
> 
> # ----------------------- Thurstone data ---------------------------------------
> 
> #  Second-order confirmatory factor analysis, from the SAS manual for PROC CALIS
> 
> (R.thur <- readMoments(file=file.path(etc, "R-Thurstone.txt"),
+ 		diag=FALSE, names=c('Sentences','Vocabulary',
+         'Sent.Completion','First.Letters','4.Letter.Words','Suffixes',
+         'Letter.Series','Pedigrees', 'Letter.Group')))
Read 36 items
                Sentences Vocabulary Sent.Completion First.Letters
Sentences           1.000      0.000           0.000         0.000
Vocabulary          0.828      1.000           0.000         0.000
Sent.Completion     0.776      0.779           1.000         0.000
First.Letters       0.439      0.493           0.460         1.000
4.Letter.Words      0.432      0.464           0.425         0.674
Suffixes            0.447      0.489           0.443         0.590
Letter.Series       0.447      0.432           0.401         0.381
Pedigrees           0.541      0.537           0.534         0.350
Letter.Group        0.380      0.358           0.359         0.424
                4.Letter.Words Suffixes Letter.Series Pedigrees Letter.Group
Sentences                0.000    0.000         0.000     0.000            0
Vocabulary               0.000    0.000         0.000     0.000            0
Sent.Completion          0.000    0.000         0.000     0.000            0
First.Letters            0.000    0.000         0.000     0.000            0
4.Letter.Words           1.000    0.000         0.000     0.000            0
Suffixes                 0.541    1.000         0.000     0.000            0
Letter.Series            0.402    0.288         1.000     0.000            0
Pedigrees                0.367    0.320         0.555     1.000            0
Letter.Group             0.446    0.325         0.598     0.452            1
> (model.thur <- specifyModel(file=file.path(etc, "model-Thurstone.txt")))
Read 16 records
NOTE: it is generally simpler to use specifyEquations() or cfa()
      see ?specifyEquations
NOTE: adding 9 variances to the model
   Path                                Parameter          StartValue
1  F1 -> Sentences                     lam11                        
2  F1 -> Vocabulary                    lam21                        
3  F1 -> Sent.Completion               lam31                        
4  F2 -> First.Letters                 lam42                        
5  F2 -> 4.Letter.Words                lam52                        
6  F2 -> Suffixes                      lam62                        
7  F3 -> Letter.Series                 lam73                        
8  F3 -> Pedigrees                     lam83                        
9  F3 -> Letter.Group                  lam93                        
10 F4 -> F1                            gam1                         
11 F4 -> F2                            gam2                         
12 F4 -> F3                            gam3                         
13 F1 <-> F1                           <fixed>            1         
14 F2 <-> F2                           <fixed>            1         
15 F3 <-> F3                           <fixed>            1         
16 F4 <-> F4                           <fixed>            1         
17 Sentences <-> Sentences             V[Sentences]                 
18 Vocabulary <-> Vocabulary           V[Vocabulary]                
19 Sent.Completion <-> Sent.Completion V[Sent.Completion]           
20 First.Letters <-> First.Letters     V[First.Letters]             
21 4.Letter.Words <-> 4.Letter.Words   V[4.Letter.Words]            
22 Suffixes <-> Suffixes               V[Suffixes]                  
23 Letter.Series <-> Letter.Series     V[Letter.Series]             
24 Pedigrees <-> Pedigrees             V[Pedigrees]                 
25 Letter.Group <-> Letter.Group       V[Letter.Group]              
> sem.thur <- sem(model.thur, R.thur, 213)
> summary(sem.thur)

 Model Chisquare =  38.1963   Df =  24 Pr(>Chisq) = 0.03310059
 Goodness-of-fit index =  0.9595704
 Adjusted goodness-of-fit index =  0.9241945
 RMSEA index =  0.0528219   90% CI: (0.01526173, 0.08306706)
 Bentler-Bonett NFI =  0.9653357
 Tucker-Lewis NNFI =  0.980022
 Bentler CFI =  0.9866813
 Bentler RNI =  0.9866813
 Bollen IFI =  0.9868296
 SRMR =  0.04359517
 AIC =  80.1963
 AICc =  43.03399
 BIC =  -90.47471
 CAIC =  -114.4747

 Normalized Residuals
      Min.    1st Qu.     Median       Mean    3rd Qu.       Max. 
-0.9724643 -0.4164672 -0.0000004  0.0401007  0.0938587  1.6274665 

 R-square for Endogenous Variables
             F1       Sentences      Vocabulary Sent.Completion              F2 
         0.6758          0.8185          0.8351          0.7329          0.6112 
  First.Letters  4.Letter.Words        Suffixes              F3   Letter.Series 
         0.6985          0.6355          0.4936          0.6642          0.6097 
      Pedigrees    Letter.Group 
         0.5186          0.4949 

 Parameter Estimates
                   Estimate  Std Error  z value  Pr(>|z|)    
lam11              0.5151232 0.06292247 8.186634 2.686339e-16
lam21              0.5203104 0.06338431 8.208821 2.233703e-16
lam31              0.4874317 0.06081527 8.014955 1.101771e-15
lam42              0.5211221 0.06106205 8.534304 1.410019e-17
lam52              0.4970664 0.05902388 8.421446 3.718671e-17
lam62              0.4380643 0.05595794 7.828457 4.938925e-15
lam73              0.4524351 0.06596903 6.858296 6.968684e-12
lam83              0.4172903 0.06215816 6.713363 1.901896e-11
lam93              0.4076312 0.06131399 6.648257 2.965833e-11
gam1               1.4438113 0.25653557 5.628113 1.821914e-08
gam2               1.2538297 0.21136564 5.932041 2.991913e-09
gam3               1.4065518 0.26890809 5.230604 1.689567e-07
V[Sentences]       0.1814979 0.02847741 6.373397 1.848862e-10
V[Vocabulary]      0.1649305 0.02776938 5.939292 2.862550e-09
V[Sent.Completion] 0.2671331 0.03336340 8.006770 1.177601e-15
V[First.Letters]   0.3015024 0.05102191 5.909275 3.436176e-09
V[4.Letter.Words]  0.3645010 0.05263547 6.925008 4.359519e-12
V[Suffixes]        0.5064150 0.05962608 8.493180 2.010593e-17
V[Letter.Series]   0.3903313 0.05933649 6.578268 4.759605e-11
V[Pedigrees]       0.4813697 0.06224844 7.733041 1.050075e-14
V[Letter.Group]    0.5051017 0.06332869 7.975875 1.513055e-15
                                                       
lam11              Sentences <--- F1                   
lam21              Vocabulary <--- F1                  
lam31              Sent.Completion <--- F1             
lam42              First.Letters <--- F2               
lam52              4.Letter.Words <--- F2              
lam62              Suffixes <--- F2                    
lam73              Letter.Series <--- F3               
lam83              Pedigrees <--- F3                   
lam93              Letter.Group <--- F3                
gam1               F1 <--- F4                          
gam2               F2 <--- F4                          
gam3               F3 <--- F4                          
V[Sentences]       Sentences <--> Sentences            
V[Vocabulary]      Vocabulary <--> Vocabulary          
V[Sent.Completion] Sent.Completion <--> Sent.Completion
V[First.Letters]   First.Letters <--> First.Letters    
V[4.Letter.Words]  4.Letter.Words <--> 4.Letter.Words  
V[Suffixes]        Suffixes <--> Suffixes              
V[Letter.Series]   Letter.Series <--> Letter.Series    
V[Pedigrees]       Pedigrees <--> Pedigrees            
V[Letter.Group]    Letter.Group <--> Letter.Group      

 Iterations =  54 
> 
> 
> #------------------------- Kerchoff/Kenney path analysis ---------------------
> 
> # An observed-variable recursive SEM from the LISREL manual
> 
> (R.kerch <- readMoments(file=file.path(etc, "R-Kerchoff.txt"),
+ 					   diag=FALSE, names=c('Intelligence','Siblings',
+                         'FatherEd','FatherOcc','Grades','EducExp','OccupAsp')))
Read 21 items
             Intelligence Siblings FatherEd FatherOcc Grades EducExp OccupAsp
Intelligence        1.000    0.000    0.000     0.000  0.000   0.000        0
Siblings           -0.100    1.000    0.000     0.000  0.000   0.000        0
FatherEd            0.277   -0.152    1.000     0.000  0.000   0.000        0
FatherOcc           0.250   -0.108    0.611     1.000  0.000   0.000        0
Grades              0.572   -0.105    0.294     0.248  1.000   0.000        0
EducExp             0.489   -0.213    0.446     0.410  0.597   1.000        0
OccupAsp            0.335   -0.153    0.303     0.331  0.478   0.651        1
> (model.kerch <- specifyModel(file=file.path(etc, "model-Kerchoff.txt")))
Read 15 records
NOTE: it is generally simpler to use specifyEquations() or cfa()
      see ?specifyEquations
NOTE: adding 3 variances to the model
   Path                     Parameter  
1  Intelligence -> Grades   gam51      
2  Siblings -> Grades       gam52      
3  FatherEd -> Grades       gam53      
4  FatherOcc -> Grades      gam54      
5  Intelligence -> EducExp  gam61      
6  Siblings -> EducExp      gam62      
7  FatherEd -> EducExp      gam63      
8  FatherOcc -> EducExp     gam64      
9  Grades -> EducExp        beta65     
10 Intelligence -> OccupAsp gam71      
11 Siblings -> OccupAsp     gam72      
12 FatherEd -> OccupAsp     gam73      
13 FatherOcc -> OccupAsp    gam74      
14 Grades -> OccupAsp       beta75     
15 EducExp -> OccupAsp      beta76     
16 Grades <-> Grades        V[Grades]  
17 EducExp <-> EducExp      V[EducExp] 
18 OccupAsp <-> OccupAsp    V[OccupAsp]
> sem.kerch <- sem(model.kerch, R.kerch, 737, 
+     fixed.x=c('Intelligence', 'Siblings', 'FatherEd', 'FatherOcc'))
> summary(sem.kerch)

 Model Chisquare =  3.268497e-13   Df =  0 Pr(>Chisq) = NA
 Goodness-of-fit index =  1
 AIC =  36
 AICc =  0.9526462
 BIC =  3.268497e-13
 CAIC =  3.268497e-13

 Normalized Residuals
      Min.    1st Qu.     Median       Mean    3rd Qu.       Max. 
-4.260e-15 -1.353e-15  0.000e+00 -4.165e-16  0.000e+00  1.489e-15 

 R-square for Endogenous Variables
  Grades  EducExp OccupAsp 
  0.3490   0.4833   0.4434 

 Parameter Estimates
            Estimate    Std Error  z value    Pr(>|z|)    
gam51        0.52590159 0.03118246 16.8653024 8.098654e-64
gam52       -0.02994194 0.03014885 -0.9931372 3.206431e-01
gam53        0.11896579 0.03825870  3.1095091 1.873985e-03
gam54        0.04060278 0.03778549  1.0745600 2.825718e-01
gam61        0.16027014 0.03270960  4.8997887 9.593979e-07
gam62       -0.11177892 0.02687645 -4.1589908 3.196568e-05
gam63        0.17271933 0.03430638  5.0346130 4.788150e-07
gam64        0.15185163 0.03368805  4.5075812 6.557084e-06
beta65       0.40515000 0.03283761 12.3379874 5.655187e-35
gam71       -0.03940453 0.03450042 -1.1421463 2.533932e-01
gam72       -0.01882452 0.02822248 -0.6670047 5.047692e-01
gam73       -0.04133251 0.03621648 -1.1412624 2.537607e-01
gam74        0.09957670 0.03544608  2.8092444 4.965793e-03
beta75       0.15791229 0.03744323  4.2173792 2.471582e-05
beta76       0.54959341 0.03825956 14.3648632 8.597634e-47
V[Grades]    0.65099496 0.03393546 19.1833261 5.101046e-82
V[EducExp]   0.51665245 0.02693237 19.1833261 5.101046e-82
V[OccupAsp]  0.55661685 0.02901566 19.1833261 5.101046e-82
                                      
gam51       Grades <--- Intelligence  
gam52       Grades <--- Siblings      
gam53       Grades <--- FatherEd      
gam54       Grades <--- FatherOcc     
gam61       EducExp <--- Intelligence 
gam62       EducExp <--- Siblings     
gam63       EducExp <--- FatherEd     
gam64       EducExp <--- FatherOcc    
beta65      EducExp <--- Grades       
gam71       OccupAsp <--- Intelligence
gam72       OccupAsp <--- Siblings    
gam73       OccupAsp <--- FatherEd    
gam74       OccupAsp <--- FatherOcc   
beta75      OccupAsp <--- Grades      
beta76      OccupAsp <--- EducExp     
V[Grades]   Grades <--> Grades        
V[EducExp]  EducExp <--> EducExp      
V[OccupAsp] OccupAsp <--> OccupAsp    

 Iterations =  0 
> 
> 
> #------------------- McArdle/Epstein latent-growth-curve model -----------------
> 
> # This model, from McArdle and Epstein (1987, p.118), illustrates the use of a 
> # raw moment matrix to fit a model with an intercept. (The example was suggested
> # by Mike Stoolmiller.)
> 
> (M.McArdle <- readMoments(file=file.path(etc, "M-McArdle.txt"),
+     names=c('WISC1', 'WISC2', 'WISC3', 'WISC4', 'UNIT')))
Read 15 items
        WISC1    WISC2    WISC3    WISC4 UNIT
WISC1 365.661    0.000    0.000    0.000    0
WISC2 503.175  719.905    0.000    0.000    0
WISC3 675.656  958.479 1303.392    0.000    0
WISC4 890.680 1265.846 1712.475 2278.257    0
UNIT   18.034   25.819   35.255   46.593    1
> (mod.McArdle <- specifyModel(file=file.path(etc, "model-McArdle.txt")))
Read 10 records
NOTE: it is generally simpler to use specifyEquations() or cfa()
      see ?specifyEquations
   Path            Parameter StartValue
1  C -> WISC1      <fixed>   6.07      
2  C -> WISC2      B2                  
3  C -> WISC3      B3                  
4  C -> WISC4      B4                  
5  UNIT -> C       Mc                  
6  C <-> C         Vc                  
7  WISC1 <-> WISC1 Vd                  
8  WISC2 <-> WISC2 Vd                  
9  WISC3 <-> WISC3 Vd                  
10 WISC4 <-> WISC4 Vd                  
> sem.McArdle <- sem(mod.McArdle, M.McArdle, 204, fixed.x="UNIT", raw=TRUE)
> summary(sem.McArdle)

Model fit to raw moment matrix.

 Model Chisquare =  83.79119   Df =  8 Pr(>Chisq) = 8.409682e-15
 AIC =  95.79119
 AICc =  84.21759
 BIC =  41.24623
 CAIC =  33.24623

 Normalized Residuals
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
-0.152880 -0.018403  0.001321 -0.005765  0.023952  0.077618 

 Parameter Estimates
   Estimate   Std Error  z value   Pr(>|z|)                     
B2  8.6135392 0.13520497 63.707266 0.000000e+00 WISC2 <--- C    
B3 11.6405430 0.16844533 69.105763 0.000000e+00 WISC3 <--- C    
B4 15.4032333 0.21242959 72.509829 0.000000e+00 WISC4 <--- C    
Mc  3.0176316 0.06064742 49.756963 0.000000e+00 C <--- UNIT     
Vc  0.4434318 0.04761309  9.313233 1.239990e-20 C <--> C        
Vd 11.7883178 0.67389327 17.492856 1.624111e-68 WISC1 <--> WISC1

 Iterations =  38 
> 
> 
> #------------ Bollen industrialization and democracy example -----------------
> 
> # This model, from Bollen (1989, Ch. 8), illustrates the use in sem() of a
> # case-by-variable data set (see ?Bollen) rather than a covariance or moment matrix
> 
> (model.bollen <- specifyModel(file=file.path(etc, "model-Bollen.txt")))
Read 21 records
NOTE: it is generally simpler to use specifyEquations() or cfa()
      see ?specifyEquations
NOTE: adding 13 variances to the model
   Path              Parameter StartValue
1  Demo60 -> y1      <fixed>   1         
2  Demo60 -> y2      lam2                
3  Demo60 -> y3      lam3                
4  Demo60 -> y4      lam4                
5  Demo65 -> y5      <fixed>   1         
6  Demo65 -> y6      lam2                
7  Demo65 -> y7      lam3                
8  Demo65 -> y8      lam4                
9  Indust -> x1      <fixed>   1         
10 Indust -> x2      lam6                
11 Indust -> x3      lam7                
12 y1 <-> y5         theta15             
13 y2 <-> y4         theta24             
14 y2 <-> y6         theta26             
15 y3 <-> y7         theta37             
16 y4 <-> y8         theta48             
17 y6 <-> y8         theta68             
18 Indust -> Demo60  gamma11             
19 Indust -> Demo65  gamma21             
20 Demo60 -> Demo65  beta21              
21 Indust <-> Indust phi                 
22 Demo60 <-> Demo60 V[Demo60]           
23 y1 <-> y1         V[y1]               
24 y2 <-> y2         V[y2]               
25 y3 <-> y3         V[y3]               
26 y4 <-> y4         V[y4]               
27 Demo65 <-> Demo65 V[Demo65]           
28 y5 <-> y5         V[y5]               
29 y6 <-> y6         V[y6]               
30 y7 <-> y7         V[y7]               
31 y8 <-> y8         V[y8]               
32 x1 <-> x1         V[x1]               
33 x2 <-> x2         V[x2]               
34 x3 <-> x3         V[x3]               
> sem.bollen <- sem(model.bollen, data=Bollen)
> summary(sem.bollen)

 Model Chisquare =  39.64376   Df =  38 Pr(>Chisq) = 0.396585
 Goodness-of-fit index =  0.9197114
 Adjusted goodness-of-fit index =  0.8605514
 RMSEA index =  0.02417753   90% CI: (NA, 0.08618725)
 Bentler-Bonett NFI =  0.9450089
 Tucker-Lewis NNFI =  0.9964273
 Bentler CFI =  0.9975316
 Bentler RNI =  0.9975316
 Bollen IFI =  0.997593
 SRMR =  0.05576578
 AIC =  95.64376
 AICc =  74.94811
 BIC =  -124.4208
 CAIC =  -162.4208

 Normalized Residuals
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-1.13834 -0.37846 -0.02113 -0.03988  0.27814  1.05131 

 R-square for Endogenous Variables
Demo60     y1     y2     y3     y4 Demo65     y5     y6     y7     y8     x1 
0.2004 0.7232 0.4755 0.5743 0.7017 0.9645 0.6673 0.5697 0.6425 0.6870 0.8464 
    x2     x3 
0.9465 0.7606 

 Parameter Estimates
          Estimate   Std Error  z value    Pr(>|z|)                       
lam2      1.19078349 0.14020140  8.4933780 2.007161e-17 y2 <--- Demo60    
lam3      1.17454027 0.12121268  9.6899123 3.328143e-22 y3 <--- Demo60    
lam4      1.25098062 0.11757298 10.6400352 1.940560e-26 y4 <--- Demo60    
lam6      2.17965696 0.13931700 15.6453050 3.576518e-55 x2 <--- Indust    
lam7      1.81820952 0.15290304 11.8912579 1.314124e-32 x3 <--- Indust    
theta15   0.59041780 0.36306858  1.6261881 1.039096e-01 y5 <--> y1        
theta24   1.45958287 0.70251366  2.0776576 3.774090e-02 y4 <--> y2        
theta26   2.21251146 0.75241914  2.9405305 3.276507e-03 y6 <--> y2        
theta37   0.72120105 0.62333119  1.1570110 2.472679e-01 y7 <--> y3        
theta48   0.36770923 0.45324028  0.8112898 4.171993e-01 y8 <--> y4        
theta68   1.39032689 0.58859218  2.3621226 1.817063e-02 y8 <--> y6        
gamma11   1.47133149 0.39495897  3.7252768 1.951010e-04 Demo60 <--- Indust
gamma21   0.60047451 0.22721817  2.6427223 8.224247e-03 Demo65 <--- Indust
beta21    0.86504140 0.07537528 11.4764609 1.732269e-30 Demo65 <--- Demo60
phi       0.45466119 0.08845700  5.1399118 2.748674e-07 Indust <--> Indust
V[Demo60] 3.92768936 0.88311593  4.4475354 8.686115e-06 Demo60 <--> Demo60
V[y1]     1.87971345 0.44228808  4.2499753 2.137941e-05 y1 <--> y1        
V[y2]     7.68379277 1.39404037  5.5118868 3.550072e-08 y2 <--> y2        
V[y3]     5.02264245 0.97585896  5.1468938 2.648351e-07 y3 <--> y3        
V[y4]     3.26806049 0.73807250  4.4278312 9.518533e-06 y4 <--> y4        
V[Demo65] 0.16668647 0.23158520  0.7197630 4.716709e-01 Demo65 <--> Demo65
V[y5]     2.34430126 0.48850470  4.7989328 1.595133e-06 y5 <--> y5        
V[y6]     5.03532995 0.93992491  5.3571620 8.453934e-08 y6 <--> y6        
V[y7]     3.60814214 0.72394255  4.9840173 6.227752e-07 y7 <--> y7        
V[y8]     3.35239711 0.71788064  4.6698531 3.014152e-06 y8 <--> y8        
V[x1]     0.08248753 0.01985853  4.1537585 3.270583e-05 x1 <--> x1        
V[x2]     0.12205511 0.07105475  1.7177615 8.584013e-02 x2 <--> x2        
V[x3]     0.47296610 0.09196885  5.1426770 2.708510e-07 x3 <--> x3        

 Iterations =  178 
> summary(sem.bollen, robust=TRUE) # robust SEs and tests

Satorra-Bentler Corrected Fit Statistics:

 Corrected Model Chisquare =  43.06438   Df =  38 Pr(>Chisq) = 0.2634617
 Corrected Chisquare (null model) =  783.1152   Df =  55
 Corrected Bentler-Bonett NFI =  0.9493768
 Corrected Tucker-Lewis NNFI =  0.9899329
 Corrected Bentler CFI =  0.9930445
 Corrected Bentler RNI =  0.9930445
 Corrected Bollen IFI =  0.9932032

Uncorrected Fit Statistics:

 Model Chisquare =  39.64376   Df =  38 Pr(>Chisq) = 0.396585
 Goodness-of-fit index =  0.9197114
 Adjusted goodness-of-fit index =  0.8605514
 RMSEA index =  0.02417753   90% CI: (NA, 0.08618725)
 Bentler-Bonett NFI =  0.9450089
 Tucker-Lewis NNFI =  0.9964273
 Bentler CFI =  0.9975316
 Bentler RNI =  0.9975316
 Bollen IFI =  0.997593
 SRMR =  0.05576578
 AIC =  95.64376
 AICc =  74.94811
 BIC =  -124.4208
 CAIC =  -162.4208

 Normalized Residuals
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-1.13834 -0.37846 -0.02113 -0.03988  0.27814  1.05131 

 R-square for Endogenous Variables
Demo60     y1     y2     y3     y4 Demo65     y5     y6     y7     y8     x1 
0.2004 0.7232 0.4755 0.5743 0.7017 0.9645 0.6673 0.5697 0.6425 0.6870 0.8464 
    x2     x3 
0.9465 0.7606 

 Parameter Estimates (with Robust Standard Errors)
          Estimate   Corrected SE z value    Pr(>|z|)                       
lam2      1.19078349 0.11285278   10.5516540 4.991061e-26 y2 <--- Demo60    
lam3      1.17454027 0.12688070    9.2570443 2.101695e-20 y3 <--- Demo60    
lam4      1.25098062 0.10340470   12.0979085 1.083363e-33 y4 <--- Demo60    
lam6      2.17965696 0.12054667   18.0814359 4.463073e-73 x2 <--- Indust    
lam7      1.81820952 0.12131710   14.9872482 8.896355e-51 x3 <--- Indust    
theta15   0.59041780 0.35708171    1.6534529 9.823872e-02 y5 <--> y1        
theta24   1.45958287 0.69505019    2.0999676 3.573169e-02 y4 <--> y2        
theta26   2.21251146 0.78493160    2.8187315 4.821382e-03 y6 <--> y2        
theta37   0.72120105 0.53296420    1.3531886 1.759954e-01 y7 <--> y3        
theta48   0.36770923 0.39335320    0.9348068 3.498879e-01 y8 <--> y4        
theta68   1.39032689 0.69858919    1.9901924 4.656975e-02 y8 <--> y6        
gamma11   1.47133149 0.30073695    4.8924200 9.960359e-07 Demo60 <--- Indust
gamma21   0.60047451 0.19440735    3.0887439 2.010047e-03 Demo65 <--- Indust
beta21    0.86504140 0.07222111   11.9776814 4.651516e-33 Demo65 <--- Demo60
phi       0.45466119 0.07038073    6.4600237 1.046866e-10 Indust <--> Indust
V[Demo60] 3.92768936 0.80718420    4.8659146 1.139287e-06 Demo60 <--> Demo60
V[y1]     1.87971345 0.30956907    6.0720325 1.263014e-09 y1 <--> y1        
V[y2]     7.68379277 1.27749493    6.0147344 1.801818e-09 y2 <--> y2        
V[y3]     5.02264245 0.99313446    5.0573640 4.250914e-07 y3 <--> y3        
V[y4]     3.26806049 0.75569164    4.3245953 1.528121e-05 y4 <--> y4        
V[Demo65] 0.16668647 0.22211914    0.7504372 4.529914e-01 Demo65 <--> Demo65
V[y5]     2.34430126 0.49118579    4.7727384 1.817378e-06 y5 <--> y5        
V[y6]     5.03532995 0.82856712    6.0771539 1.223343e-09 y6 <--> y6        
V[y7]     3.60814214 0.51656103    6.9849290 2.850001e-12 y7 <--> y7        
V[y8]     3.35239711 0.81248540    4.1261014 3.689647e-05 y8 <--> y8        
V[x1]     0.08248753 0.01446899    5.7009858 1.191165e-08 x1 <--> x1        
V[x2]     0.12205511 0.07464175    1.6352123 1.020045e-01 x2 <--> x2        
V[x3]     0.47296610 0.07628955    6.1996183 5.660025e-10 x3 <--> x3        

 Iterations =  178 
> summary(sem.bollen, analytic.se=FALSE) # uses numeric rather than analytic Hessian

 Model Chisquare =  39.64376   Df =  38 Pr(>Chisq) = 0.396585
 Goodness-of-fit index =  0.9197114
 Adjusted goodness-of-fit index =  0.8605514
 RMSEA index =  0.02417753   90% CI: (NA, 0.08618725)
 Bentler-Bonett NFI =  0.9450089
 Tucker-Lewis NNFI =  0.9964273
 Bentler CFI =  0.9975316
 Bentler RNI =  0.9975316
 Bollen IFI =  0.997593
 SRMR =  0.05576578
 AIC =  95.64376
 AICc =  74.94811
 BIC =  -124.4208
 CAIC =  -162.4208

 Normalized Residuals
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-1.13834 -0.37846 -0.02113 -0.03988  0.27814  1.05131 

 R-square for Endogenous Variables
Demo60     y1     y2     y3     y4 Demo65     y5     y6     y7     y8     x1 
0.2004 0.7232 0.4755 0.5743 0.7017 0.9645 0.6673 0.5697 0.6425 0.6870 0.8464 
    x2     x3 
0.9465 0.7606 

 Parameter Estimates
          Estimate   Std Error  z value    Pr(>|z|)                       
lam2      1.19078349 0.14262380  8.3491220 6.877229e-17 y2 <--- Demo60    
lam3      1.17454027 0.12062852  9.7368372 2.099883e-22 y3 <--- Demo60    
lam4      1.25098062 0.12378641 10.1059612 5.198330e-24 y4 <--- Demo60    
lam6      2.17965696 0.13988990 15.5812320 9.765438e-55 x2 <--- Indust    
lam7      1.81820952 0.15317446 11.8701875 1.690882e-32 x3 <--- Indust    
theta15   0.59041780 0.37183500  1.5878489 1.123205e-01 y5 <--> y1        
theta24   1.45958287 0.70503130  2.0702384 3.843003e-02 y4 <--> y2        
theta26   2.21251146 0.74594380  2.9660565 3.016451e-03 y6 <--> y2        
theta37   0.72120105 0.63200102  1.1411391 2.538121e-01 y7 <--> y3        
theta48   0.36770923 0.47013903  0.7821287 4.341389e-01 y8 <--> y4        
theta68   1.39032689 0.58991997  2.3568059 1.843288e-02 y8 <--> y6        
gamma11   1.47133149 0.39411902  3.7332161 1.890503e-04 Demo60 <--- Indust
gamma21   0.60047451 0.23990241  2.5029949 1.231473e-02 Demo65 <--- Indust
beta21    0.86504140 0.07620011 11.3522329 7.229259e-30 Demo65 <--- Demo60
phi       0.45466119 0.08856000  5.1339341 2.837474e-07 Indust <--> Indust
V[Demo60] 3.92768936 0.90699209  4.3304560 1.488009e-05 Demo60 <--> Demo60
V[y1]     1.87971345 0.46640431  4.0302231 5.572393e-05 y1 <--> y1        
V[y2]     7.68379277 1.37274815  5.5973798 2.176156e-08 y2 <--> y2        
V[y3]     5.02264245 0.98096942  5.1200806 3.054052e-07 y3 <--> y3        
V[y4]     3.26806049 0.75697323  4.3172735 1.579683e-05 y4 <--> y4        
V[Demo65] 0.16668647 0.23812629  0.6999919 4.839324e-01 Demo65 <--> Demo65
V[y5]     2.34430126 0.49336976  4.7516112 2.018021e-06 y5 <--> y5        
V[y6]     5.03532995 0.91300151  5.5151387 3.485050e-08 y6 <--> y6        
V[y7]     3.60814214 0.75306713  4.7912623 1.657353e-06 y7 <--> y7        
V[y8]     3.35239711 0.72756046  4.6077230 4.071024e-06 y8 <--> y8        
V[x1]     0.08248753 0.02013980  4.0957475 4.208084e-05 x1 <--> x1        
V[x2]     0.12205511 0.07136175  1.7103716 8.719719e-02 x2 <--> x2        
V[x3]     0.47296610 0.09096861  5.1992232 2.001231e-07 x3 <--> x3        

 Iterations =  178 
> 
>   # GLS rather than ML estimator:
> sem.bollen.gls <- sem(model.bollen, data=Bollen, objective=objectiveGLS) 
> summary(sem.bollen.gls)

 Model Chisquare =  38.61955   Df =  38 Pr(>Chisq) = 0.4415077
 Goodness-of-fit index =  0.9051117
 Adjusted goodness-of-fit index =  0.835194
 RMSEA index =  0.01484324   90% CI: (NA, 0.08329893)
 Bentler-Bonett NFI =  0.9947254
 Tucker-Lewis NNFI =  0.9998766
 Bentler CFI =  0.9999147
 Bentler RNI =  0.9999147
 Bollen IFI =  0.9999149
 SRMR =  0.1090821

 Normalized Residuals
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-0.8320 -0.1807  0.5769  0.4110  0.9253  1.4382 

 R-square for Endogenous Variables
Demo60     y1     y2     y3     y4 Demo65     y5     y6     y7     y8     x1 
0.2656 0.7567 0.4951 0.6337 0.7002 0.9449 0.6827 0.6003 0.6636 0.6816 0.8745 
    x2     x3 
0.9212 0.7595 

 Parameter Estimates
          Estimate   Std Error  z value    Pr(>|z|)                       
lam2      1.18325160 0.17327639  6.8286949 8.569061e-12 y2 <--- Demo60    
lam3      1.22390274 0.14788824  8.2758623 1.275293e-16 y3 <--- Demo60    
lam4      1.22614759 0.16027163  7.6504346 2.003012e-14 y4 <--- Demo60    
lam6      2.23979524 0.18709913 11.9711685 5.031498e-33 x2 <--- Indust    
lam7      1.88565613 0.21751770  8.6689780 4.360162e-18 x3 <--- Indust    
theta15   0.40858066 0.33287673  1.2274233 2.196635e-01 y5 <--> y1        
theta24   1.53370093 0.68406817  2.2420294 2.495947e-02 y4 <--> y2        
theta26   1.31393252 0.67591993  1.9439174 5.190541e-02 y6 <--> y2        
theta37   0.74005434 0.59467071  1.2444776 2.133239e-01 y7 <--> y3        
theta48   0.29381426 0.41440534  0.7090021 4.783232e-01 y8 <--> y4        
theta68   0.94122208 0.54672390  1.7215675 8.514790e-02 y8 <--> y6        
gamma11   1.80774355 0.48322853  3.7409702 1.833112e-04 Demo60 <--- Indust
gamma21   0.71631819 0.28531880  2.5105889 1.205300e-02 Demo65 <--- Indust
beta21    0.80076016 0.08199670  9.7657611 1.579218e-22 Demo65 <--- Demo60
phi       0.35865731 0.09128096  3.9291579 8.524385e-05 Indust <--> Indust
V[Demo60] 3.24127451 0.89309410  3.6292643 2.842301e-04 Demo60 <--> Demo60
V[y1]     1.41890638 0.40301097  3.5207636 4.303060e-04 y1 <--> y1        
V[y2]     6.30020149 1.31504240  4.7908733 1.660570e-06 y2 <--> y2        
V[y3]     3.82089217 0.93582984  4.0828920 4.447870e-05 y3 <--> y3        
V[y4]     2.84132594 0.69673158  4.0780783 4.540948e-05 y4 <--> y4        
V[Demo65] 0.21926022 0.21665961  1.0120032 3.115365e-01 Demo65 <--> Demo65
V[y5]     1.84878551 0.44720329  4.1341054 3.563400e-05 y5 <--> y5        
V[y6]     3.70704476 0.86367218  4.2921896 1.769198e-05 y6 <--> y6        
V[y7]     3.02023043 0.67471707  4.4762917 7.595070e-06 y7 <--> y7        
V[y8]     2.79368726 0.67063249  4.1657500 3.103307e-05 y8 <--> y8        
V[x1]     0.05148768 0.01659001  3.1035352 1.912235e-03 x1 <--> x1        
V[x2]     0.15383599 0.06689353  2.2997140 2.146443e-02 x2 <--> x2        
V[x3]     0.40389893 0.08718570  4.6326280 3.610530e-06 x3 <--> x3        

 Iterations =  240 
> 
> # -----  a CFA model fit by FIML to the mental-tests dataset with missing data -----
> 
> (mod.cfa.tests <- cfa(file=file.path(etc, "model-Tests.txt"), raw=TRUE))
Read 2 items
NOTE: specify fixed.x="Intercept" in call to sem
NOTE: adding 6 variances to the model
   Path              Parameter      StartValue
1  verbal -> x1      <fixed>        1         
2  verbal -> x2      lam[x2:verbal]           
3  verbal -> x3      lam[x3:verbal]           
4  math -> y1        <fixed>        1         
5  math -> y2        lam[y2:math]             
6  math -> y3        lam[y3:math]             
7  verbal <-> verbal V[verbal]                
8  math <-> math     V[math]                  
9  Intercept -> x1   intercept(x1)            
10 Intercept -> x2   intercept(x2)            
11 Intercept -> x3   intercept(x3)            
12 Intercept -> y1   intercept(y1)            
13 Intercept -> y2   intercept(y2)            
14 Intercept -> y3   intercept(y3)            
15 verbal <-> math   C[verbal,math]           
16 x1 <-> x1         V[x1]                    
17 x2 <-> x2         V[x2]                    
18 x3 <-> x3         V[x3]                    
19 y1 <-> y1         V[y1]                    
20 y2 <-> y2         V[y2]                    
21 y3 <-> y3         V[y3]                    
> cfa.tests <- sem(mod.cfa.tests, data=Tests, na.action=na.pass, 
+                 optimizer=optimizerNlm, objective=objectiveFIML, fixed.x="Intercept")
NOTE: start values computed from preliminary ML fit
NOTE: preliminary ML fit may not have converged
NOTE: preliminary iterations, 106
NOTE: iterations reported for final fit are post preliminary fit
> summary(cfa.tests)

Model fit to raw moment matrix.

 Model log-likelihood =  -347.2625   Df =  8 

 Parameter Estimates
               Estimate   Std Error   z value   Pr(>|z|)     
lam[x2:verbal]  1.0387468  0.19494815  5.328323  9.912357e-08
lam[x3:verbal]  0.8075768  0.15547780  5.194161  2.056449e-07
lam[y2:math]    0.8364372  0.08066108 10.369775  3.403264e-25
lam[y3:math]    0.6866311  0.09607708  7.146669  8.890877e-13
V[verbal]      30.2517333 11.38675113  2.656748  7.889829e-03
V[math]        24.2802991  6.76225133  3.590564  3.299627e-04
intercept(x1)  20.0991914  1.17892116 17.048800  3.567814e-65
intercept(x2)  18.6536620  1.18152980 15.787720  3.779953e-56
intercept(x3)  18.5652082  0.91370170 20.318675  8.791674e-92
intercept(y1)  17.8800429  0.90819279 19.687497  2.759940e-86
intercept(y2)  17.7272188  0.76194342 23.265794 9.845447e-120
intercept(y3)  17.8637093  0.74203491 24.073947 4.686943e-128
C[verbal,math] 13.5873665  6.15062546  2.209103  2.716746e-02
V[x1]          12.7274431  4.78005523  2.662614  7.753624e-03
V[x2]           9.3617491  4.95188609  1.890542  5.868550e-02
V[x3]           5.6729897  2.79774629  2.027700  4.259089e-02
V[y1]           1.8685456  1.47488056  1.266913  2.051863e-01
V[y2]           1.4987281  1.06248411  1.410589  1.583659e-01
V[y3]           5.2495608  1.56791595  3.348114  8.136363e-04
                                 
lam[x2:verbal] x2 <--- verbal    
lam[x3:verbal] x3 <--- verbal    
lam[y2:math]   y2 <--- math      
lam[y3:math]   y3 <--- math      
V[verbal]      verbal <--> verbal
V[math]        math <--> math    
intercept(x1)  x1 <--- Intercept 
intercept(x2)  x2 <--- Intercept 
intercept(x3)  x3 <--- Intercept 
intercept(y1)  y1 <--- Intercept 
intercept(y2)  y2 <--- Intercept 
intercept(y3)  y3 <--- Intercept 
C[verbal,math] math <--> verbal  
V[x1]          x1 <--> x1        
V[x2]          x2 <--> x2        
V[x3]          x3 <--> x3        
V[y1]          y1 <--> y1        
V[y2]          y2 <--> y2        
V[y3]          y3 <--> y3        

 Iterations =  140 
> 
> #------------ Holzinger and Swineford muiltigroup CFA example ----------------
> 
> if (require(MBESS)){ # for data
+ 	data(HS.data)
+ 	
+ 	mod.hs <- cfa(file=file.path(etc, "model-HS.txt"))
+ 	
+ 	mod.mg <- multigroupModel(mod.hs, groups=c("Female", "Male")) 
+ 	
+ 	sem.mg <- sem(mod.mg, data=HS.data, group="Gender",
+ 	              formula = ~ visual + cubes + paper + flags +
+ 	              general + paragrap + sentence + wordc + wordm +
+ 	              wordr + numberr + figurer + object + numberf + figurew +
+ 	              deduct + numeric + problemr + series + arithmet
+ 	              )
+ 	summary(sem.mg)
+ 	
+ 		# with cross-group equality constraints:
+ 		
+ 	mod.mg.eq <- multigroupModel(mod.hs, groups=c("Female", "Male"), allEqual=TRUE)
+ 	
+ 	sem.mg.eq <- sem(mod.mg.eq, data=HS.data, group="Gender",
+ 	              formula = ~ visual + cubes + paper + flags +
+ 	                general + paragrap + sentence + wordc + wordm +
+ 	                wordr + numberr + figurer + object + numberf + figurew +
+ 	                deduct + numeric + problemr + series + arithmet
+ 	              )
+ 	summary(sem.mg.eq)
+ 	
+ 	anova(sem.mg, sem.mg.eq) # test equality constraints
+     
+     options(opt) # restore fit.indices option
+ 	}
Loading required package: MBESS
Read 4 items
NOTE: adding 20 variances to the model
Error in sem.semmodList(mod.mg, data = HS.data, group = "Gender", formula = ~visual +  : 
  object 'HS.data' not found
Calls: sem -> sem.semmodList
Execution halted