The function cv.trans.psa takes a covariate data frame and replaces each categorical covariate of n >=3 levels with n new binary covariate columns, one for each level. Transforms covariate dataframe for use with the function cv.bal.psa.

cv.trans.psa(covariates, fcol = NULL)

Arguments

covariates

A dataframe of covariates, presumably some factors.

fcol

An optional vector containing the factor columns in the covariate dataframe. In NULL (default) routine to identfy factors internally.

Value

Returns a dataframe covariates.transformed containing new columns for each level of more than binary factors. The rest of the covariate dataframe stays unchanged.

See also

Author

James E. Helmreich James.Helmreich@Marist.edu

Robert M. Pruzek RMPruzek@yahoo.com

KuangNan Xiong harryxkn@yahoo.com

Examples


#Note reordering of columns, binary factor and numeric column are unchanged.
f2 <- factor(sample(c(0, 1), 20, replace = TRUE))
f4 <- factor(sample(c("a", "b", "c", "d"), 20, replace = TRUE))
cv <- rnorm(20)
X <- data.frame(f2, f4, cv)
cv.trans.psa(X)
#> $covariates.transformed
#>             cv f2_1 f4_a f4_b f4_c f4_d
#> 1  -0.09898883    1    0    0    1    0
#> 2  -0.21605786    1    0    0    1    0
#> 3   0.50664978    1    0    0    1    0
#> 4   0.99449724    1    0    1    0    0
#> 5   0.78302360    1    0    1    0    0
#> 6   1.25934822    1    0    1    0    0
#> 7   0.46098323    1    1    0    0    0
#> 8  -0.80519739    1    0    0    0    1
#> 9  -1.17996740    1    0    1    0    0
#> 10 -0.46861563    0    1    0    0    0
#> 11  1.09600832    1    0    1    0    0
#> 12  0.95827225    0    1    0    0    0
#> 13 -1.14536448    0    0    0    1    0
#> 14 -0.43310893    1    1    0    0    0
#> 15  0.37497048    1    0    0    0    1
#> 16  0.43615008    1    0    1    0    0
#> 17  0.03186639    1    0    0    0    1
#> 18 -1.35088553    0    0    1    0    0
#> 19 -0.67293004    1    0    1    0    0
#> 20  1.15554863    1    0    0    1    0
#> 
#
f2 <- factor(sample(c('c', 'C'), 20, replace = TRUE))
f4 <- factor(sample(c("b", "A", "d", "CC"), 20, replace = TRUE))
cv <- rnorm(20)
X <- data.frame(f2, f4, cv)
cv.trans.psa(X)
#> $covariates.transformed
#>             cv f2_c f4_A f4_CC f4_b f4_d
#> 1   0.98286969    1    0     0    0    1
#> 2  -1.41432600    0    1     0    0    0
#> 3   1.35000255    1    0     1    0    0
#> 4  -0.45618467    1    0     1    0    0
#> 5   0.77035231    0    0     0    0    1
#> 6   0.22670736    1    1     0    0    0
#> 7   0.53155119    0    0     0    0    1
#> 8  -1.91123935    1    0     0    1    0
#> 9  -0.27473237    1    0     0    0    1
#> 10  0.30921722    0    0     0    0    1
#> 11  1.74375552    0    0     1    0    0
#> 12  2.24954477    1    0     0    1    0
#> 13  0.29422414    1    1     0    0    0
#> 14 -0.75045766    1    0     0    1    0
#> 15 -0.52028475    1    0     0    0    1
#> 16  1.04817126    1    1     0    0    0
#> 17 -0.06630709    0    0     0    0    1
#> 18 -0.20028914    1    0     1    0    0
#> 19  1.41084729    1    0     0    0    1
#> 20 -0.53180900    0    0     1    0    0
#>