add_poly_terms | R Documentation |
<variable>_d_<degree>
(e.g., Z1_d_2
for the square of Z1
).Creates polynomial terms for specified variables in a data frame
Polynomial terms are named as <variable>_d_<degree>
(e.g., Z1_d_2
for the square of Z1
).
add_poly_terms(data, Z, degree = 3, poly = TRUE)
data |
Data frame. The data frame containing the variables for which polynomial terms are to be created. |
Z |
Character vector. The names of the variables for which polynomial terms are to be created. |
degree |
Integer. The maximum degree of polynomial terms to be created. Default is 3. |
poly |
Logical. If TRUE, polynomial terms will be created. If FALSE, no polynomial terms will be created. Default is TRUE. |
A list with two components:
data
: The modified data frame with added polynomial terms.
new_terms
: A character vector of the names of the added polynomial terms (e.g., Z1_d_2
).
#'
set.seed(123)
data_generator <- function(N){
Z1 <- rnorm(N,0,1)
Z2 <- rnorm(N,0,1)
X <- rnorm(N, Z1 + Z2, 1)
Y <- rnorm(N, Z1 + Z2, 1)
df <- data.frame(Z1, Z2, X, Y)
return(df)
}
dat <- data_generator(250)
poly_terms <- add_poly_terms(data = dat, Z = c("Z1", "Z2"), degree = 3, poly = TRUE)
print(poly_terms$new_terms)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.