form.interaction {mma} | R Documentation |
Create interaction terms of predictor(s) and potential moderator(s).
Description
Create interaction terms of predictor(S) and potential moderator(s). Mainly for linear models.
Usage
form.interaction(x,pred,inter.cov,predref=NULL,kx=NULL)
Arguments
x |
As the x in data.org. |
pred |
The predictor(s) that might have interaction effect with the potential moderators. |
inter.cov |
The vector of names of potential moderators, which are included in x as covariates. |
predref |
The reference group of the predictor if the predictor is categorical. |
kx |
The interaction is with the kx-th predictor(s). kx can be a vector. If kx is null, the interaction is with each predictor. |
Details
form.interaction is used to create interaction terms between predictor(s) and potential moderator(s). The created interaction terms should be used as covariates in linear mediation analysis. The function is not needed for nonlinear mediation method.
Value
Return a matrix with the interaction terms pred*inter.cov.
Author(s)
Qingzhao Yu qyu@lsuhsc.edu
See Also
"test.moderation"
, "moderate"
Examples
data("weight_behavior")
pred=data.frame(weight_behavior[,3])
names(pred)="pred"
x=weight_behavior[,c(2,4:14)]
inter=form.interaction(x,pred,inter.cov=c("sports","sweat"),predref=NULL)
x=cbind(x,inter)
head(x)