Last data update: 2014.03.03

R: Monotonic Increasing
MonoIncR Documentation

Monotonic Increasing

Description

Combines many of the functions in the MonoInc package. Given a data range, weights, and imputation methods of choice, MonoInc will impute flagged values using either one or a combination of two imputation methods. It can also perform all single imputation methods for comparison.

Usage

MonoInc(data, id.col, x.col, y.col, data.r = NULL, tol = 0, direction = "inc", w1 = 0.5, 
  min, max, impType1 = "nn", impType2 = "reg", sum = FALSE)

Arguments

data

a data.frame or matrix of measurement data

id.col

column where the id's are stored

x.col

column where x values, or time variable is stored

y.col

column where y values, or measurements are stored

data.r

range for y values; must have three columns: 1 - must match values in xcol, 2 - lower range values, 3 - upper range values

tol

tolerance; how much outside of the range (data.r) is acceptable; same units as data in ycol

direction

the direction of the function a choice between increasing 'inc', and decreasing 'dec'

w1

weight of imputation type 1 (impType1); default is 0.50

min

lowest acceptable value for measurement; does not have to be a number in ycol

max

highest acceptable value for measurement; does not have to be a number in ycol

impType1

imputation method 1, a choice between Nearest Neighbor "nn", Regression "reg", Fractional Regression "fr", Last Observation Carried Forward "locf", or Last & Next "ln"; default is "nn"

impType2

imputation method 2; default is "reg"

sum

if true the function will return a matrix of all imputation methods in the package

Details

If two imputation methods are chosen, MonoInc will take a weighted average of the output of the imputed values. User must chose one or two imputation methods or sum=TRUE for a comparison. If there are not enough values available to impute missing or erroneous values, MonoInc will return an NA. Advice: Do NOT overwrite original data using this function! Use parallel processing if available on your device.

Value

Returns the data matrix with additional columns for the selected imputation method. If sum=TRUE, it will return a column for each single imputation method. The Y column will have NAs, indicating that this observation was flagged and imputed, for summary only. Duplicate rows are removed.

Author(s)

Michele Josey mjosey@nccu.edu Melyssa Minto mminto@nccu.edu

Examples

data(simulated_data)
simulated_data <- simulated_data[1:1000,]
data(data.r)
library(sitar)

## Run MonoInc
sum <- MonoInc(simulated_data, 1,2,3, data.r,5,direction='inc', w1=0.3, min=30, max=175, 
    impType1=NULL, impType2=NULL, sum=TRUE)
head(sum)
test <- MonoInc(simulated_data, 1,2,3, data.r,5,direction='inc', w1=0.3, min=30, max=175, 
    impType1="nn", impType2="fr")
head(test)

## plot longitudinal height for each id
mplot(x=X, y=Nn.Fr, data=test)
tol <- 5
lines(data.r[,1], data.r[,2]-tol, col=2, lty=2)
lines(data.r[,1], data.r[,3]+tol, col=2, lty=2)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(MonoInc)
Loading required package: compare

Attaching package: 'compare'

The following object is masked from 'package:base':

    isTRUE

Loading required package: doParallel
Loading required package: foreach
Loading required package: iterators
Loading required package: parallel
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/MonoInc/MonoInc.Rd_%03d_medium.png", width=480, height=480)
> ### Name: MonoInc
> ### Title: Monotonic Increasing
> ### Aliases: MonoInc
> ### Keywords: monotonic mono
> 
> ### ** Examples
> 
> data(simulated_data)
> simulated_data <- simulated_data[1:1000,]
> data(data.r)
> library(sitar)
Loading required package: nlme
Loading required package: splines
> 
> ## Run MonoInc
> sum <- MonoInc(simulated_data, 1,2,3, data.r,5,direction='inc', w1=0.3, min=30, max=175, 
+     impType1=NULL, impType2=NULL, sum=TRUE)
Warning message:
executing %dopar% sequentially: no parallel backend registered 
> head(sum)
  ID   X         Y Nearest.Neighbor Regression      LOCF Last.Next
1  1  13  66.94740         66.94740   66.94740  66.94740  66.94740
2  1  27  82.41612         82.41612   82.41612  82.41612  82.41612
3  1  42  98.21975         98.21975   98.21975  98.21975  98.21975
5  1  46 100.33827        100.33827  100.33827 100.33827 100.33827
6  1  58 106.61578        106.61578  106.61578 106.61578 106.61578
8  1 117 132.88932        132.88932  132.88932 132.88932 132.88932
  Fractional.Reg Decreasing Outside.Range
1       66.94740      FALSE         FALSE
2       82.41612      FALSE         FALSE
3       98.21975      FALSE         FALSE
5      100.33827      FALSE         FALSE
6      106.61578      FALSE         FALSE
8      132.88932      FALSE         FALSE
> test <- MonoInc(simulated_data, 1,2,3, data.r,5,direction='inc', w1=0.3, min=30, max=175, 
+     impType1="nn", impType2="fr")
> head(test)
  ID  X     Nn.Fr Decreasing Outside.Range
1  1 13  66.94740      FALSE         FALSE
2  1 27  82.41612      FALSE         FALSE
3  1 42  98.21975      FALSE         FALSE
4  1 44  98.23894       TRUE         FALSE
5  1 46 100.33827      FALSE         FALSE
6  1 58 106.61578      FALSE         FALSE
> 
> ## plot longitudinal height for each id
> mplot(x=X, y=Nn.Fr, data=test)
> tol <- 5
> lines(data.r[,1], data.r[,2]-tol, col=2, lty=2)
> lines(data.r[,1], data.r[,3]+tol, col=2, lty=2)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>