form.interaction | R Documentation |
Create interaction terms of predictor(S) and potential moderator(s). Mainly for linear models.
form.interaction(x,pred,inter.cov,predref=NULL,kx=NULL)
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. |
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.
Return a matrix with the interaction terms pred*inter.cov.
Qingzhao Yu qyu@lsuhsc.edu
"test.moderation"
, "moderate"
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.