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)
Row | parameter_type | se_hessian | from | value_fixed | identifier | start | estimate | to | se_bootstrap | free |
---|---|---|---|---|---|---|---|---|---|---|
Symbol | Float64 | Symbol | Float64 | Symbol | Float64 | Float64 | Symbol | Float64 | Bool | |
1 | → | 0.0 | ind60 | 1.0 | const | 0.0 | 0.0 | x1 | 0.0 | false |
2 | → | 0.139945 | ind60 | 0.0 | θ_1 | 0.0 | 2.18035 | x2 | 0.174679 | true |
3 | → | 0.153212 | ind60 | 0.0 | θ_2 | 0.0 | 1.81848 | x3 | 0.144255 | true |
4 | → | 0.0 | dem60 | 1.0 | const | 0.0 | 0.0 | y1 | 0.0 | false |
5 | → | 0.186751 | dem60 | 0.0 | θ_3 | 0.0 | 1.25672 | y2 | 0.137071 | true |
6 | → | 0.14933 | dem60 | 0.0 | θ_4 | 0.0 | 1.05773 | y3 | 0.135911 | true |
7 | → | 0.151741 | dem60 | 0.0 | θ_5 | 0.0 | 1.26476 | y4 | 0.158868 | true |
8 | → | 0.0 | dem65 | 1.0 | const | 0.0 | 0.0 | y5 | 0.0 | false |
9 | → | 0.172509 | dem65 | 0.0 | θ_6 | 0.0 | 1.18572 | y6 | 0.192544 | true |
10 | → | 0.161464 | dem65 | 0.0 | θ_7 | 0.0 | 1.27954 | y7 | 0.203132 | true |
11 | → | 0.16432 | dem65 | 0.0 | θ_8 | 0.0 | 1.26596 | y8 | 0.213715 | true |
12 | → | 0.399936 | ind60 | 0.0 | θ_9 | 0.0 | 1.48297 | dem60 | 0.350699 | true |
13 | → | 0.0994512 | dem60 | 0.0 | θ_10 | 0.0 | 0.837319 | dem65 | 0.127864 | true |
14 | → | 0.235306 | ind60 | 0.0 | θ_11 | 0.0 | 0.572344 | dem65 | 0.295112 | true |
15 | ↔ | 0.0201157 | x1 | 0.0 | θ_12 | 0.0 | 0.0826497 | x1 | 0.0208137 | true |
16 | ↔ | 0.0713895 | x2 | 0.0 | θ_13 | 0.0 | 0.12143 | x2 | 0.0721299 | true |
17 | ↔ | 0.0909945 | x3 | 0.0 | θ_14 | 0.0 | 0.473005 | x3 | 0.0474256 | true |
18 | ↔ | 0.478275 | y1 | 0.0 | θ_15 | 0.0 | 1.91688 | y1 | 0.501061 | true |
19 | ↔ | 1.3733 | y2 | 0.0 | θ_16 | 0.0 | 7.47324 | y2 | 1.15016 | true |
20 | ↔ | 0.987867 | y3 | 0.0 | θ_17 | 0.0 | 5.13557 | y3 | 0.944243 | true |
21 | ↔ | 0.771184 | y4 | 0.0 | θ_18 | 0.0 | 3.19053 | y4 | 0.83622 | true |
22 | ↔ | 0.498679 | y5 | 0.0 | θ_19 | 0.0 | 2.38271 | y5 | 0.503207 | true |
23 | ↔ | 0.913706 | y6 | 0.0 | θ_20 | 0.0 | 5.0211 | y6 | 1.15585 | true |
24 | ↔ | 0.742606 | y7 | 0.0 | θ_21 | 0.0 | 3.47771 | y7 | 0.555314 | true |
25 | ↔ | 0.721402 | y8 | 0.0 | θ_22 | 0.0 | 3.29808 | y8 | 0.961604 | true |
26 | ↔ | 0.0885061 | ind60 | 0.0 | θ_23 | 0.0 | 0.4545 | ind60 | 0.038695 | true |
27 | ↔ | 0.963906 | dem60 | 0.0 | θ_24 | 0.0 | 4.00973 | dem60 | 0.644566 | true |
28 | ↔ | 0.224793 | dem65 | 0.0 | θ_25 | 0.0 | 0.174844 | dem65 | 0.251257 | true |
29 | ↔ | 0.376487 | y1 | 0.0 | θ_26 | 0.0 | 0.632078 | y5 | 0.553719 | true |
30 | ↔ | 0.713059 | y2 | 0.0 | θ_27 | 0.0 | 1.33103 | y4 | 0.711435 | true |
31 | ↔ | 0.741161 | y2 | 0.0 | θ_28 | 0.0 | 2.18224 | y6 | 0.787832 | true |
32 | ↔ | 0.633761 | y3 | 0.0 | θ_29 | 0.0 | 0.805662 | y7 | 0.579235 | true |
33 | ↔ | 0.467172 | y8 | 0.0 | θ_30 | 0.0 | 0.352869 | y4 | 0.270135 | true |
34 | ↔ | 0.583634 | y8 | 0.0 | θ_31 | 0.0 | 1.37452 | y6 | 0.825226 | true |
API - model inspection
StructuralEquationModels.sem_summary
— Function(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
StructuralEquationModels.update_estimate!
— Functionupdate_estimate!(
partable::AbstractParameterTable,
sem_fit::SemFit)
Write parameter estimates from sem_fit
to the :estimate
column of partable
StructuralEquationModels.update_partable!
— Functionupdate_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 themodel
parameters
Additional functions
Additional functions that can be used to extract information from a SemFit
object:
StructuralEquationModels.SemFit
— TypeSemFit
Fitted structural equation model.
Interfaces
minimum(::SemFit)
-> minimum objective valuesolution(::SemFit)
-> parameter estimatesstart_val(::SemFit)
-> starting valuesmodel(::SemFit)
optimization_result(::SemFit)
optimizer(::SemFit)
-> optimization algorithmn_iterations(::SemFit)
-> number of iterationsconvergence(::SemFit)
-> convergence properties
Fit measures
StructuralEquationModels.fit_measures
— Functionfit_measures(sem_fit, args...)
Return a default set of fit measures or the fit measures passed as arg...
.
StructuralEquationModels.AIC
— FunctionAIC(sem_fit::SemFit)
Return the akaike information criterion.
StructuralEquationModels.BIC
— FunctionBIC(sem_fit::SemFit)
Return the bayesian information criterion.
StructuralEquationModels.χ²
— Functionχ²(sem_fit::SemFit)
Return the χ² value.
StructuralEquationModels.df
— Functiondf(sem_fit::SemFit)
df(model::AbstractSem)
Return the degrees of freedom.
StructuralEquationModels.minus2ll
— Functionminus2ll(sem_fit::SemFit)
Return the negative 2* log likelihood.
StructuralEquationModels.n_man
— Functionn_man(sem_fit::SemFit)
n_man(model::AbstractSemSingle)
Return the number of manifest variables.
StructuralEquationModels.n_obs
— Functionn_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.
StructuralEquationModels.n_par
— Functionn_par(sem_fit::SemFit)
n_par(model::AbstractSemSingle)
n_par(model::SemEnsemble)
n_par(identifier::Dict)
Return the number of parameters.
StructuralEquationModels.p_value
— Functionp(sem_fit::SemFit)
Return the p value computed from the χ² test statistic.
StructuralEquationModels.RMSEA
— FunctionRMSEA(sem_fit::SemFit)
Return the RMSEA.