Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/loss/ML/ML.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,18 @@ end
############################################################################################

function SemML(; observed::SemObserved, approximate_hessian::Bool = false, kwargs...)

if observed isa SemObservedMissing
throw(ArgumentError(
"Normal maximum likelihood estimation can't be used with `SemObservedMissing`.
Use full information maximum likelihood (FIML) estimation or remove missing
values in your data.
A FIML model can be constructed with
Sem(
...,
observed = SemObservedMissing,
loss = SemFIML,
meanstructure = true
)"))
@warn """
ML estimation with `SemObservedMissing` will use an approximate covariance and mean estimated with EM algorithm.
For more accurate results, consider using full information maximum likelihood (FIML) estimation or remove missing values in your data.
A FIML model can be constructed with
Sem(
...,
observed = SemObservedMissing,
loss = SemFIML,
meanstructure = true
)
"""
end

obsmean = obs_mean(observed)
Expand Down
30 changes: 15 additions & 15 deletions src/loss/WLS/WLS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,24 @@ function SemWLS(;
meanstructure = false,
kwargs...,
)

if observed isa SemObservedMissing
throw(ArgumentError(
"WLS estimation can't be used with `SemObservedMissing`.
Use full information maximum likelihood (FIML) estimation or remove missing
values in your data.
A FIML model can be constructed with
Sem(
...,
observed = SemObservedMissing,
loss = SemFIML,
meanstructure = true
)"))
@warn """
WLS estimation with `SemObservedMissing` will use an approximate covariance and mean estimated with EM algorithm.
For more accurate results, consider using full information maximum likelihood (FIML) estimation or remove missing values in your data.
A FIML model can be constructed with
Sem(
...,
observed = SemObservedMissing,
loss = SemFIML,
meanstructure = true
)
"""
end

if !(implied isa RAMSymbolic)
throw(ArgumentError(
"WLS estimation is only available with the implied type RAMSymbolic at the moment."))
if !(implied isa RAMSymbolic)
"WLS estimation is only available with the implied type RAMSymbolic at the moment." |>
ArgumentError |>
throw
end

nobs_vars = nobserved_vars(observed)
Expand Down
26 changes: 14 additions & 12 deletions src/observed/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,24 @@ function SemObservedData(;
observed_var_prefix::Union{Symbol, AbstractString} = :obs,
kwargs...,
)

data, obs_vars, _ =
prepare_data(data, observed_vars, specification; observed_var_prefix)
obs_mean, obs_cov = mean_and_cov(data, 1)

if any(ismissing.(data))
throw(ArgumentError(
"Your dataset contains missing values.
Remove missing values or use full information maximum likelihood (FIML) estimation.
A FIML model can be constructed with
Sem(
...,
observed = SemObservedMissing,
loss = SemFIML,
meanstructure = true
)"))
if any(ismissing, data)
"""
Your dataset contains missing values.
Remove missing values or use full information maximum likelihood (FIML) estimation.
A FIML model can be constructed with
Sem(
...,
observed = SemObservedMissing,
loss = SemFIML,
meanstructure = true
)
""" |>
ArgumentError |>
throw
end

return SemObservedData(data, obs_vars, obs_cov, vec(obs_mean), size(data, 1))
Expand Down
Loading