
Extract Model Components for Selection Models
Source:R/extract_model_components.R
extract_model_components.RdThis internal utility function extracts key components—such as model frames, matrices,
and response variables—from formulas and a data set. It is used by models like
HeckmanCL, HeckmanGe, HeckmanSK, HeckmanBS, and HeckmantS.
Additionally, it can handle covariate matrices for modeling dispersion (sigma) and
correlation (rho) structures.
Usage
extract_model_components(
selection,
outcome,
data,
outcomeS = NULL,
outcomeC = NULL,
drop.levels = TRUE
)Arguments
- selection
A formula for the selection equation.
- outcome
A formula for the outcome equation.
- data
A data frame containing all variables.
- outcomeS
Optional formula or matrix for the dispersion model (
sigma).- outcomeC
Optional formula or matrix for the correlation model (
rho).- drop.levels
Logical. If
TRUE, drops unused factor levels.
Value
A list with the following components:
XSModel matrix for the selection equation.
YSResponse vector for the selection equation.
NXSNumber of covariates in the selection model.
XOModel matrix for the outcome equation.
YOResponse vector for the outcome equation.
NXONumber of covariates in the outcome model.
MsigmaMatrix for the dispersion model (or
NULLif not provided).NENumber of covariates for the dispersion model (0 if not provided).
MrhoMatrix for the correlation model (or
NULLif not provided).NVNumber of covariates for the correlation model (0 if not provided).
YSLevelsFactor levels of the binary selection response.