@@ -10,16 +10,15 @@ At the moment only available with the `RAMSymbolic` implied type.
1010# Constructor
1111
1212 SemWLS(;
13- observed,
14- meanstructure = false,
13+ observed, implied,
1514 wls_weight_matrix = nothing,
1615 wls_weight_matrix_mean = nothing,
1716 approximate_hessian = false,
1817 kwargs...)
1918
2019# Arguments
2120- `observed`: the `SemObserved` part of the model
22- - `meanstructure::Bool `: does the model have a meanstructure?
21+ - `implied::SemImplied `: the implied part of the model
2322- `approximate_hessian::Bool`: should the hessian be swapped for an approximation
2423- `wls_weight_matrix`: the weight matrix for weighted least squares.
2524 Defaults to GLS estimation (``0.5*(D^T*kron(S,S)*D)`` where D is the duplication matrix
@@ -29,7 +28,7 @@ At the moment only available with the `RAMSymbolic` implied type.
2928
3029# Examples
3130```julia
32- my_wls = SemWLS(observed = my_observed)
31+ my_wls = SemWLS(observed = my_observed, implied = my_implied )
3332```
3433
3534# Interfaces
@@ -50,12 +49,11 @@ SemWLS{HE}(args...) where {HE <: HessianEval} =
5049 SemWLS {HE, map(typeof, args)...} (HE (), args... )
5150
5251function SemWLS (;
53- observed,
54- implied,
55- wls_weight_matrix = nothing ,
56- wls_weight_matrix_mean = nothing ,
57- approximate_hessian = false ,
58- meanstructure = false ,
52+ observed:: SemObserved ,
53+ implied:: SemImplied ,
54+ wls_weight_matrix:: Union{AbstractMatrix, Nothing} = nothing ,
55+ wls_weight_matrix_mean:: Union{AbstractMatrix, Nothing} = nothing ,
56+ approximate_hessian:: Bool = false ,
5957 kwargs... ,
6058)
6159 if observed isa SemObservedMissing
@@ -81,6 +79,10 @@ function SemWLS(;
8179 nobs_vars = nobserved_vars (observed)
8280 tril_ind = filter (x -> (x[1 ] >= x[2 ]), CartesianIndices (obs_cov (observed)))
8381 s = obs_cov (observed)[tril_ind]
82+ size (s) == size (implied. Σ) ||
83+ throw (DimensionMismatch (" SemWLS requires implied covariance to be in vech-ed form " *
84+ " (vectorized lower triangular part of Σ matrix): $(size (s)) expected, $(size (implied. Σ)) found.\n " *
85+ " $(nameof (typeof (implied))) must be constructed with vech=true." ))
8486
8587 # compute V here
8688 if isnothing (wls_weight_matrix)
@@ -94,9 +96,12 @@ function SemWLS(;
9496 " wls_weight_matrix has to be of size $(length (tril_ind)) ×$(length (tril_ind)) " ,
9597 )
9698 end
99+ size (wls_weight_matrix) == (length (s), length (s)) ||
100+ DimensionMismatch (" wls_weight_matrix has to be of size $(length (s)) ×$(length (s)) " )
97101
98- if meanstructure
102+ if MeanStruct (implied) == HasMeanStruct
99103 if isnothing (wls_weight_matrix_mean)
104+ @warn " Computing WLS weight matrix for the meanstructure using obs_cov()"
100105 wls_weight_matrix_mean = inv (obs_cov (observed))
101106 else
102107 size (wls_weight_matrix_mean) == (nobs_vars, nobs_vars) || DimensionMismatch (
0 commit comments