impute.yai {yaImpute} | R Documentation |
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=method,k=NULL,vars=NULL,
observed=TRUE,...)
Arguments
object |
an object of class |
ancillaryData |
a data frame of variables that may not have been used in
the original call to |
method |
the method used to compute the imputed values for continuous variables,
as follows: |
method.factor |
the method used to compute the imputed values for factors, as follows: |
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 behavior depends
on the value of |
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 c("impute.yai","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
).
Author(s)
Nicholas L. Crookston ncrookston.fs@gmail.com
Andrew O. Finley finleya@msu.edu
Emilie Henderson emilie.henderson@oregonstate.edu
See Also
Examples
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)