diff options
author | Suraj Yerramilli | 2015-02-07 02:56:15 +0530 |
---|---|---|
committer | Suraj Yerramilli | 2015-02-07 02:56:15 +0530 |
commit | 1f27c46baf19f9811d9ea5be7f9d9178f4d04fce (patch) | |
tree | 732993fd3b2d2813a13ef6f3391f0fa1f569db63 | |
parent | bd6bfe89cc621dd8ffa8d1f57b07b1c3d136221b (diff) | |
download | SysID-R-code-1f27c46baf19f9811d9ea5be7f9d9178f4d04fce.tar.gz SysID-R-code-1f27c46baf19f9811d9ea5be7f9d9178f4d04fce.tar.bz2 SysID-R-code-1f27c46baf19f9811d9ea5be7f9d9178f4d04fce.zip |
added imputing function to deal with missing values
-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}} |