Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c1841da
Showing
18 changed files
with
1,050 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Package: imputeTestbench | ||
Type: Package | ||
Title: Test Bench for Missing Data Imputing Models/Methods Comparison | ||
Version: 0.1.0 | ||
Author: Neeraj Bokde | ||
Maintainer: Neeraj Bokde <neerajdhanraj@gmail.com> | ||
Description: Provides a Test bench for comparison of missing | ||
data imputation models/methods. It compares imputing methods with reference | ||
to RMSE, MAE or MAPE parameters. It allows to add new proposed methods to test | ||
bench and to compare with other methods. The function 'append_method()' allows | ||
to add multiple numbers of methods to the existing methods available in test bench. | ||
Imports: ggplot2, imputeTS, reshape2, methods, stats | ||
License: GPL | ||
LazyData: TRUE | ||
RoxygenNote: 5.0.1 | ||
Suggests: knitr, rmarkdown | ||
VignetteBuilder: knitr | ||
NeedsCompilation: no | ||
Packaged: 2016-04-17 17:32:07 UTC; NEERAJ | ||
Repository: CRAN | ||
Date/Publication: 2016-04-17 20:11:34 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
4f933b233ec56ae0ee6c747c4e928d62 *DESCRIPTION | ||
1ea6222a7478926f5db7d96450091059 *NAMESPACE | ||
c173f572f6d5ce3ccba4b8be023eb5f7 *R/append_method.R | ||
d669d33da67085fe3b536627fcd7a9af *R/error_functions.R | ||
401b4bfc21071a32d0960e1b495f31c8 *R/impute_errors.R | ||
803029808c7a3361ca3a5fe5d4a7473b *R/plot_errors.R | ||
5c37869e953de289f33b5717a3d4fdfa *build/vignette.rds | ||
155d7f30e87b1781bb59af8da7247618 *inst/doc/imputeTestbench-Vignette.R | ||
c850a692fde45c9f55f45442f1f01339 *inst/doc/imputeTestbench-Vignette.Rmd | ||
de0ada52dc4e87abd4a55527a404daba *inst/doc/imputeTestbench-Vignette.html | ||
69c68009f9e2f37fd5270640b5c4a4cb *man/append_method.Rd | ||
29fc1b5a9445b9947a4274a508667494 *man/impute_errors.Rd | ||
a1b43f0d6f7fed5e730b2234eb58d0b3 *man/mae.Rd | ||
0d6cdfb32eb78266af7dc3eec091c297 *man/mape.Rd | ||
2310169b56c8ff9707f1e6e69b89e34e *man/plot_errors.Rd | ||
472e93fa5117100e12f5bb00358cb759 *man/rmse.Rd | ||
c850a692fde45c9f55f45442f1f01339 *vignettes/imputeTestbench-Vignette.Rmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(append_method) | ||
export(impute_errors) | ||
export(mae) | ||
export(mape) | ||
export(plot_errors) | ||
export(rmse) | ||
import(ggplot2) | ||
import(imputeTS) | ||
importFrom(methods,hasArg) | ||
importFrom(reshape2,melt) | ||
importFrom(stats,ts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#' To attach and compare new method to existing comparison study done with function 'impute_errors()' | ||
#' | ||
#' @param existing_method as output obtained from impute_error() function | ||
#' @param dataIn as imput time series for testing | ||
#' @param missPercentFrom as variable from which percent of missing values to be considered | ||
#' @param missPercentTo as variable to state upto what percent missing values are to be considered | ||
#' @param interval as interval between consecutive missPercent values | ||
#' @param repetition as an integer to state number of repetition to be done for each missPercent value | ||
#' @param errorParameter as type of error calculation (RMSE, MAE or MAPE) | ||
#' @param MethodPath as location of function for proposed imputation method | ||
#' @param MethodName as name for function for proposed imputation method | ||
#' @import ggplot2 | ||
#' @import imputeTS | ||
#' @importFrom methods hasArg | ||
#' @return Returns error comparosin for imputation methods | ||
#' @export | ||
#' @examples | ||
#' #Kindly, refer "Vignette" document | ||
|
||
|
||
#================================================================================== | ||
# append_method starts here.... | ||
#================================================================================== | ||
|
||
append_method <- function(existing_method, dataIn, missPercentFrom, missPercentTo, interval, repetition, errorParameter, MethodPath, MethodName) | ||
{ | ||
|
||
if(!(hasArg(dataIn))) | ||
{ | ||
dataIn <- c(1:5,1:5,1:5,1:5,1:5,1:5,1:5,1:5,1:5,1:5,1:5,1:5,1:5,1:5,1:5,1:5,1:5,1:5,1:5,1:5) | ||
} | ||
|
||
if(!is.vector(dataIn)) | ||
{ | ||
dataIn <- dataIn[, 1] | ||
} | ||
# For future reference | ||
dataIn1 <- dataIn | ||
|
||
# Set default values | ||
if(!(hasArg(errorParameter))) | ||
{ | ||
errorParameter <- 1 | ||
} | ||
|
||
if(!(hasArg(repetition))) | ||
{ | ||
repetition <- 1 | ||
} | ||
|
||
|
||
if(!(hasArg(MethodName))) | ||
{ | ||
MethodName <- "Proposed Method" | ||
} | ||
|
||
if(!(hasArg(interval))) | ||
{ | ||
interval <- 10 | ||
} | ||
|
||
if(!(hasArg(missPercentFrom))) | ||
{ | ||
missPercentFrom <- 10 | ||
} | ||
|
||
if(!(hasArg(missPercentTo))) | ||
{ | ||
missPercentTo <- 80 | ||
} | ||
|
||
e <- 0 | ||
f <- 0 | ||
# Function to create missing values | ||
for(x in seq(missPercentFrom, missPercentTo, interval)) | ||
{ | ||
x <- x/100 | ||
a <- length(dataIn) | ||
b <- a * x | ||
b <- abs(b) | ||
c <- a-b | ||
out <- NULL | ||
|
||
for(i in 1:repetition) | ||
{ | ||
dataIn <- dataIn1 | ||
dataIn[c:(c+b)] <- NA | ||
c <- sample(1:a, 1, replace = TRUE) | ||
while(c > a-b) | ||
{ | ||
c <- sample(1:a, 1, replace = TRUE) | ||
} | ||
out[i] <- data.frame(dataIn) | ||
} | ||
|
||
gh <- NULL | ||
for(i in 1:repetition) | ||
{ | ||
outs <- as.numeric(unlist(out[i])) | ||
|
||
# to call functions from provided "MethodPath" | ||
d <- parse(text = MethodPath) | ||
d <- eval(d) | ||
d <- d$value(outs) | ||
|
||
if(errorParameter == 1) | ||
{ | ||
gh[i] <- rmse(dataIn1 - d) | ||
parameter <- "RMSE Plot" | ||
} | ||
if(errorParameter == 2) | ||
{ | ||
gh[i] <- mae(dataIn1 - d) | ||
parameter <- "MAE Plot" | ||
} | ||
if(errorParameter == 3) | ||
{ | ||
gh[i] <- mape((dataIn1 - d), dataIn1) | ||
parameter <- "MAPE Plot" | ||
} | ||
} | ||
|
||
|
||
|
||
e <- append(e,mean(gh)) | ||
f <- append(f,x) | ||
} | ||
ex <- NULL | ||
fx <- NULL | ||
ex <- e[-1] | ||
fx <- f[-1] | ||
g <- data.frame(fx,ex) | ||
|
||
#existing_method[length(existing_method)+1] <- data.frame(e[-1]) | ||
existing_method[[paste(MethodName)]] <- e[-1] | ||
#existing_method[length(existing_method)+1] <- e | ||
return(Proposed_Method = existing_method) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#' Root Mean Square Error Calculation | ||
#' | ||
#' takes difference between Original data and Predicted data as input | ||
#' @param diff is the difference between Original data and Predicted data | ||
#' @return rmseVal as Root Mean Square Error | ||
#' @export | ||
#' @examples | ||
#' ## Generate 100 random numbers within some limits | ||
#' x <- sample(1:7, 100, replace = TRUE) | ||
#' y <- sample(1:4, 100, replace = TRUE) | ||
#' z <- rmse(x - y) | ||
#' z | ||
### RSME/MAE errors ============================================================================ | ||
# Function that returns Root Mean Squared Error | ||
rmse <- function(diff) | ||
{ | ||
rmseVal <- sqrt(mean(diff^2)) | ||
return(rmseVal) | ||
} | ||
|
||
|
||
#' Mean Absolute Error Calculation | ||
#' | ||
#' takes difference between Original data and Predicted data as input | ||
#' @param diff is the difference between Original data and Predicted data | ||
#' @return maeVal as Mean Absolute Error | ||
#' @export | ||
#' @examples | ||
#' ## Generate 100 random numbers within some limits | ||
#' x <- sample(1:7, 100, replace = TRUE) | ||
#' y <- sample(1:4, 100, replace = TRUE) | ||
#' z <- mae(x - y) | ||
#' z | ||
# Function that returns Mean Absolute Error | ||
mae <- function(diff) | ||
{ | ||
maeVal <- mean(abs(diff)) | ||
return(maeVal) | ||
} | ||
|
||
|
||
#' Mean Absolute Percent Error Calculation | ||
#' | ||
#' takes difference between Original data and Predicted data as input | ||
#' @param diff is the difference between Original data and Predicted data | ||
#' @param dataIn as original input data | ||
#' @return mapeVal as Mean Absolute Error | ||
#' @export | ||
#' @examples | ||
#' ## Generate 100 random numbers within some limits | ||
#' x <- sample(1:7, 100, replace = TRUE) | ||
#' y <- sample(1:4, 100, replace = TRUE) | ||
#' z <- mape((x - y),x) | ||
#' z | ||
# Function that returns Mean Absolute Error | ||
mape <- function(diff, dataIn) | ||
{ | ||
mapeVal <- mean(abs(diff)* 100/dataIn) | ||
return(mapeVal) | ||
} | ||
|
||
#============================================================================================== |
Oops, something went wrong.