diff options
-rw-r--r-- | R/preProcess.R | 23 | ||||
-rw-r--r-- | 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}} |