impute: Impute using a previously fitted model.

View source: R/modelimpute.R

imputeR Documentation

Impute using a previously fitted model.

Description

Impute one or more variables using a single R object representing a previously fitted model.

Usage

impute(dat, formula, predictor = foretell, ...)

impute_(dat, variables, model, predictor = foretell, ...)

Arguments

dat

[data.frame] The data to be imputed.

formula

[formula] object of the form <imputed variables> ~ <model object>

predictor

[function] with signature object, newdata, ... that returns predicted values given a model object and a new dataset newdata. By default foretell is used.

...

Extra arguments passed to predictor

variables

[character] Names of columns in dat to impute.

model

A model object.

Model specification

Formulas are of the form

IMPUTED_VARIABLES ~ MODEL_OBJECT

The left-hand-side of the formula object lists the variable or variables to be imputed. The right-hand-side must be a model object for which an S3 predict method is implemented. Alternatively, one can specify a custom predicting function. This function must accept at least a model and a dataset, and return one predicted value for each row in the dataset.

foretell implements usefull predict methods for cases where by default the predicted output is not of the same type as the predicted variable (e.g. when using certain link functions in glm)

Details

impute_ is an explicit version of impute that works better in programming contexts, especially in cases involving nonstandard evaluation.

See Also

Other imputation: impute_cart(), impute_hotdeck, impute_lm()

Examples


irisNA <- iris
iris[1:3,1] <- NA
my_model <- lm(Sepal.Length ~ Sepal.Width + Species, data=iris)
impute(irisNA, Sepal.Length ~ my_model)


simputation documentation built on June 16, 2022, 5:10 p.m.