make.product: Make Product Terms (e.g., interactions)

Description Usage Arguments Value Examples

View source: R/quest_functions.R

Description

make.product creates product terms (i.e., interactions) from various components. make.product uses Center for the optional of centering and/or scaling the predictors and/or moderators before making the product terms.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
make.product(
  data,
  x.nm,
  m.nm,
  center.x = FALSE,
  center.m = FALSE,
  scale.x = FALSE,
  scale.m = FALSE,
  suffix.x = "",
  suffix.m = "",
  sep = ":",
  combo = TRUE
)

Arguments

data

data.frame of data.

x.nm

character vector of colnames from data specifying the predictor columns.

m.nm

character vector of colnames from data specifying the moderator columns.

center.x

logical vector of length 1 specifying whether the predictor columns should be grand-mean centered before making the product terms.

center.m

logical vector of length 1 specifying whether the moderator columns should be grand-mean centered before making the product terms.

scale.x

logical vector of length 1 specifying whether the predictor columns should be grand-SD scaled before making the product terms.

scale.m

logical vector of length 1 specifying whether the moderator columns should be grand-SD scaled before making the product terms.

suffix.x

character vector of length 1 specifying any suffix to add to the end of the predictor colnames x.nm when creating the colnames of the return object.

suffix.m

character vector of length 1 specifying any suffix to add to the end of the moderator colnames m.nm when creating the colnames of the return object.

sep

character vector of length 1 specifying the string to connect x.nm and m.nm when specifying the colnames of the return object.

combo

logical vector of length 1 specifying whether all combinations of the predictors and moderators should be calculated or only those in parallel to each other (i.e., x.nm[i] and m.nm[i]). This argument is only applicable when multiple predictors AND multiple moderators are given.

Value

data.frame with product terms (e.g., interactions) as columns. The colnames are created by paste(paste0(x.nm, suffix.x), paste0(m.nm, suffix.m), sep = sep).

Examples

1
2
3
4
5
6
7
make.product(data = attitude, x.nm = c("complaints","privileges"),
   m.nm = "learning", center.x = TRUE, center.m = TRUE,
   suffix.x = "_c", suffix.m = "_c") # with grand-mean centering
make.product(data = attitude, x.nm = c("complaints","privileges"),
   m.nm = c("learning","raises"), combo = TRUE) # all possible combinations
make.product(data = attitude, x.nm = c("complaints","privileges"),
   m.nm = c("learning","raises"), combo = FALSE) # only combinations "in parallel"

quest documentation built on Sept. 10, 2021, 5:07 p.m.

Related to make.product in quest...