-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSemFit.jl
More file actions
75 lines (65 loc) · 2.66 KB
/
SemFit.jl
File metadata and controls
75 lines (65 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
############################################################################################
# struct
############################################################################################
"""
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)`
- `algorithm_name(::SemFit)` -> optimization algorithm
- `n_iterations(::SemFit)` -> number of iterations
- `convergence(::SemFit)` -> convergence flags
- `converged(::SemFit)` -> convergence success
"""
mutable struct SemFit{Mi, So, St, Mo, O}
minimum::Mi
solution::So
start_val::St
model::Mo
optimization_result::O
end
############################################################################################
# pretty printing
############################################################################################
function Base.show(io::IO, semfit::SemFit)
print(io, "Fitted Structural Equation Model \n")
print(io, "=============================================== \n")
print(io, "--------------------- Model ------------------- \n")
print(io, "\n")
print(io, semfit.model)
print(io, "\n")
#print(io, "Objective value: $(round(semfit.minimum, digits = 4)) \n")
print(io, "------------- Optimization result ------------- \n")
print(io, "\n")
print(io, "engine: ")
print(io, optimizer_engine(semfit))
print(io, "\n")
print(io, "\n")
print(io, semfit.optimization_result)
end
############################################################################################
# additional methods
############################################################################################
param_labels(fit::SemFit) = param_labels(fit.model)
nparams(fit::SemFit) = nparams(fit.model)
nsamples(fit::SemFit) = nsamples(fit.model)
# access fields
minimum(sem_fit::SemFit) = sem_fit.minimum
"""
solution(sem_fit::SemFit)
Returns the vector of parameter estimates from a fitted SEM.
"""
solution(sem_fit::SemFit) = sem_fit.solution
start_val(sem_fit::SemFit) = sem_fit.start_val
model(sem_fit::SemFit) = sem_fit.model
optimization_result(sem_fit::SemFit) = sem_fit.optimization_result
# optimizer properties
optimizer_engine(sem_fit::SemFit) = optimizer_engine(optimization_result(sem_fit))
algorithm_name(sem_fit::SemFit) = algorithm_name(optimization_result(sem_fit))
n_iterations(sem_fit::SemFit) = n_iterations(optimization_result(sem_fit))
convergence(sem_fit::SemFit) = convergence(optimization_result(sem_fit))
converged(sem_fit::SemFit) = converged(optimization_result(sem_fit))