covariates | R Documentation |
This function standardizes continuous variables, transforms categorical variables to indicator variables and centers the transformed variables.
covariates(x.con, x.cat, con.rescale = TRUE, cat.center = FALSE, fill.missing = TRUE)
x.con |
a matrix or data frame consisting of continuous covariates. |
x.cat |
a matrix or data frame consisting of categorical covariates. |
con.rescale |
if |
cat.center |
if |
fill.missing |
If |
This function returns a data frame containing the rescaled variables.
For Bayesian hierarchical or penalization modeling, it is important to transform all variables to have a common scale before fitting data.
Nengjun Yi, nyi@uab.edu
# fake data
age = rnorm(50, 30, 0.1)
sex = sample(x = c("male", "female"), size = 50, replace = T, prob = c(0.5, 0.5))
diet = sample(x = c(1, 5), size = 50, replace = T, prob = c(0.3, 0.7))
race = sample(c("Asian", "White", "Black"), size = 50, replace = T, prob = c(0.2, 0.4, 0.4))
x.con = age # continuous variable
x.cat = cbind(sex, diet, race) # categorical variables
x.con[1:2] = NA
x.cat[1,] = NA
x1 = covariates(x.con = x.con, x.cat = x.cat, con.rescale = F, cat.center = F,
fill.missing = T)
x1
x2 = covariates(x.con = x.con, x.cat = x.cat, con.rescale = T, cat.center = F,
fill.missing = T)
x2
x3 = covariates(x.con = x.con, x.cat = x.cat, con.rescale = T, cat.center = T,
fill.missing = T)
x3
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.