Learn R Programming

yaImpute (version 1.0-3)

impute.yai: Impute variables from references to targets

Description

Imputes the observation for variables from a reference observation to a target observation. Also, imputes a value for a reference from other references. This practice is useful for validation (see yai). Variables not available in the original data may be imputed using argument ancillaryData.

Usage

## S3 method for class 'yai':
impute(object,ancillaryData=NULL,method="closest",
           method.factor="closest",k=NULL,vars=NULL,
           observed=TRUE,\dots)

Arguments

object
an object of class yai.
ancillaryData
a data frame of variables that may not have been used in the original call to yai. There must be one row for each reference observation, no missing data, and row names must match those used
method
the method used to compute the imputed values for continuous variables, as follows: closest: use the single neighbor that is closest (this is the default and is always used when k=1); mean: an average over
method.factor
the method used to compute the imputed values for factors, as follows: closest: use the single neighbor that is closest (this is the default and is always used when k=1); other methods are not yet supported.
k
the number neighbors to use in averages, when NULL all present are used.
vars
a character vector of variables to impute, when NULL, the behaviour depends on the value of ancillaryData: when it is NULL, the Y-variables are imputed others all present in ancillaryData are imputed.
observed
when TRUE, columns are created for observed values (those from the target observations) as well as imputed values (those from the reference observations.
...
passed to other methods, currently not used.

Value

  • An object of class impute.yai, which is a data frame with rownames identifying observations and column names identifying variables. When observed=TRUE additional columns are created with a suffix of .o. NA's fill columns of observed values when no corresponding value is known, as in the case for Y-variables from target observations. Scale factors for each variable are returned as an attribute (see attributes).

See Also

yai

Examples

Run this code
require(yaImpute)

data(iris)

# form some test data
refs=sample(rownames(iris),50)
x <- iris[,1:3]      # Sepal.Length Sepal.Width Petal.Length
y <- iris[refs,4:5]  # Petal.Width Species

# build a yai object using mahalanobis
mal <- yai(x=x,y=y,method="mahalanobis")

# output a data frame of observed and imputed values
# of all variables and observations.

impute(mal)
malImp=impute(mal,ancillaryData=iris)
plot(malImp)

Run the code above in your browser using DataLab