Estimate covariate effects with measurement parameters fixed (two-step EM)
Source:R/lca_measurement.R
fitZ_from_fit0.RdFixes mPhi at fit0$mPhi and estimates multinomial logit coefficients
mGamma (Q x (T-1)) via an EM algorithm with a BFGS M-step.
Usage
fitZ_from_fit0(
fit0,
data,
Y.names,
Zp.names,
tol = 1e-06,
maxIter = 200L,
incomplete = FALSE,
include.intercept = TRUE,
rebase = "C1",
starting_val = NULL,
verbose = FALSE
)Arguments
- fit0
Output of
lca_step1()$fit0.- data
A data.frame.
- Y.names
Character vector of item column names.
- Zp.names
Character vector of covariate column names.
- tol
Convergence tolerance. Default
1e-6.- maxIter
Maximum EM iterations. Default
200.- incomplete
Logical. FIML for partially missing indicators. See the
Missing Datasection ofvignette("tseLCA", package = "tseLCA"). DefaultFALSE.- include.intercept
Logical. Prepend intercept to covariate design matrix. Default
TRUE.- rebase
Character or integer. Reference class for the multinomial logit parameterization (e.g.
"C1","C2", or an integer). Default"C1". Must match therebaseused inlca_step1()so class column ordering is consistent.- starting_val
Optional Q x (T-1) starting value matrix for
mGamma.- verbose
Logical. Print convergence messages. Default
FALSE.
Value
A list with the following elements:
mGammaQ x (T-1) numeric matrix of multinomial logit coefficients, where Q is the number of columns in the covariate design matrix (including intercept if
include.intercept = TRUE). Rows are named by covariate, columns by non-reference class (e.g."C2","C3").mPhiExpanded item parameter matrix (items x classes), fixed at
fit0$mPhithroughout estimation.vOmegaLength-T vector of marginal class proportions implied by the final
mGamma, computed as column means of the fitted class probability matrix.LLKSeriesSingle-column matrix of observed-data log-likelihoods, one row per EM iteration. Useful for diagnosing convergence.
convergedLogical.
TRUEif the EM loop exited beforemaxIteriterations or if the final log-likelihood change was belowtol.n_obsInteger. Number of observations used in estimation after listwise deletion on covariates.
Examples
# \donttest{
d <- generate_data(200, "high", "covariate", seed = 1)
s1 <- lca_step1(d, Y.names = paste0("Y", 1:6), n_classes = 3)
# Estimate two-step gamma with mPhi fixed at Step-1 values
fZ <- fitZ_from_fit0(
fit0 = s1$fit0,
data = d,
Y.names = paste0("Y", 1:6),
Zp.names = "Zp",
verbose = TRUE
)
#> fitZ EM converged in 9 iterations.
fZ$mGamma # Q x (T-1) coefficient matrix
#> C2 C3
#> Intercept 1.988800 -3.1317130
#> Zp -1.017498 0.9190021
fZ$converged
#> [1] TRUE
# }