transform_matrix: Function to transform each column of matrix using final FP...

View source: R/transformations.R

transform_matrixR Documentation

Function to transform each column of matrix using final FP powers or acd

Description

Function to transform each column of matrix using final FP powers or acd

Usage

transform_matrix(
  x,
  power_list,
  center,
  acdx,
  keep_x_order = FALSE,
  acd_parameter_list = NULL,
  check_binary = TRUE
)

Arguments

x

a matrix with all continuous variables shifted and scaled.

power_list

a named list of FP powers to be applied to the columns of x. Only variables named in this list are transformed.

center

a named logical vector specifying whether the columns in x should be centered. Centering will occur after transformations and will be done separately for each individual column of the transformed data matrix.

acdx

a named logical vector specifying the use of acd transformation.

keep_x_order

a logical indicating whether the order of columns should be kept as in the input matrix x, of if the columns should be ordered according to power_list. The default is FALSE, since the ordering by power_list reflects the xorder argument in mfp2().

acd_parameter_list

a named list. Only required when transformation are to be applied to new data. Entries must correspond to the entries where acdx is set to TRUE. Each components is to be passed to transform_vector_acd(). The default value NULL indicates that the parameters for the acd transformations are to be estimated.

check_binary

passed to transform_vector_fp().

Details

For details on the transformations see transform_vector_fp() and transform_vector_acd().

Value

If all elements of power_list are NA then this function returns NULL. Otherwise a list with three entries: the first x_transformed is a matrix with transformed variables as named in power_list. The number of columns may possibly be different to the input matrix due to higher order FP transformations. The second entry centers stores the values used to center the variables if for any variable center = TRUE (note that usually all variables are centered, or none of them). The third entry acd_parameter stores a named list of estimated acd_parameters. May be empty if no ACD transformation is applied.

Column names

Generally the original variable names are suffixed with ".i", where i enumerates the powers for a given variable in power_list. If a term uses an acd transformation, then the variable is prefixed with A_.

Examples

x = matrix(1:100, nrow = 10)
colnames(x) = paste0("x", 1:ncol(x))
powx = setNames(replicate(ncol(x), c(1,2), simplify = FALSE), colnames(x))
center = setNames(rep(FALSE, ncol(x)), colnames(x))
acdx = setNames(rep(FALSE, ncol(x)), colnames(x))
transform_matrix(x, powx, center, acdx)


mfp2 documentation built on Nov. 15, 2023, 1:06 a.m.