Skip to content

Commit 57280f8

Browse files
author
Alexey Stukalov
committed
predict(model, scores)
by default predicts observed vars based on the latent var scores
1 parent 552691a commit 57280f8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/frontend/predict.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
function predict(model::SemLoss, params::AbstractVector,
2+
scores::AbstractMatrix;
3+
score_vars::Union{AbstractVector, Nothing} = latent_var_indices(model),
4+
predict_vars::Union{AbstractVector, Nothing} = observed_var_indices(model))
5+
ram = imply(model).ram_matrices
6+
A = materialize(ram.A, params)
7+
I_A⁻¹ = inv(I - A)
8+
sv_I_A⁻¹ = !isnothing(score_vars) ? I_A⁻¹[:, score_vars] : I_A⁻¹
9+
res = scores * sv_I_A⁻¹'
10+
if MeanStructure(imply(model)) === HasMeanStructure
11+
M = materialize(ram.M, params)
12+
M[score_vars] .= 0 # intercepts already included in the scores
13+
res .+= (I_A⁻¹ * M)'
14+
end
15+
if !isnothing(predict_vars)
16+
res = res[:, predict_vars]
17+
end
18+
return res
19+
end
20+
121
abstract type SemScoresPredictMethod end
222

323
struct SemRegressionScores <: SemScoresPredictMethod end

0 commit comments

Comments
 (0)