From 1f27c46baf19f9811d9ea5be7f9d9178f4d04fce Mon Sep 17 00:00:00 2001 From: Suraj Yerramilli Date: Sat, 7 Feb 2015 02:56:15 +0530 Subject: added imputing function to deal with missing values --- R/preProcess.R | 23 ++++++++++++++++++++--- man/dataImpute.Rd | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/R/preProcess.R b/R/preProcess.R index 0adb56c..a9db126 100644 --- a/R/preProcess.R +++ b/R/preProcess.R @@ -24,13 +24,30 @@ #' #' @seealso \code{\link[Amelia]{amelia}} #' @export -dataImpute <- function(data,m=5){ +dataImpute <- function(data,m=1){ # check if the class is correct if(class(data)!='idframe') stop("Not an idframe data") - ninputs <- dim(data$input)[2] dataMatrix <- cbind(data$input,data$output) - a.out <- amelia(dataMatrix,m=5,p2s = 0) + a.out <- amelia(dataMatrix,m=m,p2s = 0) + + a.assign <- function(dataMatrix,data){ + ninputs <- dim(data$input)[2] + out <- data + + colIndex <- 1:(dim(dataMatrix)[2]) + inputIndex <- 1:ninputs + outputIndex <- colIndex[!(colIndex %in% inputIndex)] + + out$input <- dataMatrix[,1:inputIndex,drop=F] + out$output <- dataMatrix[,1:outputIndex,drop=F] + + return(out) + } + + imputations <- lapply(X=a.out$imputations,FUN=a.assign,data=data) + + return(list(imputations=imputations,m=m)) } \ No newline at end of file diff --git a/man/dataImpute.Rd b/man/dataImpute.Rd index 9139862..67c83e0 100644 --- a/man/dataImpute.Rd +++ b/man/dataImpute.Rd @@ -4,7 +4,7 @@ \alias{dataImpute} \title{Impute missing values} \usage{ -dataImpute(data, m = 5) +dataImpute(data, m = 1) } \arguments{ \item{data}{an object of class \code{idframe}} -- cgit