library(recipes)
data(biomass, package = "modeldata")
## Truncate some values to emulate what a lower limit of
## the measurement system might look like
biomass$carbon <- ifelse(biomass$carbon > 40, biomass$carbon, 40)
biomass$hydrogen <- ifelse(biomass$hydrogen > 5, biomass$carbon, 5)
biomass_tr <- biomass[biomass$dataset == "Training", ]
biomass_te <- biomass[biomass$dataset == "Testing", ]
rec <- recipe(
HHV ~ carbon + hydrogen + oxygen + nitrogen + sulfur,
data = biomass_tr
)
impute_rec <- rec %>%
step_impute_lower(carbon, hydrogen)
tidy(impute_rec, number = 1)
impute_rec <- prep(impute_rec, training = biomass_tr)
tidy(impute_rec, number = 1)
transformed_te <- bake(impute_rec, biomass_te)
plot(transformed_te$carbon, biomass_te$carbon,
ylab = "pre-imputation", xlab = "imputed"
)
Run the code above in your browser using DataLab