Model inspection

After you fitted a model,

model_fit = sem_fit(model)

you end up with an object of type SemFit.

You can get some more information about it by using the sem_summary function:

sem_summary(model_fit)

Fitted Structural Equation Model

--------------------------------- Properties ---------------------------------

Optimization algorithm:      L-BFGS
Convergence:                 true
No. iterations/evaluations:  189

Number of parameters:        31
Number of observations:      75.0

----------------------------------- Model -----------------------------------

Structural Equation Model
- Loss Functions
   SemML
- Fields
   observed:    SemObservedData
   imply:       RAM
   optimizer:   SemOptimizerOptim

To compute fit measures, we use

fit_measures(model_fit)
Dict{Symbol, Union{Missing, Float64}} with 8 entries:
  :minus2ll => 3106.66
  :AIC      => 3168.66
  :BIC      => 3240.5
  :df       => 35.0
  :χ²       => 37.6169
  :p_value  => 0.350263
  :RMSEA    => 0.0315738
  :n_par    => 31.0

or compute them individually:

AIC(model_fit)
3168.655879277305

A list of available Fit measures is at the end of this page.

To inspect the parameter estimates, we can update a ParameterTable object and call sem_summary on it:

update_estimate!(partable, model_fit)

sem_summary(partable)

--------------------------------- Variables ---------------------------------

Latent variables:    ind60 dem60 dem65
Observed variables:  x1 x2 x3 y1 y2 y3 y4 y5 y6 y7 y8

---------------------------- Parameter Estimates -----------------------------

Loadings:

ind60

  to   estimate   identifier   value_fixed   start   free   from    type

  x1   0.0        const        1.0           0.0     0.0    ind60   →
  x2   2.18       θ_1          0.0           0.0     1.0    ind60   →
  x3   1.82       θ_2          0.0           0.0     1.0    ind60   →

dem60

  to   estimate   identifier   value_fixed   start   free   from    type

  y1   0.0        const        1.0           0.0     0.0    dem60   →
  y2   1.26       θ_3          0.0           0.0     1.0    dem60   →
  y3   1.06       θ_4          0.0           0.0     1.0    dem60   →
  y4   1.26       θ_5          0.0           0.0     1.0    dem60   →

dem65

  to   estimate   identifier   value_fixed   start   free   from    type

  y5   0.0        const        1.0           0.0     0.0    dem65   →
  y6   1.19       θ_6          0.0           0.0     1.0    dem65   →
  y7   1.28       θ_7          0.0           0.0     1.0    dem65   →
  y8   1.27       θ_8          0.0           0.0     1.0    dem65   →

Directed Effects:

  from        to      estimate   identifier   value_fixed   start   free

  ind60   →   dem60   1.48       θ_9          0.0           0.0     1.0
  dem60   →   dem65   0.84       θ_10         0.0           0.0     1.0
  ind60   →   dem65   0.57       θ_11         0.0           0.0     1.0

Variances:

  from        to      estimate   identifier   value_fixed   start   free

  x1      ↔   x1      0.08       θ_12         0.0           0.0     1.0
  x2      ↔   x2      0.12       θ_13         0.0           0.0     1.0
  x3      ↔   x3      0.47       θ_14         0.0           0.0     1.0
  y1      ↔   y1      1.92       θ_15         0.0           0.0     1.0
  y2      ↔   y2      7.47       θ_16         0.0           0.0     1.0
  y3      ↔   y3      5.14       θ_17         0.0           0.0     1.0
  y4      ↔   y4      3.19       θ_18         0.0           0.0     1.0
  y5      ↔   y5      2.38       θ_19         0.0           0.0     1.0
  y6      ↔   y6      5.02       θ_20         0.0           0.0     1.0
  y7      ↔   y7      3.48       θ_21         0.0           0.0     1.0
  y8      ↔   y8      3.3        θ_22         0.0           0.0     1.0
  ind60   ↔   ind60   0.45       θ_23         0.0           0.0     1.0
  dem60   ↔   dem60   4.01       θ_24         0.0           0.0     1.0
  dem65   ↔   dem65   0.17       θ_25         0.0           0.0     1.0

Covariances:

  from       to   estimate   identifier   value_fixed   start   free

  y1     ↔   y5   0.63       θ_26         0.0           0.0     1.0
  y2     ↔   y4   1.33       θ_27         0.0           0.0     1.0
  y2     ↔   y6   2.18       θ_28         0.0           0.0     1.0
  y3     ↔   y7   0.81       θ_29         0.0           0.0     1.0
  y8     ↔   y4   0.35       θ_30         0.0           0.0     1.0
  y8     ↔   y6   1.37       θ_31         0.0           0.0     1.0

We can also update the ParameterTable object with other information via update_partable!. For example, if we want to compare hessian-based and bootstrap-based standard errors, we may write

se_bs = se_bootstrap(model_fit; n_boot = 20)
se_he = se_hessian(model_fit)

update_partable!(partable, model_fit, se_he, :se_hessian)
update_partable!(partable, model_fit, se_bs, :se_bootstrap)

sem_summary(partable)
Number of nonconverged models: 0.0

--------------------------------- Variables ---------------------------------

Latent variables:    ind60 dem60 dem65
Observed variables:  x1 x2 x3 y1 y2 y3 y4 y5 y6 y7 y8

---------------------------- Parameter Estimates -----------------------------

Loadings:

ind60

  to   estimate   identifier   value_fixed   start   free   from    type   se_bootstrap   se_hessian

  x1   0.0        const        1.0           0.0     0.0    ind60   →      0.0            0.0
  x2   2.18       θ_1          0.0           0.0     1.0    ind60   →      0.17           0.14
  x3   1.82       θ_2          0.0           0.0     1.0    ind60   →      0.14           0.15

dem60

  to   estimate   identifier   value_fixed   start   free   from    type   se_bootstrap   se_hessian

  y1   0.0        const        1.0           0.0     0.0    dem60   →      0.0            0.0
  y2   1.26       θ_3          0.0           0.0     1.0    dem60   →      0.14           0.19
  y3   1.06       θ_4          0.0           0.0     1.0    dem60   →      0.14           0.15
  y4   1.26       θ_5          0.0           0.0     1.0    dem60   →      0.16           0.15

dem65

  to   estimate   identifier   value_fixed   start   free   from    type   se_bootstrap   se_hessian

  y5   0.0        const        1.0           0.0     0.0    dem65   →      0.0            0.0
  y6   1.19       θ_6          0.0           0.0     1.0    dem65   →      0.19           0.17
  y7   1.28       θ_7          0.0           0.0     1.0    dem65   →      0.2            0.16
  y8   1.27       θ_8          0.0           0.0     1.0    dem65   →      0.21           0.16

Directed Effects:

  from        to      estimate   identifier   value_fixed   start   free   se_bootstrap   se_hessian

  ind60   →   dem60   1.48       θ_9          0.0           0.0     1.0    0.35           0.4
  dem60   →   dem65   0.84       θ_10         0.0           0.0     1.0    0.13           0.1
  ind60   →   dem65   0.57       θ_11         0.0           0.0     1.0    0.3            0.24

Variances:

  from        to      estimate   identifier   value_fixed   start   free   se_bootstrap   se_hessian

  x1      ↔   x1      0.08       θ_12         0.0           0.0     1.0    0.02           0.02
  x2      ↔   x2      0.12       θ_13         0.0           0.0     1.0    0.07           0.07
  x3      ↔   x3      0.47       θ_14         0.0           0.0     1.0    0.05           0.09
  y1      ↔   y1      1.92       θ_15         0.0           0.0     1.0    0.5            0.48
  y2      ↔   y2      7.47       θ_16         0.0           0.0     1.0    1.15           1.37
  y3      ↔   y3      5.14       θ_17         0.0           0.0     1.0    0.94           0.99
  y4      ↔   y4      3.19       θ_18         0.0           0.0     1.0    0.84           0.77
  y5      ↔   y5      2.38       θ_19         0.0           0.0     1.0    0.5            0.5
  y6      ↔   y6      5.02       θ_20         0.0           0.0     1.0    1.16           0.91
  y7      ↔   y7      3.48       θ_21         0.0           0.0     1.0    0.56           0.74
  y8      ↔   y8      3.3        θ_22         0.0           0.0     1.0    0.96           0.72
  ind60   ↔   ind60   0.45       θ_23         0.0           0.0     1.0    0.04           0.09
  dem60   ↔   dem60   4.01       θ_24         0.0           0.0     1.0    0.64           0.96
  dem65   ↔   dem65   0.17       θ_25         0.0           0.0     1.0    0.25           0.22

Covariances:

  from       to   estimate   identifier   value_fixed   start   free   se_bootstrap   se_hessian

  y1     ↔   y5   0.63       θ_26         0.0           0.0     1.0    0.55           0.38
  y2     ↔   y4   1.33       θ_27         0.0           0.0     1.0    0.71           0.71
  y2     ↔   y6   2.18       θ_28         0.0           0.0     1.0    0.79           0.74
  y3     ↔   y7   0.81       θ_29         0.0           0.0     1.0    0.58           0.63
  y8     ↔   y4   0.35       θ_30         0.0           0.0     1.0    0.27           0.47
  y8     ↔   y6   1.37       θ_31         0.0           0.0     1.0    0.83           0.58

Export results

You may convert a ParameterTable to a DataFrame and use the DataFrames package for further analysis (or to save it to your hard drive).

using DataFrames

parameters_df = DataFrame(partable)
34×10 DataFrame
Rowparameter_typese_hessianfromvalue_fixedidentifierstartestimatetose_bootstrapfree
SymbolFloat64SymbolFloat64SymbolFloat64Float64SymbolFloat64Bool
10.0ind601.0const0.00.0x10.0false
20.139945ind600.0θ_10.02.18035x20.174679true
30.153212ind600.0θ_20.01.81848x30.144255true
40.0dem601.0const0.00.0y10.0false
50.186751dem600.0θ_30.01.25672y20.137071true
60.14933dem600.0θ_40.01.05773y30.135911true
70.151741dem600.0θ_50.01.26476y40.158868true
80.0dem651.0const0.00.0y50.0false
90.172509dem650.0θ_60.01.18572y60.192544true
100.161464dem650.0θ_70.01.27954y70.203132true
110.16432dem650.0θ_80.01.26596y80.213715true
120.399936ind600.0θ_90.01.48297dem600.350699true
130.0994512dem600.0θ_100.00.837319dem650.127864true
140.235306ind600.0θ_110.00.572344dem650.295112true
150.0201157x10.0θ_120.00.0826497x10.0208137true
160.0713895x20.0θ_130.00.12143x20.0721299true
170.0909945x30.0θ_140.00.473005x30.0474256true
180.478275y10.0θ_150.01.91688y10.501061true
191.3733y20.0θ_160.07.47324y21.15016true
200.987867y30.0θ_170.05.13557y30.944243true
210.771184y40.0θ_180.03.19053y40.83622true
220.498679y50.0θ_190.02.38271y50.503207true
230.913706y60.0θ_200.05.0211y61.15585true
240.742606y70.0θ_210.03.47771y70.555314true
250.721402y80.0θ_220.03.29808y80.961604true
260.0885061ind600.0θ_230.00.4545ind600.038695true
270.963906dem600.0θ_240.04.00973dem600.644566true
280.224793dem650.0θ_250.00.174844dem650.251257true
290.376487y10.0θ_260.00.632078y50.553719true
300.713059y20.0θ_270.01.33103y40.711435true
310.741161y20.0θ_280.02.18224y60.787832true
320.633761y30.0θ_290.00.805662y70.579235true
330.467172y80.0θ_300.00.352869y40.270135true
340.583634y80.0θ_310.01.37452y60.825226true

API - model inspection

StructuralEquationModels.sem_summaryFunction
(1) sem_summary(sem_fit::SemFit; show_fitmeasures = false)

(2) sem_summary(partable::AbstractParameterTable)

Print information about (1) a fitted SEM or (2) a parameter table to stdout.

Extended help

Addition keyword arguments

  • digits = 2: controls precision of printed estimates, standard errors, etc.
  • color = :light_cyan: color of some parts of the printed output. Can be adjusted for readability.
  • secondary_color = :light_yellow
  • show_variables = true
source
StructuralEquationModels.update_partable!Function
update_partable!(partable::AbstractParameterTable, sem_fit::SemFit, vec, column)

Write vec to column of partable.

Arguments

  • vec::Vector: has to be in the same order as the model parameters
source

Additional functions

Additional functions that can be used to extract information from a SemFit object:

StructuralEquationModels.SemFitType
SemFit

Fitted structural equation model.

Interfaces

  • minimum(::SemFit) -> minimum objective value

  • solution(::SemFit) -> parameter estimates

  • start_val(::SemFit) -> starting values

  • model(::SemFit)

  • optimization_result(::SemFit)

  • optimizer(::SemFit) -> optimization algorithm

  • n_iterations(::SemFit) -> number of iterations

  • convergence(::SemFit) -> convergence properties

source

Fit measures

StructuralEquationModels.n_obsFunction
n_obs(sem_fit::SemFit)
n_obs(model::AbstractSemSingle)
n_obs(model::SemEnsemble)

Return the number of observed data points.

For ensemble models, return the sum over all submodels.

source
StructuralEquationModels.n_parFunction
n_par(sem_fit::SemFit)
n_par(model::AbstractSemSingle)
n_par(model::SemEnsemble)
n_par(identifier::Dict)

Return the number of parameters.

source