to.ncpen.x.mat {ncpen}R Documentation

Convert a data.frame to a ncpen usable matrix.

Description

This automates the processes of to.indicators and interact.data. First, it converts categorical variables to a series of indicators. All other numerical and logical variables are preserved. Then, if interact.all == TRUE, all the variables are interacted.

Usage

to.ncpen.x.mat(df, base = NULL, interact.all = FALSE,
  base.cols = NULL, exclude.pair = NULL)

Arguments

df

a data.frame which includes numerical, logical and categorical columns.

base

a base category removed from the indicator variables. This base will work as the base case for all the categorical variables.

interact.all

indicates whether to interact all the columns (TRUE) or not (FALSE).

base.cols

indicates columns derived from a same column. For example, if age_sq is age^2, then "age" is a base column. Categorical columns will be automatically considered as base columns.

exclude.pair

the pairs will be excluded from interactions. This should be a list object of pairs. For example, list(c("a1", "a2"), c("d1", "d2")).

Value

This returns an object of matrix.

Examples

df = data.frame(num = c(1, 2, 3, 4, 5),
                ctr = c("K", "O", "R", "R", "K"),
                logi = c(TRUE, TRUE, FALSE, FALSE, TRUE),
                age = c(10, 20, 30, 40, 50),
                age_sq = c(10, 20, 30, 40, 50)^2,
                loc = c("b", "a", "c", "a", "b"),
                FTHB = c(1,0,1,0,1),
                PRM  = c(0,1,0,1,0),
                PMI  = c(1,1,0,0,0));

to.ncpen.x.mat(df, interact.all = TRUE,
   base.cols = c("age"),
   exclude.pair = list(c("FTHB", "PRM")));




[Package ncpen version 1.0.0 Index]