If fewer than 5% of values are missing from a continuous covariate, replace
missing values with the mean in meta
. Otherwise, remove the covariate from covar
.
If values are missing from a factor covariate, remove the covariate from covar
.
If a covariate has constant values, remove it from covar
.
Note that covariates are only removed from covar
, not meta
.
Value
named list of two items:
meta
data frame input
meta
with covariates imputed and/or centered and scaled as necessarycovariates
character vector input
covar
after removing covariates as necessary
Examples
meta = data.frame(V1 = c(rnorm(19), NA),
V2 = c(rnorm(12), rep(NA, 8)))
covar = c("V1","V2")
result = fix_covariates(covar, meta)
#> Warning: Numeric variable of interest V1 has 1 missing values. Replacing missing values with mean.
#> Warning: Numeric variable of interest V2 has 8 missing values. Removing.
result = fix_covariates(covar, meta, center_scale = TRUE)
#> Warning: Numeric variable of interest V1 has 1 missing values. Replacing missing values with mean.
#> Warning: Numeric variable of interest V2 has 8 missing values. Removing.