Identify the product term(s), if any, along a path in a model and return the term(s), with the variables involved and the coefficient(s) of the term(s).
get_prod( x, y, operator =":", fit =NULL, est =NULL, data =NULL, expand =FALSE)
Arguments
x: Character. Variable name.
y: Character. Variable name.
operator: Character. The string used to indicate a product term. Default is ":", used in both lm()
and lavaan::sem() for observed variables.
fit: The fit object. Currently only supports a lavaan::lavaan object. It can also be a lavaan.mi object returned by semTools::runMI() or its wrapper, such as semTools::sem.mi().
est: The output of lavaan::parameterEstimates(). If NULL, the default, it will be generated from fit. If supplied, fit will ge ignored.
data: Data frame (optional). If supplied, it will be used to identify the product terms.
expand: Whether products of more than two terms will be searched. FALSE by default.
Returns
If at least one product term is found, it returns a list with these elements:
prod: The names of the product terms found.
b: The coefficients of these product terms.
w: The variable, other than x, in each product term.
x: The x-variable, that is, where the path starts.
y: The y-variable, that is, where the path ends.
It returns NA if no product term is found along the path.
Details
This function is used by several functions in manymome
to identify product terms along a path. If possible, this is done by numerically checking whether a column in a dataset is the product of two other columns. If not possible (e.g., the "product term" is the "product" of two latent variables, formed by the products of indicators), then it requires the user to specify an operator.